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 (#153)

* 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
  • Loading branch information
Michael Ossareh authored Apr 26, 2021
1 parent 44167a5 commit fe476e0
Show file tree
Hide file tree
Showing 2 changed files with 37 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
37 changes: 36 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,35 @@ 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_absolute_file_dependency_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"),
)


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()
)
_test_file_dependency_pep_508(
mocker,
"demo",
rel_path,
requirement,
marker=SingleMarker("sys.platform", "linux"),
)

0 comments on commit fe476e0

Please sign in to comment.