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

Ensure dependency string is PEP 508 compliant #103

Merged
merged 1 commit into from
Jan 31, 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
8 changes: 1 addition & 7 deletions poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,7 @@ def __hash__(self):
def __str__(self):
if self.is_root:
return self._pretty_name

name = self._pretty_name

if self._features:
name = "{}[{}]".format(name, ",".join(sorted(self._features)))

return "{} ({})".format(name, self._pretty_constraint)
return self.base_pep_508_name

def __repr__(self):
return "<{} {}>".format(self.__class__.__name__, str(self))
19 changes: 19 additions & 0 deletions tests/packages/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,22 @@ def test_complete_name():
"foo[bar,baz]"
== Dependency("foo", ">=1.2.3", extras=["baz", "bar"]).complete_name
)


@pytest.mark.parametrize(
"name,constraint,extras,expected",
[
("A", ">2.7,<3.0", None, "A (>2.7,<3.0)"),
("A", ">2.7,<3.0", ["x"], "A[x] (>2.7,<3.0)"),
("A", ">=1.6.5,<1.8.0 || >1.8.0,<3.1.0", None, "A (>=1.6.5,!=1.8.0,<3.1.0)"),
(
"A",
">=1.6.5,<1.8.0 || >1.8.0,<3.1.0",
["x"],
"A[x] (>=1.6.5,!=1.8.0,<3.1.0)",
),
],
)
def test_dependency_string_representation(name, constraint, extras, expected):
dependency = Dependency(name=name, constraint=constraint, extras=extras)
assert str(dependency) == expected