]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Replace kwargs from bwrap with individual arguments
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 16 Jul 2023 16:01:43 +0000 (18:01 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 16 Jul 2023 16:06:09 +0000 (18:06 +0200)
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.

mkosi/__init__.py
mkosi/run.py

index 9cc3d3100e05c56729609ed4c4c2fc46c410f308..21c2b51579b50351a8f396ee896b1f4b95271436 100644 (file)
@@ -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:
index 76e0743727c9b850c074727c33a33acbf53e543b..b36a6e279630e8021084102ae064b3d2a59024ed 100644 (file)
@@ -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