From 7d7179ff52850fe23b7446893c310a7d3989a69f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Sun, 14 Jul 2024 06:49:12 +0200 Subject: [PATCH] installed repository: fix path of editable install with src layout (#9547) --- .../repositories/installed_repository.py | 5 ++++- .../editable-src-dir-2.3.4.dist-info/METADATA | 22 +++++++++++++++++++ .../site-packages/editable-src-dir.pth | 1 + .../repositories/test_installed_repository.py | 13 +++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 tests/repositories/fixtures/installed/lib/python3.7/site-packages/editable-src-dir-2.3.4.dist-info/METADATA create mode 100644 tests/repositories/fixtures/installed/lib/python3.7/site-packages/editable-src-dir.pth diff --git a/src/poetry/repositories/installed_repository.py b/src/poetry/repositories/installed_repository.py index 856b472c339..29a276a12b0 100644 --- a/src/poetry/repositories/installed_repository.py +++ b/src/poetry/repositories/installed_repository.py @@ -141,7 +141,10 @@ def create_package_from_distribution( # TODO: handle multiple source directories? if is_editable_package: source_type = "directory" - source_url = paths.pop().as_posix() + path = paths.pop() + if path.name == "src": + path = path.parent + source_url = path.as_posix() elif cls.is_vcs_package(path, env): ( source_type, diff --git a/tests/repositories/fixtures/installed/lib/python3.7/site-packages/editable-src-dir-2.3.4.dist-info/METADATA b/tests/repositories/fixtures/installed/lib/python3.7/site-packages/editable-src-dir-2.3.4.dist-info/METADATA new file mode 100644 index 00000000000..93113ecebfd --- /dev/null +++ b/tests/repositories/fixtures/installed/lib/python3.7/site-packages/editable-src-dir-2.3.4.dist-info/METADATA @@ -0,0 +1,22 @@ +Metadata-Version: 2.1 +Name: editable-src-dir +Version: 2.3.4 +Summary: Editable description. +License: MIT +Keywords: cli,commands +Author: Foo Bar +Author-email: foo@bar.com +Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.* +Classifier: License :: OSI Approved :: MIT License +Classifier: Programming Language :: Python :: 2 +Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.4 +Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 +Classifier: Programming Language :: Python :: 3.8 +Description-Content-Type: text/x-rst + +Editable +#### diff --git a/tests/repositories/fixtures/installed/lib/python3.7/site-packages/editable-src-dir.pth b/tests/repositories/fixtures/installed/lib/python3.7/site-packages/editable-src-dir.pth new file mode 100644 index 00000000000..c40b340604b --- /dev/null +++ b/tests/repositories/fixtures/installed/lib/python3.7/site-packages/editable-src-dir.pth @@ -0,0 +1 @@ +/path/to/editable/src diff --git a/tests/repositories/test_installed_repository.py b/tests/repositories/test_installed_repository.py index d5f5bf689da..5cb66854da8 100644 --- a/tests/repositories/test_installed_repository.py +++ b/tests/repositories/test_installed_repository.py @@ -69,6 +69,7 @@ def installed_results( ), 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-src-dir-2.3.4.dist-info"), metadata.PathDistribution( site_purelib / "editable-with-import-2.3.4.dist-info" ), @@ -286,6 +287,18 @@ def test_load_editable_package( assert editable.source_url == editable_source_directory_path +def test_load_editable_src_dir_package( + repository: InstalledRepository, editable_source_directory_path: str +) -> None: + # test editable package with src layout with text .pth file + editable = get_package_from_repository("editable-src-dir", repository) + assert editable is not None + assert editable.name == "editable-src-dir" + assert editable.version.text == "2.3.4" + assert editable.source_type == "directory" + assert editable.source_url == editable_source_directory_path + + def test_load_editable_with_import_package(repository: InstalledRepository) -> None: # test editable package with executable .pth file editable = get_package_from_repository("editable-with-import", repository)