diff options
| author | Cristián Maureira-Fredes <Cristian.Maureira-Fredes@qt.io> | 2024-12-12 12:53:05 +0100 |
|---|---|---|
| committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-12-18 09:24:15 +0000 |
| commit | 14c497b1ad444de5ddecba1a55de04c8bae86256 (patch) | |
| tree | 86967c1a395325132b0c9692d7cdc579886ea519 /build_scripts/utils.py | |
| parent | 7aab19d7e0427b4ae78ab23526f5f36b5b35d6b6 (diff) | |
build: options as a singleton
Avoid finding the dynamic options each time the OPTION dictionary
was imported in the different build_scripts files.
Now each setup.py invocation will have the same object.
Change-Id: Ic556d572e77e54fe27603332b7d2f99697eab86c
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
(cherry picked from commit b513d1e0ba84f997561f624c73ee54ab91581861)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'build_scripts/utils.py')
| -rw-r--r-- | build_scripts/utils.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/build_scripts/utils.py b/build_scripts/utils.py index 43ff9e003..9d021c81d 100644 --- a/build_scripts/utils.py +++ b/build_scripts/utils.py @@ -29,6 +29,15 @@ except NameError: WindowsError = None +class Singleton(type): + _instances = {} + + def __call__(cls, *args, **kwargs): + if cls not in cls._instances: + cls._instances[cls] = super().__call__(*args, **kwargs) + return cls._instances[cls] + + def which(name): """ Like shutil.which, but accepts a string or a PathLike and returns a Path @@ -38,9 +47,8 @@ def which(name): if isinstance(name, Path): name = str(name) path = shutil.which(name) - if path is None: - raise TypeError("None was returned") - path = Path(path) + if path is not None: + path = Path(path) except TypeError as e: log.error(f"{name} was not found in PATH: {e}") return path |
