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 version union constraint not properly generated #79

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
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()