]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
backend: try to use shlex.join 764/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 5 Aug 2021 15:48:37 +0000 (17:48 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 5 Aug 2021 15:48:52 +0000 (17:48 +0200)
It was added in 3.8, and unfortunately we still support python3.7.
Also remove the last backtick use in output.

mkosi/backend.py

index eb10d50fb4cbbb2f7b10a9bd3ec08944444a860c..97e3bf11be9e8ac400079093e0bfb3947f743e35 100644 (file)
@@ -25,6 +25,14 @@ from typing import (
     Union,
 )
 
+if sys.version_info >= (3, 8):
+    shell_join = shlex.join
+else:
+
+    def shell_join(cmd: List[str]) -> str:
+        return " ".join(shlex.quote(x) for x in cmd)
+
+
 # These types are only generic during type checking and not at runtime, leading
 # to a TypeError during compilation.
 # Let's be as strict as we can with the description for the usage we have.
@@ -395,7 +403,7 @@ def run_workspace_command(
     if result.returncode != 0:
         if "workspace-command" in ARG_DEBUG:
             run(cmdline, check=False)
-        die(f"Workspace command `{' '.join(cmd)}` returned non-zero exit code {result.returncode}.")
+        die(f"Workspace command {shell_join(cmd)} returned non-zero exit code {result.returncode}.")
 
 
 @contextlib.contextmanager
@@ -441,7 +449,7 @@ def spawn(
     **kwargs: Any,
 ) -> Popen:
     if "run" in ARG_DEBUG:
-        MkosiPrinter.info("+ " + " ".join(shlex.quote(x) for x in cmdline))
+        MkosiPrinter.info("+ {shell_join(cmdline)")
 
     if not stdout and not stderr:
         # Unless explicit redirection is done, print all subprocess
@@ -466,7 +474,7 @@ def run(
     **kwargs: Any,
 ) -> CompletedProcess:
     if "run" in ARG_DEBUG:
-        MkosiPrinter.info("+ " + " ".join(shlex.quote(x) for x in cmdline))
+        MkosiPrinter.info("+ {shell_join(cmdline)")
 
     if not stdout and not stderr:
         # Unless explicit redirection is done, print all subprocess