lib.version.Version.__resolved_id(): Resolve VERSION to core
__resolved_id() returns the full version if only VERSION was specified, fix that. Also: raise Version.Error instead of a bare Exception. 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 <jan@janware.com>
This commit is contained in:
parent
149739cc93
commit
f689e4ba94
2 changed files with 21 additions and 15 deletions
|
|
@ -38,11 +38,17 @@ class Version: # export
|
|||
raise Version.Error(
|
||||
f'Tried to look up version of {self.base_name} without lookup function'
|
||||
)
|
||||
version = self.__lookup_version(self.base_name)
|
||||
if self.__spec == 'REVISION':
|
||||
parts = version.split('-', 1)
|
||||
return parts[1] if len(parts) == 2 else ''
|
||||
return version
|
||||
resolved = self.__lookup_version(self.base_name)
|
||||
if self.__spec == 'VERSION-REVISION':
|
||||
return resolved
|
||||
parts = resolved.split('-')
|
||||
match self.__spec:
|
||||
case 'VERSION':
|
||||
return parts[0]
|
||||
case 'REVISION':
|
||||
return parts[1] if len(parts) == 2 else ''
|
||||
case _:
|
||||
raise Version.Error(f'Invalid version specifier "{self.__spec}"')
|
||||
|
||||
def __id(self, untemplate: bool, throw: bool = True) -> str:
|
||||
if not untemplate:
|
||||
|
|
@ -145,8 +151,8 @@ class Version: # export
|
|||
|
||||
def id(self, untemplate: bool, include_revision: bool = True) -> str:
|
||||
"""Return the version id: the raw spec if untemplate is False,
|
||||
else the resolved version. With include_revision = False a
|
||||
VERSION spec yields the core version.
|
||||
else the resolved version. A VERSION spec yields the core
|
||||
version.
|
||||
"""
|
||||
if not include_revision and self.__spec == 'VERSION':
|
||||
return self.core(untemplate)
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ except Version.Error:
|
|||
|
||||
# The lookup resolves the macros
|
||||
d = Dependency('foo = VERSION', app.get_version)
|
||||
assert d.constraint_str() == 'foo = 1.2.3-45'
|
||||
assert d.constraint_str() == 'foo = 1.2.3'
|
||||
d = Dependency('foo = VERSION', app.get_version)
|
||||
assert d.constraint_str(include_revision = False) == 'foo = 1.2.3'
|
||||
# Only the VERSION macro loses its revision, VERSION-REVISION and
|
||||
|
|
@ -89,7 +89,7 @@ except Dependency.Error:
|
|||
|
||||
# The lookup uses the base name, not the subpackage name
|
||||
d = Dependency('foo-devel = VERSION', app.get_version)
|
||||
assert d.constraint_str() == 'foo-devel = 1.2.3-45'
|
||||
assert d.constraint_str() == 'foo-devel = 1.2.3'
|
||||
# Unknown projects fail when untemplating
|
||||
try:
|
||||
Dependency('baz = VERSION', app.get_version).constraint_str()
|
||||
|
|
@ -105,8 +105,8 @@ def mapper(project: str) -> str:
|
|||
return '1.2.3-45'
|
||||
|
||||
d = Dependency('foo = VERSION', mapper)
|
||||
assert d.constraint_str() == 'foo = 1.2.3-45'
|
||||
assert d.constraint_str() == 'foo = 1.2.3-45'
|
||||
assert d.constraint_str() == 'foo = 1.2.3'
|
||||
assert d.constraint_str() == 'foo = 1.2.3'
|
||||
assert calls == ['foo']
|
||||
|
||||
# as_range expands full boundaries into a revision range
|
||||
|
|
@ -122,12 +122,12 @@ constraint = d.constraint_str(untemplated = False, as_range = True)
|
|||
assert constraint == 'foo >= VERSION-REVISION foo < 1.2.4'
|
||||
# VERSION is not full, so a VERSION constraint is not expanded
|
||||
d = Dependency('foo = VERSION', app.get_version)
|
||||
assert d.constraint_str(as_range = True) == 'foo = 1.2.3-45'
|
||||
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-45'
|
||||
assert d.constraint_str(as_range = True) == 'foo >= 1.2.3'
|
||||
# '<' and '<=' are not expanded
|
||||
d = Dependency('foo <= VERSION', app.get_version)
|
||||
assert d.constraint_str(as_range = True) == 'foo <= 1.2.3-45'
|
||||
assert d.constraint_str(as_range = True) == 'foo <= 1.2.3'
|
||||
# versions without a full major.minor.micro-revision are not expanded
|
||||
d = Dependency('foo = 1.0', app.get_version)
|
||||
assert d.constraint_str(as_range = True) == 'foo = 1.0'
|
||||
|
|
@ -213,7 +213,7 @@ assert deps[2].constraint_str() == 'baz'
|
|||
|
||||
# parse_deps_spec passes the lookup to the created packages
|
||||
deps = Dependency.parse_deps_spec('foo = VERSION, bar', app.get_version)
|
||||
assert deps[0].constraint_str() == 'foo = 1.2.3-45'
|
||||
assert deps[0].constraint_str() == 'foo = 1.2.3'
|
||||
assert deps[1].constraint_str() == 'bar'
|
||||
|
||||
# Malformed specs are rejected when parsed
|
||||
|
|
|
|||
Loading…
Reference in a new issue