Skip to content

Commit

Permalink
installed repository: improve recognition of installed packages' type…
Browse files Browse the repository at this point in the history
…s (especially relevant for installing project plugins if Poetry has been installed via pipx) (python-poetry#9547)
  • Loading branch information
radoering committed Jul 14, 2024
1 parent 8e87b75 commit fae20e1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/poetry/repositories/installed_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down
27 changes: 27 additions & 0 deletions tests/repositories/test_installed_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fae20e1

Please sign in to comment.