cmds.projects.CmdCreateFile: Fix spurious trailing newline

create-file and create-pkg-config both print the rendered template with a
newline appended over the original template, owed to using print() instead
of sys.stdout.write(). Fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-09-11 20:47:20 +02:00
commit 174c6fba16
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
2 changed files with 13 additions and 6 deletions

View file

@ -1,3 +1,5 @@
import sys
from argparse import ArgumentParser, ArgumentTypeError, Namespace from argparse import ArgumentParser, ArgumentTypeError, Namespace
from enum import Enum, auto from enum import Enum, auto
from typing import override from typing import override
@ -132,4 +134,4 @@ class CmdCreateFile(Cmd): # export
method = getattr(self, 'render_' + args.format, None) method = getattr(self, 'render_' + args.format, None)
if method is None: # Should be prevented by choices=[] but keeps linter happy if method is None: # Should be prevented by choices=[] but keeps linter happy
raise Exception(f'Unsupported output format {args.format}') raise Exception(f'Unsupported output format {args.format}')
print(method(args.module, args.field)) sys.stdout.write(method(args.module, args.field))

View file

@ -1,5 +1,7 @@
from __future__ import annotations from __future__ import annotations
import sys
from typing import TYPE_CHECKING, override from typing import TYPE_CHECKING, override
from .Cmd import Cmd, Parent from .Cmd import Cmd, Parent
@ -74,16 +76,19 @@ class CmdCreatePkgConfig(Cmd): # export
] ]
) )
extra: list[str] = []
if args.cflags is not None: if args.cflags is not None:
contents += f'Cflags: {args.cflags}\n' extra.append(f'Cflags: {args.cflags}')
if args.libflags is not None: if args.libflags is not None:
contents += f'Libs: {args.libflags}\n' extra.append(f'Libs: {args.libflags}')
val = merged.get('requires_run') val = merged.get('requires_run')
if val is not None: if val is not None:
contents += f'Requires: {self.__cleanup_requires(val)}' extra.append(f'Requires: {self.__cleanup_requires(val)}')
val = merged.get('requires_build') val = merged.get('requires_build')
if val is not None: if val is not None:
contents += (f'Requires.private: {self.__cleanup_requires(val)}') extra.append(f'Requires.private: {self.__cleanup_requires(val)}')
# not sure what to do with requires_devel # not sure what to do with requires_devel
print(contents) if extra:
contents += '\n'.join(extra)
sys.stdout.write(contents)