aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/project/os.py
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-10-09 16:49:25 +0500
committerEgor Tensin <egor@tensin.name>2026-10-09 16:58:00 +0500
commit21a16d5f91429cf2a61dcdae45c5448c096123d7 (patch)
tree8052fd16287a06c4d0fd564cb62cf44de0b60d76 /project/os.py
parentugprade to StrEnum (diff)
downloadcmake-common-21a16d5f91429cf2a61dcdae45c5448c096123d7.tar.gz
cmake-common-21a16d5f91429cf2a61dcdae45c5448c096123d7.zip
use the match statement
Diffstat (limited to 'project/os.py')
-rw-r--r--project/os.py18
1 files changed, 7 insertions, 11 deletions
diff --git a/project/os.py b/project/os.py
index 199086f..38dc5d9 100644
--- a/project/os.py
+++ b/project/os.py
@@ -3,26 +3,22 @@
# For details, see https://github.com/egor-tensin/cmake-common
# Distributed under the MIT License.
-from enum import auto, StrEnum
+from enum import StrEnum
import platform
class OS(StrEnum):
- WINDOWS = auto()
- LINUX = auto()
- MACOS = auto()
+ WINDOWS = "Windows"
+ LINUX = "Linux"
+ MACOS = "Darwin"
@staticmethod
def current():
system = platform.system()
- mapping = {
- "Windows": OS.WINDOWS,
- "Linux": OS.LINUX,
- "Darwin": OS.MACOS,
- }
- if system not in mapping:
+ try:
+ return OS(system)
+ except ValueError:
raise NotImplementedError(f"unsupported OS: {system}")
- return mapping[system]
def on_windows():