bpo-41207 In distutils.spawn, rewrite FileNotFound (GH-21359)

Automerge-Triggered-By: @jaraco
(cherry picked from commit 6ae2780be0)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
This commit is contained in:
Miss Islington (bot) 2020-07-07 04:31:32 -07:00 committed by GitHub
parent edeaf61b68
commit 2c82628e9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 3 deletions

View file

@ -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:

View file

@ -124,6 +124,11 @@ class SpawnTestCase(support.TempdirManager,
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)

View file

@ -0,0 +1 @@
In distutils.spawn, restore expectation that DistutilsExecError is raised when the command is not found.