diff options
| author | Egor Tensin <egor@tensin.name> | 2026-10-09 12:08:53 +0500 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-10-09 12:08:53 +0500 |
| commit | b6078e1d19235301948766721a7d9f4903b98745 (patch) | |
| tree | 1ccc8ea3988fc23f543e7955a047335ffadee3ba /project | |
| parent | minor imports refactoring (diff) | |
| download | cmake-common-b6078e1d19235301948766721a7d9f4903b98745.tar.gz cmake-common-b6078e1d19235301948766721a7d9f4903b98745.zip | |
ugprade to StrEnum
Diffstat (limited to 'project')
| -rw-r--r-- | project/configuration.py | 15 | ||||
| -rw-r--r-- | project/linkage.py | 11 | ||||
| -rw-r--r-- | project/os.py | 13 | ||||
| -rw-r--r-- | project/platform.py | 13 | ||||
| -rw-r--r-- | project/toolset.py | 27 |
5 files changed, 29 insertions, 50 deletions
diff --git a/project/configuration.py b/project/configuration.py index e98b9c1..69dfe10 100644 --- a/project/configuration.py +++ b/project/configuration.py @@ -4,19 +4,16 @@ # Distributed under the MIT License. import argparse -from enum import Enum +from enum import auto, StrEnum -class Configuration(Enum): +class Configuration(StrEnum): """Correspond to CMake's default CMAKE_BUILD_TYPE values.""" - DEBUG = "Debug" - MINSIZEREL = "MinSizeRel" - RELWITHDEBINFO = "RelWithDebInfo" - RELEASE = "Release" - - def __str__(self): - return str(self.value) + DEBUG = auto() + MINSIZEREL = auto() + RELWITHDEBINFO = auto() + RELEASE = auto() @staticmethod def all(): diff --git a/project/linkage.py b/project/linkage.py index dfa474d..b952031 100644 --- a/project/linkage.py +++ b/project/linkage.py @@ -4,18 +4,15 @@ # Distributed under the MIT License. import argparse -from enum import Enum +from enum import auto, StrEnum import logging from project.os import on_linux_like -class Linkage(Enum): - STATIC = "static" - SHARED = "shared" - - def __str__(self): - return str(self.value) +class Linkage(StrEnum): + STATIC = auto() + SHARED = auto() @staticmethod def all(): diff --git a/project/os.py b/project/os.py index 4ddf703..199086f 100644 --- a/project/os.py +++ b/project/os.py @@ -3,17 +3,14 @@ # For details, see https://github.com/egor-tensin/cmake-common # Distributed under the MIT License. -from enum import Enum +from enum import auto, StrEnum import platform -class OS(Enum): - WINDOWS = "Windows" - LINUX = "Linux" - MACOS = "macOS" - - def __str__(self): - return str(self.value) +class OS(StrEnum): + WINDOWS = auto() + LINUX = auto() + MACOS = auto() @staticmethod def current(): diff --git a/project/platform.py b/project/platform.py index cae02a4..5091f7f 100644 --- a/project/platform.py +++ b/project/platform.py @@ -4,23 +4,20 @@ # Distributed under the MIT License. import argparse -from enum import Enum +from enum import auto, StrEnum import os.path import platform from project.os import on_windows -class Platform(Enum): +class Platform(StrEnum): # I only build for x86(-64), so here it goes. - X86 = "x86" - X64 = "x64" + X86 = auto() + X64 = auto() # 'auto' means that no additional arguments will be passed to either # Boost's b2 nor CMake (except on Windows, see below). - AUTO = "auto" - - def __str__(self): - return str(self.value) + AUTO = auto() @staticmethod def windows_native(): diff --git a/project/toolset.py b/project/toolset.py index 8b6ea07..f93881f 100644 --- a/project/toolset.py +++ b/project/toolset.py @@ -25,7 +25,7 @@ import abc import argparse from contextlib import contextmanager from decimal import Decimal -from enum import Enum +from enum import auto, StrEnum import logging import os.path import shutil @@ -36,7 +36,7 @@ from project.platform import Platform from project import utils -class MSVCVersion(Enum): +class MSVCVersion(StrEnum): # It's the MSVC "toolset" version, or whatever. # Source: https://cmake.org/cmake/help/latest/variable/MSVC_TOOLSET_VERSION.html VS2010 = "100" @@ -49,9 +49,6 @@ class MSVCVersion(Enum): VS2026 = "145" # ^^^ Update the mappings below. - def __str__(self): - return str(self.value) - def help(self): if self in _msvc_to_vs_version: return f"Visual Studio {_msvc_to_vs_version[self]}" @@ -91,7 +88,7 @@ class MSVCVersion(Enum): return f"v{self}" -class VisualStudioVersion(Enum): +class VisualStudioVersion(StrEnum): VS2010 = "2010" VS2012 = "2012" VS2013 = "2013" @@ -102,9 +99,6 @@ class VisualStudioVersion(Enum): VS2026 = "2026" # ^^^ Update the mappings below. - def __str__(self): - return str(self.value) - def help(self): if self in _vs_to_msvc_version: return f"Same as '{ToolsetType.MSVC}{_vs_to_msvc_version[self]}'" @@ -145,18 +139,15 @@ _msvc_to_vs_version = { _vs_to_msvc_version = {v: k for k, v in _msvc_to_vs_version.items()} -class ToolsetType(Enum): - AUTO = "auto" - MSVC = "msvc" +class ToolsetType(StrEnum): + AUTO = auto() + MSVC = auto() VISUAL_STUDIO = "vs" - GCC = "gcc" - MINGW = "mingw" - CLANG = "clang" + GCC = auto() + MINGW = auto() + CLANG = auto() CLANG_CL = "clang-cl" - def __str__(self): - return str(self.value) - def help(self): if self is ToolsetType.AUTO: return "Means 'gcc' on Linux and 'msvc' on Windows" |
