fix(addon): accept PEP 440 post-release versions in compat ranges
2.2.6.post1 made every add-on command fail with VersionSpecError. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,8 @@ user-facing notes live in [`docs/updates/`](docs/updates/) (English and
|
||||
- Editor: the parameter panel reads `scad.var(name="j1", default=0.0, ...)` — the keyword
|
||||
form — as well as `scad.var("j1", 0.0, ...)`. Before, only the second positional argument
|
||||
was taken as the default, so keyword declarations never showed up as parameters.
|
||||
- Add-ons: `[compat] sca` ranges and the add-on commands accept a post-release version such as
|
||||
`2.2.6.post1` (it sorts after `2.2.6` and before `2.2.7`); the parser rejected it.
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@ Supported syntax — deliberately a small, documented subset:
|
||||
* versions are dot-separated numeric components with optional
|
||||
pre-release suffixes (``2.1.2``, ``2.0.4b2``); a suffix sorts before
|
||||
the same numeric component without one (``2.0.4b2 < 2.0.4``);
|
||||
* a trailing ``.postN`` component is a post-release (PEP 440): it sorts
|
||||
after the release it follows and before the next one
|
||||
(``2.2.6 < 2.2.6.post1 < 2.2.6.post2 < 2.2.7``);
|
||||
* ranges are comma-separated clauses with the operators
|
||||
``== != >= <= > <``; a bare version means exact equality;
|
||||
* clauses must be jointly satisfiable (``>=2.1,<2.0`` is rejected).
|
||||
@@ -21,6 +24,7 @@ from . import AddonError
|
||||
|
||||
_CLAUSE_RE = re.compile(r"^(==|!=|>=|<=|>|<)?\s*([0-9][0-9A-Za-z.]*)$")
|
||||
_COMPONENT_RE = re.compile(r"^([0-9]+)([a-zA-Z][0-9A-Za-z]*)?$")
|
||||
_POST_RE = re.compile(r"^post([0-9]+)$")
|
||||
|
||||
|
||||
class VersionSpecError(AddonError):
|
||||
@@ -34,6 +38,12 @@ def version_key(text: str) -> tuple[tuple[int, int, str], ...]:
|
||||
raise VersionSpecError("empty version literal")
|
||||
components: list[tuple[int, int, str]] = []
|
||||
for part in stripped.split("."):
|
||||
post = _POST_RE.match(part)
|
||||
if post is not None and components:
|
||||
# after the release it follows (a missing component pads as (0, 1, "")),
|
||||
# and in order among post-releases
|
||||
components.append((int(post.group(1)), 2, ""))
|
||||
continue
|
||||
match = _COMPONENT_RE.match(part)
|
||||
if match is None:
|
||||
raise VersionSpecError(
|
||||
|
||||
@@ -50,8 +50,27 @@ def test_prerelease_suffix_sorts_before_release():
|
||||
assert compare_versions("2.1.2", "2.1.2") == 0
|
||||
|
||||
|
||||
def test_post_release_sorts_after_its_release_and_before_the_next():
|
||||
# the SDK itself is released as 2.2.6.post1 (PEP 440): compat ranges are
|
||||
# checked against that version
|
||||
assert compare_versions("2.2.6.post1", "2.2.6") == 1
|
||||
assert compare_versions("2.2.6", "2.2.6.post1") == -1
|
||||
assert compare_versions("2.2.6.post2", "2.2.6.post1") == 1
|
||||
assert compare_versions("2.2.6.post10", "2.2.6.post2") == 1
|
||||
assert compare_versions("2.2.7", "2.2.6.post9") == 1
|
||||
assert compare_versions("2.2.6.post1", "2.2.6.post1") == 0
|
||||
assert compare_versions("2.2.6b2", "2.2.6.post1") == -1
|
||||
|
||||
|
||||
def test_ranges_hold_for_a_post_release():
|
||||
assert VersionRange.parse(">=2.2.6,<2.2.7").matches("2.2.6.post1")
|
||||
assert VersionRange.parse("==2.2.6.post1").matches("2.2.6.post1")
|
||||
assert not VersionRange.parse("<=2.2.6").matches("2.2.6.post1")
|
||||
assert not VersionRange.parse(">=2.2.7").matches("2.2.6.post1")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"spec", ["", " ", "*", "2.*", ">=2.1,,3", ">=", "==x.y", "v2.1"]
|
||||
"spec", ["", " ", "*", "2.*", ">=2.1,,3", ">=", "==x.y", "v2.1", "2.2.post", "2.2.postx"]
|
||||
)
|
||||
def test_invalid_specs_are_rejected_with_named_error(spec):
|
||||
with pytest.raises(VersionSpecError):
|
||||
|
||||
Reference in New Issue
Block a user