Skip to content

Commit a4a1f23

Browse files
committed
Extract function for _debug wrapper.
1 parent ffdb32d commit a4a1f23

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

distutils/spawn.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
from .errors import DistutilsExecError
1616

1717

18+
def _debug(cmd):
19+
"""
20+
Render a subprocess command differently depending on DEBUG.
21+
"""
22+
return cmd if DEBUG else cmd[0]
23+
24+
1825
def spawn(cmd, search_path=True, verbose=False, dry_run=False, env=None):
1926
"""Run another program, specified as a command list 'cmd', in a new process.
2027
@@ -52,14 +59,12 @@ def spawn(cmd, search_path=True, verbose=False, dry_run=False, env=None):
5259
try:
5360
subprocess.check_call(cmd, env=env)
5461
except OSError as exc:
55-
if not DEBUG:
56-
cmd = cmd[0]
57-
raise DistutilsExecError(f"command {cmd!r} failed: {exc.args[-1]}") from exc
62+
raise DistutilsExecError(
63+
f"command {_debug(cmd)!r} failed: {exc.args[-1]}"
64+
) from exc
5865
except subprocess.CalledProcessError as err:
59-
if not DEBUG:
60-
cmd = cmd[0]
6166
raise DistutilsExecError(
62-
f"command {cmd!r} failed with exit code {err.returncode}"
67+
f"command {_debug(cmd)!r} failed with exit code {err.returncode}"
6368
) from err
6469

6570

0 commit comments

Comments
 (0)