Skip to content

Commit

Permalink
semver: allow constraints with trailing commas (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering authored and abn committed May 24, 2022
1 parent 96c43de commit becf970
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/poetry/core/semver/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def parse_constraint(constraints: str) -> VersionConstraint:
or_constraints = re.split(r"\s*\|\|?\s*", constraints.strip())
or_groups = []
for constraints in or_constraints:
# allow trailing commas for robustness (even though it may not be
# standard-compliant it seems to occur in some packages)
constraints = constraints.rstrip(",").rstrip()
and_constraints = re.split(
"(?<!^)(?<![~=>< ,]) *(?<!-)[, ](?!-) *(?!,|$)", constraints
)
Expand Down
35 changes: 35 additions & 0 deletions tests/semver/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,41 @@ def test_parse_constraints_negative_wildcard(
assert parse_constraint(input) == constraint


@pytest.mark.parametrize(
"input,constraint",
[
(">3.7,", VersionRange(min=Version.parse("3.7"))),
(">3.7 , ", VersionRange(min=Version.parse("3.7"))),
(
">3.7,<3.8,",
VersionRange(min=Version.parse("3.7"), max=Version.parse("3.8")),
),
(
">3.7,||<3.6,",
VersionRange(min=Version.parse("3.7")).union(
VersionRange(max=Version.parse("3.6"))
),
),
(
">3.7 , || <3.6 , ",
VersionRange(min=Version.parse("3.7")).union(
VersionRange(max=Version.parse("3.6"))
),
),
(
">3.7, <3.8, || <3.6, >3.5",
VersionRange(min=Version.parse("3.7"), max=Version.parse("3.8")).union(
VersionRange(min=Version.parse("3.5"), max=Version.parse("3.6"))
),
),
],
)
def test_parse_constraints_with_trailing_comma(
input: str, constraint: VersionRange
) -> None:
assert parse_constraint(input) == constraint


@pytest.mark.parametrize(
"input, expected",
[
Expand Down

0 comments on commit becf970

Please sign in to comment.