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

Handle whitespaces for PEP-440 constraints #16

Merged
merged 1 commit into from
Apr 8, 2020
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
2 changes: 1 addition & 1 deletion poetry/core/semver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def parse_constraint(constraints): # type: (str) -> VersionConstraint
or_groups = []
for constraints in or_constraints:
and_constraints = re.split(
"(?<!^)(?<![=>< ,]) *(?<!-)[, ](?!-) *(?!,|$)", constraints
"(?<!^)(?<![~=>< ,]) *(?<!-)[, ](?!-) *(?!,|$)", constraints
)
constraint_objects = []

Expand Down
4 changes: 2 additions & 2 deletions poetry/core/semver/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
COMPLETE_VERSION = re.compile("(?i)" + _COMPLETE_VERSION)

CARET_CONSTRAINT = re.compile(r"(?i)^\^({})$".format(_COMPLETE_VERSION))
TILDE_CONSTRAINT = re.compile("(?i)^~(?!=)({})$".format(_COMPLETE_VERSION))
TILDE_PEP440_CONSTRAINT = re.compile("(?i)^~=({})$".format(_COMPLETE_VERSION))
TILDE_CONSTRAINT = re.compile(r"(?i)^~(?!=)\s*({})$".format(_COMPLETE_VERSION))
TILDE_PEP440_CONSTRAINT = re.compile(r"(?i)^~=\s*({})$".format(_COMPLETE_VERSION))
X_CONSTRAINT = re.compile(r"^(!=|==)?\s*v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.[xX*])+$")
BASIC_CONSTRAINT = re.compile(
r"(?i)^(<>|!=|>=?|<=?|==?)?\s*({}|dev)".format(_COMPLETE_VERSION)
Expand Down
86 changes: 86 additions & 0 deletions tests/semver/test_parse_constraint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import pytest

from poetry.core.semver import Version
from poetry.core.semver import VersionRange
from poetry.core.semver import VersionUnion
from poetry.core.semver import parse_constraint


@pytest.mark.parametrize(
"constraint,version",
[
("~=3.8", VersionRange(min=Version(3, 8), max=Version(4, 0), include_min=True)),
(
"~= 3.8",
VersionRange(min=Version(3, 8), max=Version(4, 0), include_min=True),
),
("~3.8", VersionRange(min=Version(3, 8), max=Version(3, 9), include_min=True)),
("~ 3.8", VersionRange(min=Version(3, 8), max=Version(3, 9), include_min=True)),
(">3.8", VersionRange(min=Version(3, 8))),
(">=3.8", VersionRange(min=Version(3, 8), include_min=True)),
(">= 3.8", VersionRange(min=Version(3, 8), include_min=True)),
(
">3.8,<=6.5",
VersionRange(min=Version(3, 8), max=Version(6, 5), include_max=True),
),
(
">3.8,<= 6.5",
VersionRange(min=Version(3, 8), max=Version(6, 5), include_max=True),
),
(
"> 3.8,<= 6.5",
VersionRange(min=Version(3, 8), max=Version(6, 5), include_max=True),
),
(
"> 3.8,<=6.5",
VersionRange(min=Version(3, 8), max=Version(6, 5), include_max=True),
),
(
">3.8 ,<=6.5",
VersionRange(min=Version(3, 8), max=Version(6, 5), include_max=True),
),
(
">3.8, <=6.5",
VersionRange(min=Version(3, 8), max=Version(6, 5), include_max=True),
),
(
">3.8 , <=6.5",
VersionRange(min=Version(3, 8), max=Version(6, 5), include_max=True),
),
(
"==3.8",
VersionRange(
min=Version(3, 8), max=Version(3, 8), include_min=True, include_max=True
),
),
(
"== 3.8",
VersionRange(
min=Version(3, 8), max=Version(3, 8), include_min=True, include_max=True
),
),
(
"~2.7 || ~3.8",
VersionUnion(
VersionRange(min=Version(2, 7), max=Version(2, 8), include_min=True),
VersionRange(min=Version(3, 8), max=Version(3, 9), include_min=True),
),
),
(
"~2.7||~3.8",
VersionUnion(
VersionRange(min=Version(2, 7), max=Version(2, 8), include_min=True),
VersionRange(min=Version(3, 8), max=Version(3, 9), include_min=True),
),
),
(
"~ 2.7||~ 3.8",
VersionUnion(
VersionRange(min=Version(2, 7), max=Version(2, 8), include_min=True),
VersionRange(min=Version(3, 8), max=Version(3, 9), include_min=True),
),
),
],
)
def test_parse_constraint(constraint, version):
assert parse_constraint(constraint) == version