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 authored and finswimmer committed Sep 7, 2020
1 parent 670018b commit b647193
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
5 changes: 4 additions & 1 deletion poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,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(c) for c 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 @@ -49,13 +49,17 @@ def test_convert_dependencies():
Dependency("B", "~1.0"),
Dependency("C", "1.2.3"),
VCSDependency("D", "git", "https://github.com/sdispater/d.git"),
Dependency("E", "^1.0"),
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 @@ -130,3 +130,49 @@ def test_to_pep_508_with_patch_python_version(python_versions, marker):

assert expected == dependency.to_pep_508()
assert marker == str(dependency.marker)


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 b647193

Please sign in to comment.