Skip to content

Commit

Permalink
Fix version union constraint not properly generated
Browse files Browse the repository at this point in the history
When we have a union of constraints, those were not properly generated.
For example, ^1.2.3,!=1.3.5 would be converted to ^1.2.3,!=1.3.5 (same
string) under PEP508, which is not valid.
  • Loading branch information
tomzx committed Dec 18, 2019
1 parent b30577d commit 26070a1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
5 changes: 4 additions & 1 deletion poetry/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ def base_pep_508_name(self): # type: () -> str
if self.constraint.excludes_single_version():
requirement += " ({})".format(str(self.constraint))
else:
requirement += " ({})".format(self.pretty_constraint)
constraints = self.pretty_constraint.split(",")
constraints = [parse_constraint(c) for c in constraints]
constraints = [str(r) for r in constraints]
requirement += " ({})".format(",".join(constraints))
elif isinstance(self.constraint, Version):
requirement += " (=={})".format(self.constraint.text)
elif not self.constraint.is_any():
Expand Down
4 changes: 4 additions & 0 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,17 @@ def test_convert_dependencies():
get_dependency("B", "~1.0"),
get_dependency("C", "1.2.3"),
VCSDependency("D", "git", "https://github.com/sdispater/d.git"),
get_dependency("E", "^1.0"),
get_dependency("F", "^1.0,!=1.3"),
],
)
main = [
"A>=1.0,<2.0",
"B>=1.0,<1.1",
"C==1.2.3",
"D @ git+https://github.com/sdispater/d.git@master",
"E>=1.0,<2.0",
"F>=1.0,<2.0,!=1.3",
]
extras = {}

Expand Down
46 changes: 46 additions & 0 deletions tests/packages/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,49 @@ def test_to_pep_508_with_single_version_excluded():
dependency = Dependency("foo", "!=1.2.3")

assert "foo (!=1.2.3)" == dependency.to_pep_508()


def test_to_pep_508_tilde():
dependency = Dependency("foo", "~1.2.3")

assert "foo (>=1.2.3,<1.3.0)" == dependency.to_pep_508()

dependency = Dependency("foo", "~1.2")

assert "foo (>=1.2,<1.3)" == dependency.to_pep_508()

dependency = Dependency("foo", "~0.2.3")

assert "foo (>=0.2.3,<0.3.0)" == dependency.to_pep_508()

dependency = Dependency("foo", "~0.2")

assert "foo (>=0.2,<0.3)" == dependency.to_pep_508()


def test_to_pep_508_caret():
dependency = Dependency("foo", "^1.2.3")

assert "foo (>=1.2.3,<2.0.0)" == dependency.to_pep_508()

dependency = Dependency("foo", "^1.2")

assert "foo (>=1.2,<2.0)" == dependency.to_pep_508()

dependency = Dependency("foo", "^0.2.3")

assert "foo (>=0.2.3,<0.3.0)" == dependency.to_pep_508()

dependency = Dependency("foo", "^0.2")

assert "foo (>=0.2,<0.3)" == dependency.to_pep_508()


def test_to_pep_508_combination():
dependency = Dependency("foo", "^1.2,!=1.3.5")

assert "foo (>=1.2,<2.0,!=1.3.5)" == dependency.to_pep_508()

dependency = Dependency("foo", "~1.2,!=1.2.5")

assert "foo (>=1.2,<1.3,!=1.2.5)" == dependency.to_pep_508()

0 comments on commit 26070a1

Please sign in to comment.