Skip to content

Commit fae20e1

Browse files
committed
installed repository: improve recognition of installed packages' types (especially relevant for installing project plugins if Poetry has been installed via pipx) (python-poetry#9547)
1 parent 8e87b75 commit fae20e1

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

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

tests/repositories/test_installed_repository.py

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

0 commit comments

Comments
 (0)