Commit c55d55a8 by Sébastien Eustace

Fix handling of PEP 440 ~= version constraint

parent 19006330
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
- Fixed terminal coloring being activated even if not supported. - Fixed terminal coloring being activated even if not supported.
- Fixed wrong executable being picked up on Windows in `poetry run`. - Fixed wrong executable being picked up on Windows in `poetry run`.
- Fixed error when listing distribution links for private repositories. - Fixed error when listing distribution links for private repositories.
- Fixed handling of PEP 440 `~=` version constraint.
## [0.10.1] - 2018-05-28 ## [0.10.1] - 2018-05-28
......
...@@ -4,6 +4,7 @@ from .empty_constraint import EmptyConstraint ...@@ -4,6 +4,7 @@ from .empty_constraint import EmptyConstraint
from .patterns import BASIC_CONSTRAINT from .patterns import BASIC_CONSTRAINT
from .patterns import CARET_CONSTRAINT from .patterns import CARET_CONSTRAINT
from .patterns import TILDE_CONSTRAINT from .patterns import TILDE_CONSTRAINT
from .patterns import TILDE_PEP440_CONSTRAINT
from .patterns import X_CONSTRAINT from .patterns import X_CONSTRAINT
from .version import Version from .version import Version
from .version_constraint import VersionConstraint from .version_constraint import VersionConstraint
...@@ -59,6 +60,28 @@ def parse_single_constraint(constraint): # type: (str) -> VersionConstraint ...@@ -59,6 +60,28 @@ def parse_single_constraint(constraint): # type: (str) -> VersionConstraint
high = version.stable.next_major high = version.stable.next_major
return VersionRange(version, high, include_min=True) return VersionRange(version, high, include_min=True)
return VersionRange()
# PEP 440 Tilde range (~=)
m = TILDE_PEP440_CONSTRAINT.match(constraint)
if m:
precision = 1
if m.group(3):
precision += 1
if m.group(4):
precision += 1
version = Version.parse(m.group(1))
if precision == 2:
low = version
high = version.stable.next_major
else:
low = Version(version.major, version.minor, 0)
high = version.stable.next_minor
return VersionRange(low, high, include_min=True)
# Caret range # Caret range
m = CARET_CONSTRAINT.match(constraint) m = CARET_CONSTRAINT.match(constraint)
......
...@@ -11,7 +11,8 @@ _COMPLETE_VERSION = "v?(\d+)(?:\.(\d+))?(?:\.(\d+))?{}(?:\+[^\s]+)?".format(MODI ...@@ -11,7 +11,8 @@ _COMPLETE_VERSION = "v?(\d+)(?:\.(\d+))?(?:\.(\d+))?{}(?:\+[^\s]+)?".format(MODI
COMPLETE_VERSION = re.compile("(?i)" + _COMPLETE_VERSION) COMPLETE_VERSION = re.compile("(?i)" + _COMPLETE_VERSION)
CARET_CONSTRAINT = re.compile("(?i)^\^({})$".format(_COMPLETE_VERSION)) CARET_CONSTRAINT = re.compile("(?i)^\^({})$".format(_COMPLETE_VERSION))
TILDE_CONSTRAINT = re.compile("(?i)^~=?({})$".format(_COMPLETE_VERSION)) TILDE_CONSTRAINT = re.compile("(?i)^~(?!=)({})$".format(_COMPLETE_VERSION))
TILDE_PEP440_CONSTRAINT = re.compile("(?i)^~=({})$".format(_COMPLETE_VERSION))
X_CONSTRAINT = re.compile("^(!= ?|==)?v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.[xX*])+$") X_CONSTRAINT = re.compile("^(!= ?|==)?v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.[xX*])+$")
BASIC_CONSTRAINT = re.compile( BASIC_CONSTRAINT = re.compile(
"(?i)^(<>|!=|>=?|<=?|==?)?\s*({})".format(_COMPLETE_VERSION) "(?i)^(<>|!=|>=?|<=?|==?)?\s*({})".format(_COMPLETE_VERSION)
......
...@@ -60,6 +60,9 @@ def test_parse_constraint_wildcard(input, constraint): ...@@ -60,6 +60,9 @@ def test_parse_constraint_wildcard(input, constraint):
("~1.2-beta", VersionRange(Version(1, 2, 0, "beta"), Version(1, 3, 0), True)), ("~1.2-beta", VersionRange(Version(1, 2, 0, "beta"), Version(1, 3, 0), True)),
("~1.2-b2", VersionRange(Version(1, 2, 0, "b2"), Version(1, 3, 0), True)), ("~1.2-b2", VersionRange(Version(1, 2, 0, "b2"), Version(1, 3, 0), True)),
("~0.3", VersionRange(Version(0, 3, 0), Version(0, 4, 0), True)), ("~0.3", VersionRange(Version(0, 3, 0), Version(0, 4, 0), True)),
("~3.5", VersionRange(Version(3, 5, 0), Version(3, 6, 0), True)),
("~=3.5", VersionRange(Version(3, 5, 0), Version(4, 0, 0), True)), # PEP 440
("~=3.5.3", VersionRange(Version(3, 5, 0), Version(3, 6, 0), True)), # PEP 440
], ],
) )
def test_parse_constraint_tilde(input, constraint): def test_parse_constraint_tilde(input, constraint):
......
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