[Python-checkins] r80501 - in python/branches/py3k: Lib/compileall.py Lib/test/test_compileall.py Makefile.pre.in

barry.warsaw python-checkins at python.org
Mon Apr 26 17:59:03 CEST 2010


Author: barry.warsaw
Date: Mon Apr 26 17:59:03 2010
New Revision: 80501

Log:
Bug 8527 - multiple compileall calls produce cascading __pycache__ directories.

* Patch contributed by Arfrever Frehtes Taifersar Arahesis.
* Test added by Barry

Also, improve Makefile's deletion of __pycache__ directories so e.g. 'make
distclean' doesn't fail if no __pycache__ directories exist.


Modified:
   python/branches/py3k/Lib/compileall.py
   python/branches/py3k/Lib/test/test_compileall.py
   python/branches/py3k/Makefile.pre.in

Modified: python/branches/py3k/Lib/compileall.py
==============================================================================
--- python/branches/py3k/Lib/compileall.py	(original)
+++ python/branches/py3k/Lib/compileall.py	Mon Apr 26 17:59:03 2010
@@ -45,6 +45,8 @@
     names.sort()
     success = 1
     for name in names:
+        if name == '__pycache__':
+            continue
         fullname = os.path.join(dir, name)
         if ddir is not None:
             dfile = os.path.join(ddir, name)

Modified: python/branches/py3k/Lib/test/test_compileall.py
==============================================================================
--- python/branches/py3k/Lib/test/test_compileall.py	(original)
+++ python/branches/py3k/Lib/test/test_compileall.py	Mon Apr 26 17:59:03 2010
@@ -150,6 +150,24 @@
         expected.sort()
         self.assertEqual(sorted(os.listdir(self.pkgdir)), expected)
 
+    def test_multiple_runs(self):
+        # Bug 8527 reported that multiple calls produced empty
+        # __pycache__/__pycache__ directories.
+        retcode = subprocess.call(
+            (sys.executable, '-m', 'compileall', '-q', self.pkgdir))
+        self.assertEqual(retcode, 0)
+        # Verify the __pycache__ directory contents.
+        cachedir = os.path.join(self.pkgdir, '__pycache__')
+        self.assertTrue(os.path.exists(cachedir))
+        cachecachedir = os.path.join(cachedir, '__pycache__')
+        self.assertFalse(os.path.exists(cachecachedir))
+        # Call compileall again.
+        retcode = subprocess.call(
+            (sys.executable, '-m', 'compileall', '-q', self.pkgdir))
+        self.assertEqual(retcode, 0)
+        self.assertTrue(os.path.exists(cachedir))
+        self.assertFalse(os.path.exists(cachecachedir))
+
 
 def test_main():
     support.run_unittest(

Modified: python/branches/py3k/Makefile.pre.in
==============================================================================
--- python/branches/py3k/Makefile.pre.in	(original)
+++ python/branches/py3k/Makefile.pre.in	Mon Apr 26 17:59:03 2010
@@ -1161,7 +1161,7 @@
 # files, which clobber removes as well
 pycremoval:
 	find $(srcdir) -name '*.py[co]' -exec rm -f {} ';'
-	find $(srcdir) -name '__pycache__' | xargs rmdir
+	find $(srcdir) -name '__pycache__' -exec rmdir {} ';'
 
 rmtestturds:
 	-rm -f *BAD *GOOD *SKIPPED


More information about the Python-checkins mailing list