From 6ff03fadebe3314b1e069ac55cdca8ed73c62b19 Mon Sep 17 00:00:00 2001 From: qlearzyy Date: Mon, 30 Nov 2026 22:14:12 +0100 Subject: [PATCH] gh-88621: Report missing compileall paths as failures --- Doc/library/compileall.rst | 6 ++++-- Lib/compileall.py | 4 ++++ Lib/test/test_compileall.py | 17 ++++++++++++++++- ...026-11-30-21-30-00.gh-issue-88621.Lxk8tG.rst | 2 ++ 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2026-11-30-21-30-00.gh-issue-88621.Lxk8tG.rst diff --git a/Doc/library/compileall.rst b/Doc/library/compileall.rst index ebbbf857e717a4..742a2ef58c226c 100644 --- a/Doc/library/compileall.rst +++ b/Doc/library/compileall.rst @@ -30,8 +30,10 @@ compile Python sources. file ... Positional arguments are files to compile or directories that contain - source files, traversed recursively. If no argument is given, behave as if - the command line was :samp:`-l {}`. + source files, traversed recursively. A named input path that does not exist + causes a nonzero exit status. + If no argument is given, behave as if the command line was + :samp:`-l {}`. .. option:: -l diff --git a/Lib/compileall.py b/Lib/compileall.py index 812a496611e043..276a3543025430 100644 --- a/Lib/compileall.py +++ b/Lib/compileall.py @@ -451,6 +451,10 @@ def main(): limit_sl_dest=args.limit_sl_dest, hardlink_dupes=args.hardlink_dupes): success = False + elif dest and not os.path.exists(dest): + if args.quiet < 2: + print("Can't list {!r}".format(dest)) + success = False else: if not compile_dir(dest, maxlevels, args.ddir, args.force, args.rx, args.quiet, diff --git a/Lib/test/test_compileall.py b/Lib/test/test_compileall.py index 9a6ca2be1624c6..04adb277b2cab2 100644 --- a/Lib/test/test_compileall.py +++ b/Lib/test/test_compileall.py @@ -776,6 +776,19 @@ def test_regexp(self): self.assertNotCompiled(self.barfn) self.assertCompiled(self.initfn) + def test_missing_dir(self): + missing = os.path.join(self.directory, 'missing') + rc, out, err = self.assertRunNotOK('-q', missing, self.pkgdir) + self.assertEqual(rc, 1) + self.assertIn(b"Can't list", out) + self.assertEqual(err, b'') + self.assertCompiled(self.barfn) + + rc, out, err = self.assertRunNotOK('-qq', missing) + self.assertEqual(rc, 1) + self.assertEqual(out, b'') + self.assertEqual(err, b'') + def test_multiple_dirs(self): pkgdir2 = os.path.join(self.directory, 'foo2') os.mkdir(pkgdir2) @@ -864,8 +877,10 @@ def test_compiles_as_much_as_possible(self): self.assertCompiled(self.barfn) def test_invalid_arg_produces_message(self): - out = self.assertRunOK('badfilename') + rc, out, err = self.assertRunNotOK('badfilename') + self.assertEqual(rc, 1) self.assertRegex(out, b"Can't list 'badfilename'") + self.assertEqual(err, b'') def test_pyc_invalidation_mode(self): script_helper.make_script(self.pkgdir, 'f1', '') diff --git a/Misc/NEWS.d/next/Library/2026-11-30-21-30-00.gh-issue-88621.Lxk8tG.rst b/Misc/NEWS.d/next/Library/2026-11-30-21-30-00.gh-issue-88621.Lxk8tG.rst new file mode 100644 index 00000000000000..b08d482ec3e40c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-11-30-21-30-00.gh-issue-88621.Lxk8tG.rst @@ -0,0 +1,2 @@ +Make :mod:`compileall` exit with a nonzero status when an explicitly named +path does not exist.