Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8a1d1e6

Browse files
committed
#19532: make compileall with no file/dir args respect -f and -q.
Patch by Vajrasky Kok.
1 parent 1f1ec12 commit 8a1d1e6

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

Lib/compileall.py

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

Lib/test/test_compileall.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,29 @@ def test_no_args_compiles_path(self):
177177
self.assertNotCompiled(self.initfn)
178178
self.assertNotCompiled(self.barfn)
179179

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

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Core and Builtins
2929
Library
3030
-------
3131

32+
- Issue #19532: python -m compileall with no filename/directory arguments now
33+
respects the -f and -q flags instead of ignoring them.
34+
3235
- Issue #19623: Fixed writing to unseekable files in the aifc module.
3336

3437
- Issue #17919: select.poll.register() again works with poll.POLLNVAL on AIX.

0 commit comments

Comments
 (0)