Skip to content

Commit

Permalink
Handle non-editable packages with pth files
Browse files Browse the repository at this point in the history
When detecting installed packages, this change ensures that packages
with .pth files are not incorrectly marked as editable. A package is
considered editable only if at least one of the paths detected is
not in the environment site.

Resolves: python-poetry#3077
  • Loading branch information
abn committed Oct 14, 2020
1 parent 42c8ccc commit 2e28cf5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
12 changes: 10 additions & 2 deletions poetry/repositories/installed_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,22 @@ def load(cls, env): # type: (Env) -> InstalledRepository
if path.name.endswith(".dist-info"):
paths = cls.get_package_paths(env=env, name=package.pretty_name)
if paths:
is_editable_package = False
for src in paths:
if cls.is_vcs_package(src, env):
cls.set_package_vcs_properties(package, env)
break

if not (
is_editable_package
or env.is_path_relative_to_lib(src)
):
is_editable_package = True
else:
# TODO: handle multiple source directories?
package._source_type = "directory"
package._source_url = paths.pop().as_posix()
if is_editable_package:
package._source_type = "directory"
package._source_url = paths.pop().as_posix()
continue

if cls.is_vcs_package(path, env):
Expand Down
11 changes: 11 additions & 0 deletions tests/repositories/test_installed_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
zipp.Path(str(SITE_PURELIB / "foo-0.1.0-py3.8.egg"), "EGG-INFO")
),
metadata.PathDistribution(VENDOR_DIR / "attrs-19.3.0.dist-info"),
metadata.PathDistribution(SITE_PURELIB / "standard-1.2.3.dist-info"),
metadata.PathDistribution(SITE_PURELIB / "editable-2.3.4.dist-info"),
metadata.PathDistribution(SITE_PURELIB / "editable-with-import-2.3.4.dist-info"),
metadata.PathDistribution(SITE_PLATLIB / "lib64-2.3.4.dist-info"),
Expand Down Expand Up @@ -158,3 +159,13 @@ def test_load_editable_with_import_package(repository):
assert editable.version.text == "2.3.4"
assert editable.source_type is None
assert editable.source_url is None


def test_load_standard_package_with_pth_file(repository):
# test standard packages with .pth file is not treated as editable
standard = get_package_from_repository("standard", repository)
assert standard is not None
assert standard.name == "standard"
assert standard.version.text == "1.2.3"
assert standard.source_type is None
assert standard.source_url is None

0 comments on commit 2e28cf5

Please sign in to comment.