diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-04-18 01:20:21 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-04-18 01:20:21 (GMT) |
commit | 12b6457e24924ff60cf89fd19a584185a5d6c256 (patch) | |
tree | 6ed970bea82d50c12b89edbbf9be39507588cf20 /Lib/compileall.py | |
parent | 3090694068670371cdbd5b1a3d3c5dbecc83835a (diff) | |
download | cpython-12b6457e24924ff60cf89fd19a584185a5d6c256.zip cpython-12b6457e24924ff60cf89fd19a584185a5d6c256.tar.gz cpython-12b6457e24924ff60cf89fd19a584185a5d6c256.tar.bz2 |
Fix compileall.py so that it fails on SyntaxErrors
The changes cause compilation failures in any file in the Python
installation lib directory to cause the install to fail. It looks
like compileall.py intended to behave this way, but a change to
py_compile.py and a separate bug defeated it.
Fixes SF bug #412436
This change affects the test suite, which contains several files that
contain intentional errors. The solution is to extend compileall.py
with the ability to skip compilation of selected files.
NB compileall.py is changed so that compile_dir() returns success only
if all recursive calls to compile_dir() also check success.
Diffstat (limited to 'Lib/compileall.py')
-rw-r--r-- | Lib/compileall.py | 34 |
1 files changed, 26 insertions, 8 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) |