Skip to content

Commit

Permalink
Ensure dependency string is PEP 508 compliant (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
abn authored Jan 31, 2021
1 parent 76e64cb commit bbd545e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
8 changes: 1 addition & 7 deletions poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,7 @@ def __hash__(self): # type: () -> int
def __str__(self): # type: () -> str
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): # type: () -> str
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 @@ -205,3 +205,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

0 comments on commit bbd545e

Please sign in to comment.