cmds.projects.lib.templates.tmpl_render(): RenderValues

tmpl_render()'s "values" argument currently understands dict[str,str|list[str]]. Enhance that to understand the broader RenderValues type, which also includes Iterable[tuple[str, str]], as produced by argparse.add_argument(action='append').

This commit also adds proper type-checking for the values argument. Before, its type had gone unchecked entirely.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-06-04 07:27:52 +02:00
commit 81e71bc5c1
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
3 changed files with 103 additions and 20 deletions

View file

@ -1,8 +1,9 @@
from __future__ import annotations
from typing import TYPE_CHECKING
from .Cmd import Cmd, Parent
from .lib.templates import tmpl_render
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from argparse import ArgumentParser, Namespace
@ -61,24 +62,26 @@ class CmdCreatePkgConfig(Cmd): # export
contents = tmpl_render(
'pkg-config',
{
'prefix': args.prefix,
'name': args.name,
'description': merged['summary'],
'version': args.version,
},
[
{
'prefix': args.prefix,
'name': args.name,
'description': merged['summary'] or '',
'version': args.version,
}
]
)
if args.cflags is not None:
contents += f'Cflags: {args.cflags}\n'
if args.libflags is not None:
contents += f'Libs: {args.libflags}\n'
if merged['requires_run'] is not None:
contents += f'Requires: {self.__cleanup_requires(merged["requires_run"])}'
if merged['requires_build'] is not None:
contents += (
f'Requires.private: {self.__cleanup_requires(merged["requires_build"])}'
)
val = merged.get('requires_run')
if val is not None:
contents += f'Requires: {self.__cleanup_requires(val)}'
val = merged.get('requires_build')
if val is not None:
contents += (f'Requires.private: {self.__cleanup_requires(val)}')
# not sure what to do with requires_devel
print(contents)