Skip to content

Commit

Permalink
Fix handling of PEP 440 ~= version constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater committed May 31, 2018
1 parent 1900633 commit c55d55a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Fixed terminal coloring being activated even if not supported.
- Fixed wrong executable being picked up on Windows in `poetry run`.
- Fixed error when listing distribution links for private repositories.
- Fixed handling of PEP 440 `~=` version constraint.


## [0.10.1] - 2018-05-28
Expand Down
23 changes: 23 additions & 0 deletions poetry/semver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .patterns import BASIC_CONSTRAINT
from .patterns import CARET_CONSTRAINT
from .patterns import TILDE_CONSTRAINT
from .patterns import TILDE_PEP440_CONSTRAINT
from .patterns import X_CONSTRAINT
from .version import Version
from .version_constraint import VersionConstraint
Expand Down Expand Up @@ -59,6 +60,28 @@ def parse_single_constraint(constraint): # type: (str) -> VersionConstraint
high = version.stable.next_major

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
m = CARET_CONSTRAINT.match(constraint)
Expand Down
3 changes: 2 additions & 1 deletion poetry/semver/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
COMPLETE_VERSION = re.compile("(?i)" + _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*])+$")
BASIC_CONSTRAINT = re.compile(
"(?i)^(<>|!=|>=?|<=?|==?)?\s*({})".format(_COMPLETE_VERSION)
Expand Down
3 changes: 3 additions & 0 deletions tests/semver/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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-b2", VersionRange(Version(1, 2, 0, "b2"), Version(1, 3, 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):
Expand Down

0 comments on commit c55d55a

Please sign in to comment.