Skip to content

Commit

Permalink
fix(packages/dependency): add space after filename for file dependenc…
Browse files Browse the repository at this point in the history
…ies with markers

local vendored files need a space after the file name and before the ";" which demarks the start of
markers

fix #3872
  • Loading branch information
ossareh committed Apr 1, 2021
1 parent 8996496 commit acd21af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 21 additions & 1 deletion tests/packages/test_file_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -20,14 +21,16 @@ 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

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
Expand Down Expand Up @@ -62,3 +65,20 @@ 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"

def _dep_with_marker(path):
dependency = FileDependency("demo", path, base=Path(__file__).parent)
dependency.marker = SingleMarker("sys.platform", "linux")
return dependency

abs_path = DIST_PATH / wheel
expected = '{} @ file://{} ; sys_platform == "linux"'.format("demo", abs_path)
assert expected == _dep_with_marker(abs_path).to_pep_508()

rel_path = Path("..") / "fixtures" / "distributions" / wheel
expected = '{} @ {} ; sys_platform == "linux"'.format("demo", rel_path)
assert expected == _dep_with_marker(rel_path).to_pep_508()

0 comments on commit acd21af

Please sign in to comment.