Skip to content

Commit 2c82628

Browse files
bpo-41207 In distutils.spawn, rewrite FileNotFound (GH-21359)
Automerge-Triggered-By: @jaraco (cherry picked from commit 6ae2780) Co-authored-by: Jason R. Coombs <[email protected]>
1 parent edeaf61 commit 2c82628

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

Lib/distutils/spawn.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,15 @@ def spawn(cmd, search_path=1, verbose=0, dry_run=0):
7171
env = dict(os.environ,
7272
MACOSX_DEPLOYMENT_TARGET=cur_target)
7373

74-
proc = subprocess.Popen(cmd, env=env)
75-
proc.wait()
76-
exitcode = proc.returncode
74+
try:
75+
proc = subprocess.Popen(cmd, env=env)
76+
proc.wait()
77+
exitcode = proc.returncode
78+
except OSError as exc:
79+
if not DEBUG:
80+
cmd = cmd[0]
81+
raise DistutilsExecError(
82+
"command %r failed: %s" % (cmd, exc.args[-1])) from exc
7783

7884
if exitcode:
7985
if not DEBUG:

Lib/distutils/tests/test_spawn.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ def test_find_executable(self):
124124
rv = find_executable(program)
125125
self.assertEqual(rv, filename)
126126

127+
def test_spawn_missing_exe(self):
128+
with self.assertRaises(DistutilsExecError) as ctx:
129+
spawn(['does-not-exist'])
130+
self.assertIn("command 'does-not-exist' failed", str(ctx.exception))
131+
127132

128133
def test_suite():
129134
return unittest.makeSuite(SpawnTestCase)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In distutils.spawn, restore expectation that DistutilsExecError is raised when the command is not found.

0 commit comments

Comments
 (0)