From 2e28cf5c02d772d348da2350a05c94facf8e1b28 Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Thu, 15 Oct 2020 01:52:30 +0200 Subject: [PATCH] Handle non-editable packages with pth files 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: #3077 --- poetry/repositories/installed_repository.py | 12 ++++++++++-- tests/repositories/test_installed_repository.py | 11 +++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/poetry/repositories/installed_repository.py b/poetry/repositories/installed_repository.py index a0630116f53..1320fdd6698 100644 --- a/poetry/repositories/installed_repository.py +++ b/poetry/repositories/installed_repository.py @@ -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): diff --git a/tests/repositories/test_installed_repository.py b/tests/repositories/test_installed_repository.py index 79ac262671c..3caa702a09c 100644 --- a/tests/repositories/test_installed_repository.py +++ b/tests/repositories/test_installed_repository.py @@ -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"), @@ -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