Skip to content

Commit

Permalink
bpo-41207 In distutils.spawn, rewrite FileNotFound (GH-21359)
Browse files Browse the repository at this point in the history
Automerge-Triggered-By: @jaraco
  • Loading branch information
jaraco authored Jul 7, 2020
1 parent c6fff69 commit e34d6d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 9 additions & 3 deletions spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,15 @@ def spawn(cmd, search_path=1, verbose=0, dry_run=0):
env = dict(os.environ,
MACOSX_DEPLOYMENT_TARGET=cur_target)

proc = subprocess.Popen(cmd, env=env)
proc.wait()
exitcode = proc.returncode
try:
proc = subprocess.Popen(cmd, env=env)
proc.wait()
exitcode = proc.returncode
except OSError as exc:
if not DEBUG:
cmd = cmd[0]
raise DistutilsExecError(
"command %r failed: %s" % (cmd, exc.args[-1])) from exc

if exitcode:
if not DEBUG:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ def test_find_executable(self):
rv = find_executable(program)
self.assertEqual(rv, filename)

def test_spawn_missing_exe(self):
with self.assertRaises(DistutilsExecError) as ctx:
spawn(['does-not-exist'])
self.assertIn("command 'does-not-exist' failed", str(ctx.exception))


def test_suite():
return unittest.makeSuite(SpawnTestCase)
Expand Down

0 comments on commit e34d6d8

Please sign in to comment.