[Python-checkins] bpo-41207 In distutils.spawn, rewrite FileNotFound (GH-21359)

Jason R. Coombs webhook-mailer at python.org
Tue Jul 7 07:11:45 EDT 2020


https://github.com/python/cpython/commit/6ae2780be0667a8dc52c4fb583171ec86067d700
commit: 6ae2780be0667a8dc52c4fb583171ec86067d700
branch: master
author: Jason R. Coombs <jaraco at jaraco.com>
committer: GitHub <noreply at github.com>
date: 2020-07-07T04:11:28-07:00
summary:

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



Automerge-Triggered-By: @jaraco

files:
A Misc/NEWS.d/next/Library/2020-07-06-16-58-53.bpo-41207.Emw7Nk.rst
M Lib/distutils/spawn.py
M Lib/distutils/tests/test_spawn.py

diff --git a/Lib/distutils/spawn.py b/Lib/distutils/spawn.py
index aad277b0ca776..0d1bd0391e6f1 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 3647bab7b1cbc..4ec767b120e71 100644
--- a/Lib/distutils/tests/test_spawn.py
+++ b/Lib/distutils/tests/test_spawn.py
@@ -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)
diff --git a/Misc/NEWS.d/next/Library/2020-07-06-16-58-53.bpo-41207.Emw7Nk.rst b/Misc/NEWS.d/next/Library/2020-07-06-16-58-53.bpo-41207.Emw7Nk.rst
new file mode 100644
index 0000000000000..db99c63f94883
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-07-06-16-58-53.bpo-41207.Emw7Nk.rst
@@ -0,0 +1 @@
+In distutils.spawn, restore expectation that DistutilsExecError is raised when the command is not found.



More information about the Python-checkins mailing list