From: Zbigniew Jędrzejewski-Szmek Date: Thu, 5 Aug 2021 15:48:37 +0000 (+0200) Subject: backend: try to use shlex.join X-Git-Tag: v11~80^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F764%2Fhead;p=thirdparty%2Fmkosi.git backend: try to use shlex.join It was added in 3.8, and unfortunately we still support python3.7. Also remove the last backtick use in output. --- diff --git a/mkosi/backend.py b/mkosi/backend.py index eb10d50fb..97e3bf11b 100644 --- a/mkosi/backend.py +++ b/mkosi/backend.py @@ -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