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

semver: allow constraints with trailing commas (again) #371

Merged
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
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()
radoering marked this conversation as resolved.
Show resolved Hide resolved
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