From 702b3e2d5cadee0d08f51da3747330ff0e9a5090 Mon Sep 17 00:00:00 2001 From: "P. Michael Ossareh" Date: Thu, 1 Apr 2021 15:58:37 -0500 Subject: [PATCH 1/2] fix(packages/dependency): add space after filename for file dependencies with markers local vendored files need a space after the file name and before the ";" which demarks the start of markers fix #3872 --- poetry/core/packages/dependency.py | 2 +- tests/packages/test_file_dependency.py | 33 +++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/poetry/core/packages/dependency.py b/poetry/core/packages/dependency.py index 6e06bc6fa..aa75e3e2f 100644 --- a/poetry/core/packages/dependency.py +++ b/poetry/core/packages/dependency.py @@ -262,7 +262,7 @@ def to_pep_508(self, with_extras: bool = True) -> str: ) if markers: - if self.is_vcs() or self.is_url(): + if self.is_vcs() or self.is_url() or self.is_file(): requirement += " " if len(markers) > 1: diff --git a/tests/packages/test_file_dependency.py b/tests/packages/test_file_dependency.py index 3abe20f88..d5664c192 100644 --- a/tests/packages/test_file_dependency.py +++ b/tests/packages/test_file_dependency.py @@ -4,6 +4,7 @@ from poetry.core.packages.dependency import Dependency from poetry.core.packages.file_dependency import FileDependency +from poetry.core.version.markers import SingleMarker DIST_PATH = Path(__file__).parent.parent / "fixtures" / "distributions" @@ -20,7 +21,7 @@ def test_file_dependency_dir(): def _test_file_dependency_pep_508( - mocker, name, path, pep_508_input, pep_508_output=None + mocker, name, path, pep_508_input, pep_508_output=None, marker=None ): mocker.patch.object(Path, "exists").return_value = True mocker.patch.object(Path, "is_file").return_value = True @@ -28,6 +29,8 @@ def _test_file_dependency_pep_508( dep = Dependency.create_from_pep_508( pep_508_input, relative_to=Path(__file__).parent ) + if marker: + dep.marker = marker assert dep.is_file() assert dep.name == name @@ -62,3 +65,31 @@ def test_file_dependency_pep_508_local_file_relative_path(mocker): requirement = "{} @ {}".format("demo", path) _test_file_dependency_pep_508(mocker, "demo", path, requirement) + + +def test_to_pep_508_with_marker(mocker): + wheel = "demo-0.1.0-py2.py3-none-any.whl" + + abs_path = DIST_PATH / wheel + requirement = '{} @ file://{} ; sys_platform == "linux"'.format( + "demo", abs_path.as_posix() + ) + _test_file_dependency_pep_508( + mocker, + "demo", + abs_path, + requirement, + marker=SingleMarker("sys.platform", "linux"), + ) + + rel_path = Path("..") / "fixtures" / "distributions" / wheel + requirement = '{} @ {} ; sys_platform == "linux"'.format( + "demo", rel_path.as_posix() + ) + _test_file_dependency_pep_508( + mocker, + "demo", + rel_path, + requirement, + marker=SingleMarker("sys.platform", "linux"), + ) From b4607fed134bc54c6760446df3d0e08299c99436 Mon Sep 17 00:00:00 2001 From: "P. Michael Ossareh" Date: Sun, 25 Apr 2021 14:54:26 -0500 Subject: [PATCH 2/2] style(tests): split unit test into two functions --- tests/packages/test_file_dependency.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/packages/test_file_dependency.py b/tests/packages/test_file_dependency.py index d5664c192..8315594ca 100644 --- a/tests/packages/test_file_dependency.py +++ b/tests/packages/test_file_dependency.py @@ -67,7 +67,7 @@ def test_file_dependency_pep_508_local_file_relative_path(mocker): _test_file_dependency_pep_508(mocker, "demo", path, requirement) -def test_to_pep_508_with_marker(mocker): +def test_absolute_file_dependency_to_pep_508_with_marker(mocker): wheel = "demo-0.1.0-py2.py3-none-any.whl" abs_path = DIST_PATH / wheel @@ -82,6 +82,10 @@ def test_to_pep_508_with_marker(mocker): marker=SingleMarker("sys.platform", "linux"), ) + +def test_relative_file_dependency_to_pep_508_with_marker(mocker): + wheel = "demo-0.1.0-py2.py3-none-any.whl" + rel_path = Path("..") / "fixtures" / "distributions" / wheel requirement = '{} @ {} ; sys_platform == "linux"'.format( "demo", rel_path.as_posix()