diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2019-02-12 22:36:02 +0100 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2019-02-26 09:33:26 +0100 |
commit | 1dfa3783f50afffe1f537c482e856a2a5a40fc1c (patch) | |
tree | 00525b539bf8e419ef59dfd3cd75f15a560c20e5 /mesonbuild | |
parent | b69e45ebaca517a47ab39757d1f61f9fd5f55804 (diff) | |
download | meson-1dfa3783f50afffe1f537c482e856a2a5a40fc1c.zip meson-1dfa3783f50afffe1f537c482e856a2a5a40fc1c.tar.gz meson-1dfa3783f50afffe1f537c482e856a2a5a40fc1c.tar.bz2 |
Use @lru_cache and added return annotation
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/dependencies/base.py | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 516b036..44c3ef2 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -924,9 +924,6 @@ class CMakeDependency(ExternalDependency): # CMake generators to try (empty for no generator) class_cmake_generators = ['', 'Ninja', 'Unix Makefiles', 'Visual Studio 10 2010'] class_working_generator = None - # Cache for os.listdir and os.path.exists - class_listdir_cache = {} - class_isdir_cache = {} def _gen_exception(self, msg): return DependencyException('Dependency {} not found: {}'.format(self.name, msg)) @@ -1112,21 +1109,21 @@ class CMakeDependency(ExternalDependency): self.vars = {} return res - def _cached_listdir(self, path: str) -> List[Tuple[str, str]]: - if path not in CMakeDependency.class_listdir_cache: - try: - CMakeDependency.class_listdir_cache[path] = [(x, str(x).lower()) for x in os.listdir(path)] - except: - CMakeDependency.class_listdir_cache[path] = [] - return CMakeDependency.class_listdir_cache[path] + @staticmethod + @functools.lru_cache(maxsize=None) + def _cached_listdir(path: str) -> List[Tuple[str, str]]: + try: + return [(x, str(x).lower()) for x in os.listdir(path)] + except: + return [] - def _cached_isdir(self, path: str) -> bool: - if path not in CMakeDependency.class_isdir_cache: - try: - CMakeDependency.class_isdir_cache[path] = os.path.isdir(path) - except: - CMakeDependency.class_isdir_cache[path] = False - return CMakeDependency.class_isdir_cache[path] + @staticmethod + @functools.lru_cache(maxsize=None) + def _cached_isdir(path: str) -> bool: + try: + return os.path.isdir(path) + except: + return False def _preliminary_find_check(self, name: str, module_path: List[str]) -> bool: lname = str(name).lower() @@ -1628,7 +1625,7 @@ set(CMAKE_CXX_ABI_COMPILED TRUE) set(CMAKE_SIZEOF_VOID_P "{}") '''.format(os.path.realpath(__file__), ctypes.sizeof(ctypes.c_voidp))) - def _setup_cmake_dir(self, cmake_file: str): + def _setup_cmake_dir(self, cmake_file: str) -> str: # Setup the CMake build environment and return the "build" directory build_dir = '{}/cmake_{}'.format(self.cmake_root_dir, self.name) os.makedirs(build_dir, exist_ok=True) |