From f3b4a9972163e6063b9d37db6352a54735955d81 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 5 Jul 2020 16:31:24 -0400 Subject: Add test for spawn when exe is missing. Ref pypa/distutils#3. --- distutils/tests/test_spawn.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/distutils/tests/test_spawn.py b/distutils/tests/test_spawn.py index 919d0ad9..704019a1 100644 --- a/distutils/tests/test_spawn.py +++ b/distutils/tests/test_spawn.py @@ -126,6 +126,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']) + assert 'command does-no-exist failed' in str(ctx) + def test_suite(): return unittest.makeSuite(SpawnTestCase) -- cgit v1.2.3 From 7aa5abeafc1e0b1b351c4c8ac7eb14c310366a46 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 5 Jul 2020 16:33:16 -0400 Subject: Replace OSError with DistutilsExecError. Fixes pypa/distutils#3 and pypa/setuptools#2228 and bpo-41207. --- distutils/spawn.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/distutils/spawn.py b/distutils/spawn.py index aad277b0..0d1bd039 100644 --- a/distutils/spawn.py +++ b/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: -- cgit v1.2.3