Skip to content

Commit 419cb29

Browse files
committed
installed repository: improve recognition of installed packages' types (especially relevant for installing project plugins if Poetry has been installed via pipx) (#9547)
1 parent 2a5126e commit 419cb29

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/poetry/repositories/installed_repository.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from packaging.utils import canonicalize_name
1111
from poetry.core.packages.package import Package
12+
from poetry.core.packages.utils.utils import is_python_project
1213
from poetry.core.packages.utils.utils import url_to_path
1314
from poetry.core.utils.helpers import module_name
1415

@@ -150,8 +151,7 @@ def create_package_from_distribution(
150151
) = cls.get_package_vcs_properties_from_path(
151152
env.path / "src" / canonicalize_name(distribution.metadata["name"])
152153
)
153-
else:
154-
# If not, it's a path dependency
154+
elif is_python_project(path.parent):
155155
source_type = "directory"
156156
source_url = str(path.parent)
157157

tests/repositories/test_installed_repository.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,3 +423,30 @@ def test_system_site_packages_source_type(
423423
package.name: package.source_type for package in installed_repository.packages
424424
}
425425
assert source_types == {"cleo": None, "directory-pep-610": "directory"}
426+
427+
428+
def test_pipx_shared_lib_site_packages(
429+
tmp_path: Path,
430+
poetry: Poetry,
431+
site_purelib: Path,
432+
caplog: LogCaptureFixture,
433+
) -> None:
434+
"""
435+
Simulate pipx shared/lib/site-packages which is not relative to the venv path.
436+
"""
437+
venv_path = tmp_path / "venv"
438+
shared_lib_site_path = tmp_path / "site"
439+
env = MockEnv(
440+
path=venv_path, sys_path=[str(venv_path / "purelib"), str(shared_lib_site_path)]
441+
)
442+
dist_info = "cleo-0.7.6.dist-info"
443+
shutil.copytree(site_purelib / dist_info, shared_lib_site_path / dist_info)
444+
installed_repository = InstalledRepository.load(env)
445+
446+
assert len(installed_repository.packages) == 1
447+
cleo_package = installed_repository.packages[0]
448+
cleo_package.to_dependency()
449+
# There must not be a warning
450+
# that the package does not seem to be a valid Python package.
451+
assert caplog.messages == []
452+
assert cleo_package.source_type is None

0 commit comments

Comments
 (0)