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:
Jan Lindemann 2026-09-15 19:56:47 +02:00
commit f689e4ba94
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
2 changed files with 21 additions and 15 deletions

View file

@ -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)