lib.Distro: Fix os-release and cascade macros
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m34s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m30s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 4m30s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m16s
CI / Packaging test (push) Successful in 0s
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m34s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m30s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 4m30s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m16s
CI / Packaging test (push) Successful in 0s
expand_macros() looks up each %{name} via getattr with '-' turned into '_',
but macro_names advertises two names that don't resolve: 'os-release' has
no corresponding attribute, and 'os-cascade' resolves to the list property
os_cascade, which str.replace() rejects. Both macros are listed in the
platform info help output, yet always fail when used in a format string.
The space-joined cascade string is the cascade property, and 'cascade' is
the macro name the make recipes and scripts already use, together with the
--format default in cmds/platform/CmdInfo.py.
Before the App.distro_* properties moved to Distro, the advertised macro
names were derived from the distro_* attribute names, so the advertised
macro was %{cascade}; the hand-written macro_names replaced it with the
list attribute's name.
- Add the missing os_release attribute as an alias of os_release_str
- Advertise the 'cascade' macro in macro_names instead of 'os-cascade',
leaving os_cascade as the purely programmatic list
- Update the platform info help expected output accordingly
- Add unit tests for the os-release field parsers, the derived properties,
and the expansion of every advertised macro
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
This commit is contained in:
parent
94bde9147b
commit
13e6ae8807
4 changed files with 170 additions and 2 deletions
|
|
@ -49,7 +49,7 @@ class Distro(abc.ABC):
|
|||
'name',
|
||||
'codename',
|
||||
'gnu-triplet',
|
||||
'os-cascade',
|
||||
'cascade',
|
||||
'os-release',
|
||||
'pkg-ext',
|
||||
]
|
||||
|
|
@ -210,6 +210,12 @@ class Distro(abc.ABC):
|
|||
)
|
||||
return self.__os_release_str
|
||||
|
||||
# -- expand_macros() looks up macro names via getattr with '-' turned
|
||||
# into '_', so 'os-release' needs this alias
|
||||
@property
|
||||
def os_release(self) -> str:
|
||||
return self.os_release_str
|
||||
|
||||
@cached_property
|
||||
def name(self) -> str:
|
||||
return self.os_release_field('NAME')
|
||||
|
|
@ -284,6 +290,8 @@ class Distro(abc.ABC):
|
|||
|
||||
@classmethod
|
||||
def macros(cls) -> list[str]:
|
||||
# -- The doubled percent is not a typo: the macros are embedded
|
||||
# in an argparse help string, where %% escapes to a literal %
|
||||
return ['%%{' + name + '}' for name in cls.macro_names]
|
||||
|
||||
def expand_macros(self, fmt: str | Iterable[str]) -> str | list[str]:
|
||||
|
|
|
|||
Loading…
Reference in a new issue