[Python-checkins] cpython (merge 3.3 -> default): Merge: #19532: make compileall with no file/dir args respect -f and -q.

r.david.murray python-checkins at python.org
Mon Dec 16 02:57:08 CET 2013


http://hg.python.org/cpython/rev/0e07ab605e0b
changeset:   87974:0e07ab605e0b
parent:      87972:629852f6d186
parent:      87973:6afad4f29249
user:        R David Murray <rdmurray at bitdance.com>
date:        Sun Dec 15 20:56:00 2013 -0500
summary:
  Merge: #19532: make compileall with no file/dir args respect -f and -q.

files:
  Lib/compileall.py           |   3 ++-
  Lib/test/test_compileall.py |  25 +++++++++++++++++++++++--
  Misc/NEWS                   |   3 +++
  3 files changed, 28 insertions(+), 3 deletions(-)


diff --git a/Lib/compileall.py b/Lib/compileall.py
--- a/Lib/compileall.py
+++ b/Lib/compileall.py
@@ -229,7 +229,8 @@
                         success = False
             return success
         else:
-            return compile_path(legacy=args.legacy)
+            return compile_path(legacy=args.legacy, force=args.force,
+                                quiet=args.quiet)
     except KeyboardInterrupt:
         print("\n[interrupted]")
         return False
diff --git a/Lib/test/test_compileall.py b/Lib/test/test_compileall.py
--- a/Lib/test/test_compileall.py
+++ b/Lib/test/test_compileall.py
@@ -5,8 +5,6 @@
 import py_compile
 import shutil
 import struct
-import subprocess
-import sys
 import tempfile
 import time
 import unittest
@@ -181,6 +179,29 @@
         self.assertNotCompiled(self.initfn)
         self.assertNotCompiled(self.barfn)
 
+    def test_no_args_respects_force_flag(self):
+        bazfn = script_helper.make_script(self.directory, 'baz', '')
+        self.assertRunOK(PYTHONPATH=self.directory)
+        pycpath = importlib.util.cache_from_source(bazfn)
+        # Set atime/mtime backward to avoid file timestamp resolution issues
+        os.utime(pycpath, (time.time()-60,)*2)
+        mtime = os.stat(pycpath).st_mtime
+        # Without force, no recompilation
+        self.assertRunOK(PYTHONPATH=self.directory)
+        mtime2 = os.stat(pycpath).st_mtime
+        self.assertEqual(mtime, mtime2)
+        # Now force it.
+        self.assertRunOK('-f', PYTHONPATH=self.directory)
+        mtime2 = os.stat(pycpath).st_mtime
+        self.assertNotEqual(mtime, mtime2)
+
+    def test_no_args_respects_quiet_flag(self):
+        script_helper.make_script(self.directory, 'baz', '')
+        noisy = self.assertRunOK(PYTHONPATH=self.directory)
+        self.assertIn(b'Listing ', noisy)
+        quiet = self.assertRunOK('-q', PYTHONPATH=self.directory)
+        self.assertNotIn(b'Listing ', quiet)
+
     # Ensure that the default behavior of compileall's CLI is to create
     # PEP 3147 pyc/pyo files.
     for name, ext, switch in [
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -44,6 +44,9 @@
 Library
 -------
 
+- Issue #19532: python -m compileall with no filename/directory arguments now
+  respects the -f and -q flags instead of ignoring them.
+
 - Issue #19623: Fixed writing to unseekable files in the aifc module.
 
 - Issue #19946: multiprocessing.spawn now raises ImportError when the module to

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list