Bug 8563 - compileall.compile_file() creates empty __pycache__ directories in
data directories where there is no source.
Fix by: Arfrever Frehtes Taifersar Arahesis (Arfrever)
Test by: Barry
diff --git a/Lib/compileall.py b/Lib/compileall.py
index be9e2ad..ea2ee7f 100644
--- a/Lib/compileall.py
+++ b/Lib/compileall.py
@@ -91,13 +91,14 @@
else:
cfile = imp.cache_from_source(fullname)
cache_dir = os.path.dirname(cfile)
- try:
- os.mkdir(cache_dir)
- except OSError as error:
- if error.errno != errno.EEXIST:
- raise
head, tail = name[:-3], name[-3:]
if tail == '.py':
+ if not legacy:
+ try:
+ os.mkdir(cache_dir)
+ except OSError as error:
+ if error.errno != errno.EEXIST:
+ raise
if not force:
try:
mtime = int(os.stat(fullname).st_mtime)