Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(packages/dependency): add space after filename for file dependencies with markers #153

Merged
merged 2 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"),
)