summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/compileall.py34
-rw-r--r--Makefile.pre.in5
2 files changed, 29 insertions, 10 deletions
diff --git a/Lib/compileall.py b/Lib/compileall.py
index 93ec7ad..cb4a3e9 100644
--- a/Lib/compileall.py
+++ b/Lib/compileall.py
@@ -19,7 +19,7 @@ import py_compile
__all__ = ["compile_dir","compile_path"]
-def compile_dir(dir, maxlevels=10, ddir=None, force=0):
+def compile_dir(dir, maxlevels=10, ddir=None, force=0, rx=None):
"""Byte-compile all modules in the given directory tree.
Arguments (only dir is required):
@@ -45,6 +45,10 @@ def compile_dir(dir, maxlevels=10, ddir=None, force=0):
dfile = os.path.join(ddir, name)
else:
dfile = None
+ if rx:
+ mo = rx.search(fullname)
+ if mo:
+ continue
if os.path.isfile(fullname):
head, tail = name[:-3], name[-3:]
if tail == '.py':
@@ -55,21 +59,26 @@ def compile_dir(dir, maxlevels=10, ddir=None, force=0):
if (ctime > ftime) and not force: continue
print 'Compiling', fullname, '...'
try:
- py_compile.compile(fullname, None, dfile)
+ ok = py_compile.compile(fullname, None, dfile)
except KeyboardInterrupt:
raise KeyboardInterrupt
except:
+ # XXX py_compile catches SyntaxErrors
if type(sys.exc_type) == type(''):
exc_type_name = sys.exc_type
else: exc_type_name = sys.exc_type.__name__
print 'Sorry:', exc_type_name + ':',
print sys.exc_value
success = 0
+ else:
+ if ok == 0:
+ success = 0
elif maxlevels > 0 and \
name != os.curdir and name != os.pardir and \
os.path.isdir(fullname) and \
not os.path.islink(fullname):
- compile_dir(fullname, maxlevels - 1, dfile, force)
+ if not compile_dir(fullname, maxlevels - 1, dfile, force, rx):
+ success = 0
return success
def compile_path(skip_curdir=1, maxlevels=0, force=0):
@@ -94,22 +103,29 @@ def main():
"""Script main program."""
import getopt
try:
- opts, args = getopt.getopt(sys.argv[1:], 'lfd:')
+ opts, args = getopt.getopt(sys.argv[1:], 'lfd:x:')
except getopt.error, msg:
print msg
- print "usage: compileall [-l] [-f] [-d destdir] [directory ...]"
+ print "usage: python compileall.py [-l] [-f] [-d destdir] " \
+ "[-s regexp] [directory ...]"
print "-l: don't recurse down"
print "-f: force rebuild even if timestamps are up-to-date"
print "-d destdir: purported directory name for error messages"
- print "if no directory arguments, -l sys.path is assumed"
+ print " if no directory arguments, -l sys.path is assumed"
+ print "-x regexp: skip files matching the regular expression regexp"
+ print " the regexp is search for in the full path of the file"
sys.exit(2)
maxlevels = 10
ddir = None
force = 0
+ rx = None
for o, a in opts:
if o == '-l': maxlevels = 0
if o == '-d': ddir = a
if o == '-f': force = 1
+ if o == '-x':
+ import re
+ rx = re.compile(a)
if ddir:
if len(args) != 1:
print "-d destdir require exactly one directory argument"
@@ -118,7 +134,8 @@ def main():
try:
if args:
for dir in args:
- success = success and compile_dir(dir, maxlevels, ddir, force)
+ if not compile_dir(dir, maxlevels, ddir, force, rx):
+ success = 0
else:
success = compile_path()
except KeyboardInterrupt:
@@ -127,4 +144,5 @@ def main():
return success
if __name__ == '__main__':
- sys.exit(not main())
+ exit_status = not main()
+ sys.exit(exit_status)
diff --git a/Makefile.pre.in b/Makefile.pre.in
index f81702b..f2f3336 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -616,9 +616,10 @@ libinstall: $(PYTHON) $(srcdir)/Lib/$(PLATDIR)
done
$(INSTALL_DATA) $(srcdir)/LICENSE $(LIBDEST)/LICENSE.txt
PYTHONPATH=$(LIBDEST) \
- ./$(PYTHON) -tt $(LIBDEST)/compileall.py $(LIBDEST)
+ ./$(PYTHON) -tt $(LIBDEST)/compileall.py -x badsyntax \
+ $(LIBDEST)
PYTHONPATH=$(LIBDEST) \
- ./$(PYTHON) -O $(LIBDEST)/compileall.py $(LIBDEST)
+ ./$(PYTHON) -O $(LIBDEST)/compileall.py -x badsyntax $(LIBDEST)
# Create the PLATDIR source directory, if one wasn't distributed..
$(srcdir)/Lib/$(PLATDIR):