diff options
author | Barry Warsaw <barry@python.org> | 2010-04-26 15:59:03 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2010-04-26 15:59:03 (GMT) |
commit | c04317fdc45ded619a1b66941d1437a5e9a37a73 (patch) | |
tree | 4ad24fecd84e55ecfc977b544f27f9a71751f23e /Lib | |
parent | a1af3e0b9ee9ee150d0ddce1306ce1a7aadf2a03 (diff) | |
download | cpython-c04317fdc45ded619a1b66941d1437a5e9a37a73.zip cpython-c04317fdc45ded619a1b66941d1437a5e9a37a73.tar.gz cpython-c04317fdc45ded619a1b66941d1437a5e9a37a73.tar.bz2 |
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.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/compileall.py | 2 | ||||
-rw-r--r-- | Lib/test/test_compileall.py | 18 |
2 files changed, 20 insertions, 0 deletions
diff --git a/Lib/compileall.py b/Lib/compileall.py index d9d7816..be9e2ad 100644 --- a/Lib/compileall.py +++ b/Lib/compileall.py @@ -45,6 +45,8 @@ def compile_dir(dir, maxlevels=10, ddir=None, 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) diff --git a/Lib/test/test_compileall.py b/Lib/test/test_compileall.py index 8b34587..fe26026 100644 --- a/Lib/test/test_compileall.py +++ b/Lib/test/test_compileall.py @@ -150,6 +150,24 @@ class CommandLineTests(unittest.TestCase): 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( |