From 3f00f4a416bff46b1c4228bed286eba66bc07227 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Tue, 15 Sep 2026 19:58:24 +0200 Subject: [PATCH] lib.version.Dependency.__version_boundaries(): Use Version.next() Use Version.next() in __version_boundaries, which steps the last existing part, so '= 1.0' spans '>= 1.0, < 1.1'. Tests written by AI. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1 Signed-off-by: Jan Lindemann --- src/python/jw/pkg/lib/version/Dependency.py | 16 +++++++++------- test/unit/python/jw/pkg/lib/version/test.py | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/python/jw/pkg/lib/version/Dependency.py b/src/python/jw/pkg/lib/version/Dependency.py index b9fb9f49..f09b4e30 100644 --- a/src/python/jw/pkg/lib/version/Dependency.py +++ b/src/python/jw/pkg/lib/version/Dependency.py @@ -74,13 +74,14 @@ class Dependency: # export return (specified, ) ret: list[Boundary] = [] match specified.op: - case '>' | '>=': - ret.append(specified) - ret.append(Boundary('<', specified.version.next_binary_incompatible)) case '=': + try: + next_version = specified.version.next + except Version.Error: + return (specified, ) ret.append(Boundary('>=', specified.version)) - ret.append(Boundary('<', specified.version.next_binary_incompatible)) - case '<' | '<=': + ret.append(Boundary('<', next_version)) + case '>' | '>=' | '<' | '<=': ret.append(specified) case _: self.__raise( @@ -150,8 +151,9 @@ class Dependency: # export NAMES_ONLY renders the name alone. With untemplated = False the VERSION, VERSION-REVISION and REVISION macros are kept as written instead of resolved. include_revision = False drops the - revision of VERSION specs. as_range expands a boundary that - pins a full version into the range it spans. no_subpackages + revision of VERSION specs. as_range expands a = boundary that + does not pin a full version into the range it spans; other + operators pass through unchanged. no_subpackages renders the base name, quote wraps the result in the given string. """ diff --git a/test/unit/python/jw/pkg/lib/version/test.py b/test/unit/python/jw/pkg/lib/version/test.py index b3525225..72a62ba2 100644 --- a/test/unit/python/jw/pkg/lib/version/test.py +++ b/test/unit/python/jw/pkg/lib/version/test.py @@ -109,7 +109,7 @@ assert d.constraint_str() == 'foo = 1.2.3' assert d.constraint_str() == 'foo = 1.2.3' assert calls == ['foo'] -# as_range expands a non-full boundary into the range it spans +# as_range expands a non-full = boundary into the range it spans d = Dependency('foo = VERSION-REVISION', app.get_version) assert d.constraint_str(as_range = True) == 'foo = 1.2.3-45' d = Dependency('foo >= VERSION-REVISION', app.get_version) @@ -123,14 +123,22 @@ assert constraint == 'foo = VERSION-REVISION' # A full version stays exact; a non-full one expands d = Dependency('foo = VERSION', app.get_version) assert d.constraint_str(as_range = True) == 'foo >= 1.2.3, foo < 1.2.4' +# Operators other than = pass through unchanged d = Dependency('foo >= VERSION', app.get_version) -assert d.constraint_str(as_range = True) == 'foo >= 1.2.3, foo < 1.2.4' -# '<' and '<=' are not expanded +assert d.constraint_str(as_range = True) == 'foo >= 1.2.3' d = Dependency('foo <= VERSION', app.get_version) assert d.constraint_str(as_range = True) == 'foo <= 1.2.3' -# The bound steps a micro, so a tripartite core expands +# The bound steps the last part, whatever it is +d = Dependency('foo = 1.0', app.get_version) +assert d.constraint_str(as_range = True) == 'foo >= 1.0, foo < 1.1' d = Dependency('foo = 1.2.3', app.get_version) assert d.constraint_str(as_range = True) == 'foo >= 1.2.3, foo < 1.2.4' +d = Dependency('foo = 1.2.3rc1', app.get_version) +assert d.constraint_str(as_range = True) == 'foo >= 1.2.3rc1, foo < 1.2.4' +# A last part without leading digits cannot be stepped, so the pin +# stays exact +d = Dependency('foo = 1.0-rc1', app.get_version) +assert d.constraint_str(as_range = True) == 'foo = 1.0-rc1' # Default syntax is SEM_VER d = Dependency('foo < 2.0') assert d.constraint_str(untemplated = False) == 'foo < 2.0'