[Python-checkins] CVS: python/dist/src/Lib compileall.py,1.8,1.9
Jeremy Hylton
jhylton@users.sourceforge.net
Tue, 17 Apr 2001 18:20:23 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv24014/Lib
Modified Files:
compileall.py
Log Message:
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.
Index: compileall.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/compileall.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** compileall.py 2001/01/20 19:54:20 1.8
--- compileall.py 2001/04/18 01:20:21 1.9
***************
*** 20,24 ****
__all__ = ["compile_dir","compile_path"]
! def compile_dir(dir, maxlevels=10, ddir=None, force=0):
"""Byte-compile all modules in the given directory tree.
--- 20,24 ----
__all__ = ["compile_dir","compile_path"]
! def compile_dir(dir, maxlevels=10, ddir=None, force=0, rx=None):
"""Byte-compile all modules in the given directory tree.
***************
*** 46,49 ****
--- 46,53 ----
else:
dfile = None
+ if rx:
+ mo = rx.search(fullname)
+ if mo:
+ continue
if os.path.isfile(fullname):
head, tail = name[:-3], name[-3:]
***************
*** 56,63 ****
print 'Compiling', fullname, '...'
try:
! py_compile.compile(fullname, None, dfile)
except KeyboardInterrupt:
raise KeyboardInterrupt
except:
if type(sys.exc_type) == type(''):
exc_type_name = sys.exc_type
--- 60,68 ----
print 'Compiling', fullname, '...'
try:
! 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
***************
*** 66,74 ****
print sys.exc_value
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)
return success
--- 71,83 ----
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):
! if not compile_dir(fullname, maxlevels - 1, dfile, force, rx):
! success = 0
return success
***************
*** 95,114 ****
import getopt
try:
! opts, args = getopt.getopt(sys.argv[1:], 'lfd:')
except getopt.error, msg:
print msg
! print "usage: compileall [-l] [-f] [-d destdir] [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"
sys.exit(2)
maxlevels = 10
ddir = None
force = 0
for o, a in opts:
if o == '-l': maxlevels = 0
if o == '-d': ddir = a
if o == '-f': force = 1
if ddir:
if len(args) != 1:
--- 104,130 ----
import getopt
try:
! opts, args = getopt.getopt(sys.argv[1:], 'lfd:x:')
except getopt.error, msg:
print msg
! 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 "-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:
***************
*** 119,123 ****
if args:
for dir in args:
! success = success and compile_dir(dir, maxlevels, ddir, force)
else:
success = compile_path()
--- 135,140 ----
if args:
for dir in args:
! if not compile_dir(dir, maxlevels, ddir, force, rx):
! success = 0
else:
success = compile_path()
***************
*** 128,130 ****
if __name__ == '__main__':
! sys.exit(not main())
--- 145,148 ----
if __name__ == '__main__':
! exit_status = not main()
! sys.exit(exit_status)