From: Daan De Meyer Date: Sun, 16 Jul 2023 16:01:43 +0000 (+0200) Subject: Replace kwargs from bwrap with individual arguments X-Git-Tag: v15~76^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fca9c7d0d61c9dd4320c531e1756c8fa45f6ac85;p=thirdparty%2Fmkosi.git Replace kwargs from bwrap with individual arguments kwargs makes it impossible for mypy to point out wrong arguments so let's drop it in favor of individual arguments to get more out of the type checker. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 9cc3d3100..21c2b5157 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -1032,8 +1032,8 @@ def maybe_compress(state: MkosiState, compression: Compression, src: Path, dst: src.unlink() # if src == dst, make sure dst doesn't truncate the src file but creates a new file. with dst.open("wb") as o: - bwrap(compressor_command(compression), user=state.uid, group=state.gid, stdin=i, stdout=o, - tools=state.config.tools_tree) + bwrap(compressor_command(compression), stdin=i, stdout=o, tools=state.config.tools_tree) + os.chown(dst, uid=state.uid, gid=state.gid) def copy_nspawn_settings(state: MkosiState) -> None: diff --git a/mkosi/run.py b/mkosi/run.py index 76e074372..b36a6e279 100644 --- a/mkosi/run.py +++ b/mkosi/run.py @@ -367,9 +367,14 @@ def bwrap( *, tools: Optional[Path] = None, apivfs: Optional[Path] = None, - env: Mapping[str, PathString] = {}, log: bool = True, - **kwargs: Any, + # The following arguments are passed directly to run(). + stdin: _FILE = None, + stdout: _FILE = None, + stderr: _FILE = None, + input: Optional[str] = None, + check: bool = True, + env: Mapping[str, PathString] = {}, ) -> CompletedProcess: with bwrap_cmd(tools=tools, apivfs=apivfs) as bwrap: if tools: @@ -380,12 +385,28 @@ def bwrap( env = dict(PATH="/usr/bin:/usr/sbin") | env try: - result = run([*bwrap, *cmd], text=True, env=env, log=False, **kwargs) + result = run( + [*bwrap, *cmd], + text=True, + env=env, + log=False, + stdin=stdin, + stdout=stdout, + stderr=stderr, + input=input, + check=check, + ) except subprocess.CalledProcessError as e: if log: logging.error(f"\"{' '.join(str(s) for s in cmd)}\" returned non-zero exit code {e.returncode}.") if ARG_DEBUG_SHELL.get(): - run([*bwrap, "sh"], stdin=sys.stdin, check=False, env=env, log=False) + run( + [*bwrap, "sh"], + stdin=sys.stdin, + check=False, + env=env, + log=False, + ) raise e return result