From 80523f224e2f07b04bf14ec098da7108cdb1e070 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 5 Aug 2021 17:48:37 +0200 Subject: [PATCH] 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. --- mkosi/backend.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 -- 2.47.2