]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41207 In distutils.spawn, rewrite FileNotFound (GH-21359)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 7 Jul 2020 11:31:32 +0000 (04:31 -0700)
committerGitHub <noreply@github.com>
Tue, 7 Jul 2020 11:31:32 +0000 (04:31 -0700)
Automerge-Triggered-By: @jaraco
(cherry picked from commit 6ae2780be0667a8dc52c4fb583171ec86067d700)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Lib/distutils/spawn.py
Lib/distutils/tests/test_spawn.py
Misc/NEWS.d/next/Library/2020-07-06-16-58-53.bpo-41207.Emw7Nk.rst [new file with mode: 0644]

index aad277b0ca7767c09f470bf402b2053cfcfcf49c..0d1bd0391e6f1134e4472d7e133d8302d564a7dc 100644 (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:
index cf1faad5f4dd5d2ecd1f50e38def83a803f1929c..ad5038142faadf6c488074a607f4a950342c16fc 100644 (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)
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 (file)
index 0000000..db99c63
--- /dev/null
@@ -0,0 +1 @@
+In distutils.spawn, restore expectation that DistutilsExecError is raised when the command is not found.