Skip to content

Commit 019a26a

Browse files
committed
semver: allow constraints with trailing commas (again)
1 parent 96c43de commit 019a26a

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/poetry/core/semver/helpers.py

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ def parse_constraint(constraints: str) -> VersionConstraint:
1818
or_constraints = re.split(r"\s*\|\|?\s*", constraints.strip())
1919
or_groups = []
2020
for constraints in or_constraints:
21+
# allow trailing commas for robustness (even though it may not be
22+
# standard-compliant it seems to occur in some packages)
23+
constraints = constraints.rstrip(",").rstrip()
2124
and_constraints = re.split(
2225
"(?<!^)(?<![~=>< ,]) *(?<!-)[, ](?!-) *(?!,|$)", constraints
2326
)

tests/semver/test_helpers.py

+35
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,41 @@ def test_parse_constraints_negative_wildcard(
347347
assert parse_constraint(input) == constraint
348348

349349

350+
@pytest.mark.parametrize(
351+
"input,constraint",
352+
[
353+
(">3.7,", VersionRange(min=Version.parse("3.7"))),
354+
(">3.7 , ", VersionRange(min=Version.parse("3.7"))),
355+
(
356+
">3.7,<3.8,",
357+
VersionRange(min=Version.parse("3.7"), max=Version.parse("3.8")),
358+
),
359+
(
360+
">3.7,||<3.6,",
361+
VersionRange(min=Version.parse("3.7")).union(
362+
VersionRange(max=Version.parse("3.6"))
363+
),
364+
),
365+
(
366+
">3.7 , || <3.6 , ",
367+
VersionRange(min=Version.parse("3.7")).union(
368+
VersionRange(max=Version.parse("3.6"))
369+
),
370+
),
371+
(
372+
">3.7, <3.8, || <3.6, >3.5",
373+
VersionRange(min=Version.parse("3.7"), max=Version.parse("3.8")).union(
374+
VersionRange(min=Version.parse("3.5"), max=Version.parse("3.6"))
375+
),
376+
),
377+
],
378+
)
379+
def test_parse_constraints_with_trailing_comma(
380+
input: str, constraint: VersionRange
381+
) -> None:
382+
assert parse_constraint(input) == constraint
383+
384+
350385
@pytest.mark.parametrize(
351386
"input, expected",
352387
[

0 commit comments

Comments
 (0)