Commit b309a748 by Sébastien Eustace

Fix Dependency.to_pep508() for inequality specifiers

parent d12f6421
...@@ -144,9 +144,10 @@ class Dependency(object): ...@@ -144,9 +144,10 @@ class Dependency(object):
requirement += "[{}]".format(",".join(self.extras)) requirement += "[{}]".format(",".join(self.extras))
if isinstance(self.constraint, VersionUnion): if isinstance(self.constraint, VersionUnion):
requirement += " ({})".format( if self.constraint.excludes_single_version():
",".join([str(c).replace(" ", "") for c in self.constraint.ranges]) requirement += " ({})".format(str(self.constraint))
) else:
requirement += " ({})".format(self.pretty_constraint)
elif isinstance(self.constraint, Version): elif isinstance(self.constraint, Version):
requirement += " (=={})".format(self.constraint.text) requirement += " (=={})".format(self.constraint.text)
elif not self.constraint.is_any(): elif not self.constraint.is_any():
......
...@@ -228,7 +228,7 @@ class VersionUnion(VersionConstraint): ...@@ -228,7 +228,7 @@ class VersionUnion(VersionConstraint):
raise ValueError("Unknown VersionConstraint type {}".format(constraint)) raise ValueError("Unknown VersionConstraint type {}".format(constraint))
def _excludes_single_version(self): # type: () -> bool def excludes_single_version(self): # type: () -> bool
from .version import Version from .version import Version
from .version_range import VersionRange from .version_range import VersionRange
...@@ -243,7 +243,7 @@ class VersionUnion(VersionConstraint): ...@@ -243,7 +243,7 @@ class VersionUnion(VersionConstraint):
def __str__(self): def __str__(self):
from .version_range import VersionRange from .version_range import VersionRange
if self._excludes_single_version(): if self.excludes_single_version():
return "!={}".format(VersionRange().difference(self)) return "!={}".format(VersionRange().difference(self))
return " || ".join([str(r) for r in self._ranges]) return " || ".join([str(r) for r in self._ranges])
......
...@@ -102,3 +102,9 @@ def test_to_pep_508_in_extras(): ...@@ -102,3 +102,9 @@ def test_to_pep_508_in_extras():
") " ") "
'and (extra == "foo" or extra == "bar")' 'and (extra == "foo" or extra == "bar")'
) )
def test_to_pep_508_with_single_version_excluded():
dependency = Dependency("foo", "!=1.2.3")
assert "foo (!=1.2.3)" == dependency.to_pep_508()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment