From b6661838ceda7e617f5462df9bd5823985a32020 Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sun, 30 Oct 2022 18:44:48 +0000 Subject: [PATCH] Use file:// urls for path and directory dependencies --- src/poetry/core/packages/directory_dependency.py | 4 +--- src/poetry/core/packages/file_dependency.py | 4 +--- tests/packages/test_directory_dependency.py | 3 ++- tests/packages/test_file_dependency.py | 15 +++++++++++++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/poetry/core/packages/directory_dependency.py b/src/poetry/core/packages/directory_dependency.py index 5b3cfa5d6..5c882afee 100644 --- a/src/poetry/core/packages/directory_dependency.py +++ b/src/poetry/core/packages/directory_dependency.py @@ -89,9 +89,7 @@ def base_pep_508_name(self) -> str: extras = ",".join(sorted(self.extras)) requirement += f"[{extras}]" - path = ( - path_to_url(self.path) if self.path.is_absolute() else self.path.as_posix() - ) + path = path_to_url(self.full_path) requirement += f" @ {path}" return requirement diff --git a/src/poetry/core/packages/file_dependency.py b/src/poetry/core/packages/file_dependency.py index a5dade981..2b71000c6 100644 --- a/src/poetry/core/packages/file_dependency.py +++ b/src/poetry/core/packages/file_dependency.py @@ -78,9 +78,7 @@ def base_pep_508_name(self) -> str: extras = ",".join(sorted(self.extras)) requirement += f"[{extras}]" - path = ( - path_to_url(self.path) if self.path.is_absolute() else self.path.as_posix() - ) + path = path_to_url(self.full_path) requirement += f" @ {path}" return requirement diff --git a/tests/packages/test_directory_dependency.py b/tests/packages/test_directory_dependency.py index 8d9c43170..00cda295f 100644 --- a/tests/packages/test_directory_dependency.py +++ b/tests/packages/test_directory_dependency.py @@ -66,7 +66,8 @@ def test_directory_dependency_pep_508_local_relative() -> None: _test_directory_dependency_pep_508("demo", path, requirement) requirement = f"demo @ {path}" - expected = f"demo @ {path.as_posix()}" + base = Path(__file__).parent + expected = f"demo @ {(base / path).resolve().as_uri()}" _test_directory_dependency_pep_508("demo", path, requirement, expected) diff --git a/tests/packages/test_file_dependency.py b/tests/packages/test_file_dependency.py index af1809e0c..ee1b1199c 100644 --- a/tests/packages/test_file_dependency.py +++ b/tests/packages/test_file_dependency.py @@ -145,7 +145,8 @@ def test_file_dependency_pep_508_local_file_relative_path( _test_file_dependency_pep_508(mocker, "demo", path, requirement) requirement = f"demo @ {path}" - expected = f"demo @ {path.as_posix()}" + base = Path(__file__).parent + expected = f"demo @ {(base / path).resolve().as_uri()}" _test_file_dependency_pep_508(mocker, "demo", path, requirement, expected) @@ -168,11 +169,16 @@ def test_relative_file_dependency_to_pep_508_with_marker(mocker: MockerFixture) rel_path = Path("..") / "fixtures" / "distributions" / wheel requirement = f'demo @ {rel_path.as_posix()} ; sys_platform == "linux"' + base = Path(__file__).parent + expected = ( + f'demo @ {(base / rel_path).resolve().as_uri()} ; sys_platform == "linux"' + ) _test_file_dependency_pep_508( mocker, "demo", rel_path, requirement, + expected, marker=SingleMarker("sys.platform", "linux"), ) @@ -182,12 +188,17 @@ def test_file_dependency_pep_508_extras(mocker: MockerFixture) -> None: rel_path = Path("..") / "fixtures" / "distributions" / wheel requirement = f'demo[foo,bar] @ {rel_path.as_posix()} ; sys_platform == "linux"' + base = Path(__file__).parent + expected = ( + f"demo[bar,foo] @ {(base / rel_path).resolve().as_uri()} ;" + ' sys_platform == "linux"' + ) _test_file_dependency_pep_508( mocker, "demo", rel_path, requirement, - f'demo[bar,foo] @ {rel_path.as_posix()} ; sys_platform == "linux"', + expected, )