From 4dc0bdf9333eff136cbbceaa549da8f306ac50ef Mon Sep 17 00:00:00 2001 From: Marcel Jackwerth Date: Fri, 15 Nov 2024 17:43:50 +0100 Subject: [PATCH 1/2] Add lru_cache for _find_maturin_project_above --- src/maturin_import_hook/project_importer.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/maturin_import_hook/project_importer.py b/src/maturin_import_hook/project_importer.py index 7f3367c..0dedd7e 100644 --- a/src/maturin_import_hook/project_importer.py +++ b/src/maturin_import_hook/project_importer.py @@ -1,4 +1,5 @@ import contextlib +import functools import importlib import importlib.abc import importlib.machinery @@ -373,6 +374,7 @@ def _is_editable_installed_package(project_dir: Path, package_name: str) -> bool return False +@functools.lru_cache(maxsize=None) # number of serach paths should be small def _find_maturin_project_above(path: Path) -> Optional[Path]: for search_path in itertools.chain((path,), path.parents): if is_maybe_maturin_project(search_path): From c5c7ffaac427e8022478c7218e7228e4b18c2e65 Mon Sep 17 00:00:00 2001 From: Marcel Jackwerth Date: Fri, 15 Nov 2024 17:47:51 +0100 Subject: [PATCH 2/2] Use functools.cache instead --- src/maturin_import_hook/project_importer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/maturin_import_hook/project_importer.py b/src/maturin_import_hook/project_importer.py index 0dedd7e..31fc2da 100644 --- a/src/maturin_import_hook/project_importer.py +++ b/src/maturin_import_hook/project_importer.py @@ -374,7 +374,7 @@ def _is_editable_installed_package(project_dir: Path, package_name: str) -> bool return False -@functools.lru_cache(maxsize=None) # number of serach paths should be small +@functools.cache def _find_maturin_project_above(path: Path) -> Optional[Path]: for search_path in itertools.chain((path,), path.parents): if is_maybe_maturin_project(search_path):