From fae20e140a908d87d2c2657cc9e40c1c0c0d4729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Sat, 13 Jul 2024 23:30:07 +0200 Subject: [PATCH] installed repository: improve recognition of installed packages' types (especially relevant for installing project plugins if Poetry has been installed via pipx) (#9547) --- .../repositories/installed_repository.py | 4 +-- .../repositories/test_installed_repository.py | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/poetry/repositories/installed_repository.py b/src/poetry/repositories/installed_repository.py index 2912641fdc9..856b472c339 100644 --- a/src/poetry/repositories/installed_repository.py +++ b/src/poetry/repositories/installed_repository.py @@ -9,6 +9,7 @@ from packaging.utils import canonicalize_name from poetry.core.packages.package import Package +from poetry.core.packages.utils.utils import is_python_project from poetry.core.packages.utils.utils import url_to_path from poetry.core.utils.helpers import module_name @@ -149,8 +150,7 @@ def create_package_from_distribution( ) = cls.get_package_vcs_properties_from_path( env.path / "src" / canonicalize_name(distribution.metadata["name"]) ) - else: - # If not, it's a path dependency + elif is_python_project(path.parent): source_type = "directory" source_url = str(path.parent) diff --git a/tests/repositories/test_installed_repository.py b/tests/repositories/test_installed_repository.py index dee5761571b..d5f5bf689da 100644 --- a/tests/repositories/test_installed_repository.py +++ b/tests/repositories/test_installed_repository.py @@ -422,3 +422,30 @@ def test_system_site_packages_source_type( package.name: package.source_type for package in installed_repository.packages } assert source_types == {"cleo": None, "directory-pep-610": "directory"} + + +def test_pipx_shared_lib_site_packages( + tmp_path: Path, + poetry: Poetry, + site_purelib: Path, + caplog: LogCaptureFixture, +) -> None: + """ + Simulate pipx shared/lib/site-packages which is not relative to the venv path. + """ + venv_path = tmp_path / "venv" + shared_lib_site_path = tmp_path / "site" + env = MockEnv( + path=venv_path, sys_path=[str(venv_path / "purelib"), str(shared_lib_site_path)] + ) + dist_info = "cleo-0.7.6.dist-info" + shutil.copytree(site_purelib / dist_info, shared_lib_site_path / dist_info) + installed_repository = InstalledRepository.load(env) + + assert len(installed_repository.packages) == 1 + cleo_package = installed_repository.packages[0] + cleo_package.to_dependency() + # There must not be a warning + # that the package does not seem to be a valid Python package. + assert caplog.messages == [] + assert cleo_package.source_type is None