Skip to content

Commit 6ff03fa

Browse files
committed
gh-88621: Report missing compileall paths as failures
1 parent 114f465 commit 6ff03fa

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

‎Doc/library/compileall.rst‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ compile Python sources.
3030
file ...
3131

3232
Positional arguments are files to compile or directories that contain
33-
source files, traversed recursively. If no argument is given, behave as if
34-
the command line was :samp:`-l {<directories from sys.path>}`.
33+
source files, traversed recursively. A named input path that does not exist
34+
causes a nonzero exit status.
35+
If no argument is given, behave as if the command line was
36+
:samp:`-l {<directories from sys.path>}`.
3537

3638
.. option:: -l
3739

‎Lib/compileall.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,10 @@ def main():
451451
limit_sl_dest=args.limit_sl_dest,
452452
hardlink_dupes=args.hardlink_dupes):
453453
success = False
454+
elif dest and not os.path.exists(dest):
455+
if args.quiet < 2:
456+
print("Can't list {!r}".format(dest))
457+
success = False
454458
else:
455459
if not compile_dir(dest, maxlevels, args.ddir,
456460
args.force, args.rx, args.quiet,

‎Lib/test/test_compileall.py‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,19 @@ def test_regexp(self):
776776
self.assertNotCompiled(self.barfn)
777777
self.assertCompiled(self.initfn)
778778

779+
def test_missing_dir(self):
780+
missing = os.path.join(self.directory, 'missing')
781+
rc, out, err = self.assertRunNotOK('-q', missing, self.pkgdir)
782+
self.assertEqual(rc, 1)
783+
self.assertIn(b"Can't list", out)
784+
self.assertEqual(err, b'')
785+
self.assertCompiled(self.barfn)
786+
787+
rc, out, err = self.assertRunNotOK('-qq', missing)
788+
self.assertEqual(rc, 1)
789+
self.assertEqual(out, b'')
790+
self.assertEqual(err, b'')
791+
779792
def test_multiple_dirs(self):
780793
pkgdir2 = os.path.join(self.directory, 'foo2')
781794
os.mkdir(pkgdir2)
@@ -864,8 +877,10 @@ def test_compiles_as_much_as_possible(self):
864877
self.assertCompiled(self.barfn)
865878

866879
def test_invalid_arg_produces_message(self):
867-
out = self.assertRunOK('badfilename')
880+
rc, out, err = self.assertRunNotOK('badfilename')
881+
self.assertEqual(rc, 1)
868882
self.assertRegex(out, b"Can't list 'badfilename'")
883+
self.assertEqual(err, b'')
869884

870885
def test_pyc_invalidation_mode(self):
871886
script_helper.make_script(self.pkgdir, 'f1', '')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Make :mod:`compileall` exit with a nonzero status when an explicitly named
2+
path does not exist.

0 commit comments

Comments
 (0)