diff --git a/src/poetry/core/packages/dependency.py b/src/poetry/core/packages/dependency.py index bbf8d5290..1ba279bab 100644 --- a/src/poetry/core/packages/dependency.py +++ b/src/poetry/core/packages/dependency.py @@ -330,6 +330,7 @@ def create_from_pep_508( """ from poetry.core.packages.url_dependency import URLDependency from poetry.core.packages.utils.link import Link + from poetry.core.packages.utils.utils import cached_is_dir from poetry.core.packages.utils.utils import is_archive_file from poetry.core.packages.utils.utils import is_python_project from poetry.core.packages.utils.utils import is_url @@ -361,7 +362,7 @@ def create_from_pep_508( else: path_str = os.path.normpath(os.path.abspath(name)) # noqa: PTH100 p, extras = strip_extras(path_str) - if p.is_dir() and (os.path.sep in name or name.startswith(".")): + if cached_is_dir(p) and (os.path.sep in name or name.startswith(".")): if not is_python_project(Path(name)): raise ValueError( f"Directory {name!r} is not installable. Not a Python project." diff --git a/src/poetry/core/packages/utils/utils.py b/src/poetry/core/packages/utils/utils.py index 271e1e2d8..ca0456094 100644 --- a/src/poetry/core/packages/utils/utils.py +++ b/src/poetry/core/packages/utils/utils.py @@ -117,10 +117,16 @@ def strip_extras(path: str) -> tuple[Path, str | None]: return Path(path_no_extras), extras +@functools.lru_cache(maxsize=None) +def cached_is_dir(path: Path) -> bool: + """A cached version of `Path.is_dir`.""" + return path.is_dir() + + @functools.lru_cache(maxsize=None) def is_python_project(path: Path) -> bool: """Return true if the directory is a Python project""" - if not path.is_dir(): + if not cached_is_dir(path): return False setup_py = path / "setup.py"