summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-07-07 11:31:32 (GMT)
committerGitHub <noreply@github.com>2020-07-07 11:31:32 (GMT)
commit2c82628e9aa2af4b662e92e227618859675dd726 (patch)
tree7c151135444ea1e78f562dd3b0e185eea40a7ef0 /Lib
parentedeaf61b6827ab3a8673aff1fb7717917f08f003 (diff)
downloadcpython-2c82628e9aa2af4b662e92e227618859675dd726.zip
cpython-2c82628e9aa2af4b662e92e227618859675dd726.tar.gz
cpython-2c82628e9aa2af4b662e92e227618859675dd726.tar.bz2
bpo-41207 In distutils.spawn, rewrite FileNotFound (GH-21359)
Automerge-Triggered-By: @jaraco (cherry picked from commit 6ae2780be0667a8dc52c4fb583171ec86067d700) Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/distutils/spawn.py12
-rw-r--r--Lib/distutils/tests/test_spawn.py5
2 files changed, 14 insertions, 3 deletions
diff --git a/Lib/distutils/spawn.py b/Lib/distutils/spawn.py
index aad277b..0d1bd03 100644
--- a/Lib/distutils/spawn.py
+++ b/Lib/distutils/spawn.py
@@ -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:
diff --git a/Lib/distutils/tests/test_spawn.py b/Lib/distutils/tests/test_spawn.py
index cf1faad..ad50381 100644
--- a/Lib/distutils/tests/test_spawn.py
+++ b/Lib/distutils/tests/test_spawn.py
@@ -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)