Skip to content

Commit 755d5ea

Browse files
committed
Merge: python#19532: make compileall with no file/dir args respect -f and -q.
2 parents 575596e + 8a1d1e6 commit 755d5ea

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

Lib/compileall.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ def main():
229229
success = False
230230
return success
231231
else:
232-
return compile_path(legacy=args.legacy)
232+
return compile_path(legacy=args.legacy, force=args.force,
233+
quiet=args.quiet)
233234
except KeyboardInterrupt:
234235
print("\n[interrupted]")
235236
return False

Lib/test/test_compileall.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import py_compile
66
import shutil
77
import struct
8-
import subprocess
9-
import sys
108
import tempfile
119
import time
1210
import unittest
@@ -181,6 +179,29 @@ def test_no_args_compiles_path(self):
181179
self.assertNotCompiled(self.initfn)
182180
self.assertNotCompiled(self.barfn)
183181

182+
def test_no_args_respects_force_flag(self):
183+
bazfn = script_helper.make_script(self.directory, 'baz', '')
184+
self.assertRunOK(PYTHONPATH=self.directory)
185+
pycpath = importlib.util.cache_from_source(bazfn)
186+
# Set atime/mtime backward to avoid file timestamp resolution issues
187+
os.utime(pycpath, (time.time()-60,)*2)
188+
mtime = os.stat(pycpath).st_mtime
189+
# Without force, no recompilation
190+
self.assertRunOK(PYTHONPATH=self.directory)
191+
mtime2 = os.stat(pycpath).st_mtime
192+
self.assertEqual(mtime, mtime2)
193+
# Now force it.
194+
self.assertRunOK('-f', PYTHONPATH=self.directory)
195+
mtime2 = os.stat(pycpath).st_mtime
196+
self.assertNotEqual(mtime, mtime2)
197+
198+
def test_no_args_respects_quiet_flag(self):
199+
script_helper.make_script(self.directory, 'baz', '')
200+
noisy = self.assertRunOK(PYTHONPATH=self.directory)
201+
self.assertIn(b'Listing ', noisy)
202+
quiet = self.assertRunOK('-q', PYTHONPATH=self.directory)
203+
self.assertNotIn(b'Listing ', quiet)
204+
184205
# Ensure that the default behavior of compileall's CLI is to create
185206
# PEP 3147 pyc/pyo files.
186207
for name, ext, switch in [

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Core and Builtins
4444
Library
4545
-------
4646

47+
- Issue #19532: python -m compileall with no filename/directory arguments now
48+
respects the -f and -q flags instead of ignoring them.
49+
4750
- Issue #19623: Fixed writing to unseekable files in the aifc module.
4851

4952
- Issue #19946: multiprocessing.spawn now raises ImportError when the module to

0 commit comments

Comments
 (0)