Skip to content

Commit

Permalink
Extract function for _debug wrapper.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Apr 21, 2024
1 parent d34c81e commit 1288c31
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions distutils/spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
from .errors import DistutilsExecError


def _debug(cmd):
"""
Render a subprocess command differently depending on DEBUG.
"""
return cmd if DEBUG else cmd[0]


def spawn(cmd, search_path=True, verbose=False, dry_run=False, env=None):
"""Run another program, specified as a command list 'cmd', in a new process.
Expand Down Expand Up @@ -58,14 +65,12 @@ def spawn(cmd, search_path=True, verbose=False, dry_run=False, env=None):
try:
subprocess.check_call(cmd, env=env)
except OSError as exc:
if not DEBUG:
cmd = cmd[0]
raise DistutilsExecError(f"command {cmd!r} failed: {exc.args[-1]}") from exc
raise DistutilsExecError(
f"command {_debug(cmd)!r} failed: {exc.args[-1]}"
) from exc
except subprocess.CalledProcessError as err:
if not DEBUG:
cmd = cmd[0]
raise DistutilsExecError(
f"command {cmd!r} failed with exit code {err.returncode}"
f"command {_debug(cmd)!r} failed with exit code {err.returncode}"
) from err


Expand Down

0 comments on commit 1288c31

Please sign in to comment.