From 56577e82e2eecaa98577c02e2951ac9e5c31d663 Mon Sep 17 00:00:00 2001 From: Anjie Yang Date: Thu, 31 Oct 2024 09:42:15 +0800 Subject: [PATCH] update check_host_os --- gui/utils.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/gui/utils.py b/gui/utils.py index e78d048..3a7b521 100644 --- a/gui/utils.py +++ b/gui/utils.py @@ -27,11 +27,25 @@ from gui.envs import MAC_ENV, UBUNTU_ENV, WINDOWS_ENV from gui.host_os import HostOS +_CACHED_HOST_OS = None def check_host_os() -> HostOS: - # TODO: Check the host OS and return the corresponding HostOS enum - return HostOS.WINDOWS + global _CACHED_HOST_OS + if _CACHED_HOST_OS is None: + import platform + host_os = platform.system().lower() + + if host_os == "linux": + _CACHED_HOST_OS = HostOS.LINUX + elif host_os == "darwin": + _CACHED_HOST_OS = HostOS.MAC + elif host_os == "windows": + _CACHED_HOST_OS = HostOS.WINDOWS + else: + raise ValueError(f"Host OS {host_os} is not supported") + + return _CACHED_HOST_OS @evaluator(env_name="ubuntu") def empty_evaluator_linux() -> bool: