Mercurial > cpython-lru_cache-weakref
annotate Lib/compileall.py @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | 13807703afd0 |
| children | 08c5473bedcc |
| rev | line source |
|---|---|
|
7126
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
1 """Module/script to "compile" all .py files to .pyc (or .pyo) file. |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
2 |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
3 When called as a script with arguments, this compiles the directories |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
4 given as arguments recursively; the -l option prevents it from |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
5 recursing into directories. |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
6 |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
7 Without arguments, if compiles all modules on sys.path, without |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
8 recursing into subdirectories. (Even though it should do so for |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
9 packages -- for now, you'll have to deal with packages separately.) |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
10 |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
11 See module py_compile for details of the actual byte-compilation. |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
12 |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
13 """ |
|
1828
b464e1d0b2fb
New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 import os |
|
b464e1d0b2fb
New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 import sys |
|
b464e1d0b2fb
New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 import py_compile |
|
51500
584c47d8c93f
compileall used the ctime of bytecode and source to determine if the bytecode
Brett Cannon <bcannon@gmail.com>
parents:
45657
diff
changeset
|
17 import struct |
|
584c47d8c93f
compileall used the ctime of bytecode and source to determine if the bytecode
Brett Cannon <bcannon@gmail.com>
parents:
45657
diff
changeset
|
18 import imp |
|
1828
b464e1d0b2fb
New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 |
|
16070
b5345e99596b
added __all__ lists to a number of Python modules
Skip Montanaro <skip@pobox.com>
parents:
10498
diff
changeset
|
20 __all__ = ["compile_dir","compile_path"] |
|
b5345e99596b
added __all__ lists to a number of Python modules
Skip Montanaro <skip@pobox.com>
parents:
10498
diff
changeset
|
21 |
|
22374
2417694324ef
Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents:
17559
diff
changeset
|
22 def compile_dir(dir, maxlevels=10, ddir=None, |
|
2417694324ef
Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents:
17559
diff
changeset
|
23 force=0, rx=None, quiet=0): |
|
7126
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
24 """Byte-compile all modules in the given directory tree. |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
25 |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
26 Arguments (only dir is required): |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
27 |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
28 dir: the directory to byte-compile |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
29 maxlevels: maximum recursion level (default 10) |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
30 ddir: if given, purported directory name (this is the |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
31 directory name that will show up in error messages) |
|
9664
4eee061dac44
A mod whose author I forget. (I must've mislaid the email. If it's
Guido van Rossum <guido@python.org>
parents:
7755
diff
changeset
|
32 force: if 1, force compilation, even if timestamps are up-to-date |
|
22374
2417694324ef
Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents:
17559
diff
changeset
|
33 quiet: if 1, be quiet during compilation |
|
1828
b464e1d0b2fb
New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 |
|
7126
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
35 """ |
|
22374
2417694324ef
Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents:
17559
diff
changeset
|
36 if not quiet: |
|
2417694324ef
Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents:
17559
diff
changeset
|
37 print 'Listing', dir, '...' |
|
7126
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
38 try: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
39 names = os.listdir(dir) |
|
7126
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
40 except os.error: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
41 print "Can't list", dir |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
42 names = [] |
|
7126
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
43 names.sort() |
|
10498
fe8645e49314
When run as a script, report failures in the exit code as well.
Fred Drake <fdrake@acm.org>
parents:
9664
diff
changeset
|
44 success = 1 |
|
7126
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
45 for name in names: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
46 fullname = os.path.join(dir, name) |
|
23610
0a2818cc342c
Use is None rather than general boolean
Raymond Hettinger <python@rcn.com>
parents:
22374
diff
changeset
|
47 if ddir is not None: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
48 dfile = os.path.join(ddir, name) |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
49 else: |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
50 dfile = None |
|
23610
0a2818cc342c
Use is None rather than general boolean
Raymond Hettinger <python@rcn.com>
parents:
22374
diff
changeset
|
51 if rx is not None: |
|
17559
28c14a79ad22
Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
52 mo = rx.search(fullname) |
|
28c14a79ad22
Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
53 if mo: |
|
28c14a79ad22
Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
54 continue |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
55 if os.path.isfile(fullname): |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
56 head, tail = name[:-3], name[-3:] |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
57 if tail == '.py': |
|
51500
584c47d8c93f
compileall used the ctime of bytecode and source to determine if the bytecode
Brett Cannon <bcannon@gmail.com>
parents:
45657
diff
changeset
|
58 if not force: |
|
584c47d8c93f
compileall used the ctime of bytecode and source to determine if the bytecode
Brett Cannon <bcannon@gmail.com>
parents:
45657
diff
changeset
|
59 try: |
|
53267
13807703afd0
Automatic conversion of floats to integers for struct.pack integer codes
Mark Dickinson <dickinsm@gmail.com>
parents:
51500
diff
changeset
|
60 mtime = int(os.stat(fullname).st_mtime) |
|
51500
584c47d8c93f
compileall used the ctime of bytecode and source to determine if the bytecode
Brett Cannon <bcannon@gmail.com>
parents:
45657
diff
changeset
|
61 expect = struct.pack('<4sl', imp.get_magic(), mtime) |
|
584c47d8c93f
compileall used the ctime of bytecode and source to determine if the bytecode
Brett Cannon <bcannon@gmail.com>
parents:
45657
diff
changeset
|
62 cfile = fullname + (__debug__ and 'c' or 'o') |
|
584c47d8c93f
compileall used the ctime of bytecode and source to determine if the bytecode
Brett Cannon <bcannon@gmail.com>
parents:
45657
diff
changeset
|
63 with open(cfile, 'rb') as chandle: |
|
584c47d8c93f
compileall used the ctime of bytecode and source to determine if the bytecode
Brett Cannon <bcannon@gmail.com>
parents:
45657
diff
changeset
|
64 actual = chandle.read(8) |
|
584c47d8c93f
compileall used the ctime of bytecode and source to determine if the bytecode
Brett Cannon <bcannon@gmail.com>
parents:
45657
diff
changeset
|
65 if expect == actual: |
|
584c47d8c93f
compileall used the ctime of bytecode and source to determine if the bytecode
Brett Cannon <bcannon@gmail.com>
parents:
45657
diff
changeset
|
66 continue |
|
584c47d8c93f
compileall used the ctime of bytecode and source to determine if the bytecode
Brett Cannon <bcannon@gmail.com>
parents:
45657
diff
changeset
|
67 except IOError: |
|
584c47d8c93f
compileall used the ctime of bytecode and source to determine if the bytecode
Brett Cannon <bcannon@gmail.com>
parents:
45657
diff
changeset
|
68 pass |
|
22374
2417694324ef
Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents:
17559
diff
changeset
|
69 if not quiet: |
|
2417694324ef
Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents:
17559
diff
changeset
|
70 print 'Compiling', fullname, '...' |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
71 try: |
|
27250
16a876746285
Patch #661719: Expose compilation errors as exceptions on request.
Martin v. Löwis <martin@v.loewis.de>
parents:
23625
diff
changeset
|
72 ok = py_compile.compile(fullname, None, dfile, True) |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
73 except KeyboardInterrupt: |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
74 raise KeyboardInterrupt |
|
27250
16a876746285
Patch #661719: Expose compilation errors as exceptions on request.
Martin v. Löwis <martin@v.loewis.de>
parents:
23625
diff
changeset
|
75 except py_compile.PyCompileError,err: |
|
32391
6fc02915f637
Patch #975885: print file name in err msg in quiet mode
Martin v. Löwis <martin@v.loewis.de>
parents:
30223
diff
changeset
|
76 if quiet: |
|
6fc02915f637
Patch #975885: print file name in err msg in quiet mode
Martin v. Löwis <martin@v.loewis.de>
parents:
30223
diff
changeset
|
77 print 'Compiling', fullname, '...' |
|
27250
16a876746285
Patch #661719: Expose compilation errors as exceptions on request.
Martin v. Löwis <martin@v.loewis.de>
parents:
23625
diff
changeset
|
78 print err.msg |
|
10498
fe8645e49314
When run as a script, report failures in the exit code as well.
Fred Drake <fdrake@acm.org>
parents:
9664
diff
changeset
|
79 success = 0 |
| 27263 | 80 except IOError, e: |
| 81 print "Sorry", e | |
| 82 success = 0 | |
|
17559
28c14a79ad22
Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
83 else: |
|
28c14a79ad22
Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
84 if ok == 0: |
|
28c14a79ad22
Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
85 success = 0 |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
86 elif maxlevels > 0 and \ |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
87 name != os.curdir and name != os.pardir and \ |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
88 os.path.isdir(fullname) and \ |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
89 not os.path.islink(fullname): |
|
51500
584c47d8c93f
compileall used the ctime of bytecode and source to determine if the bytecode
Brett Cannon <bcannon@gmail.com>
parents:
45657
diff
changeset
|
90 if not compile_dir(fullname, maxlevels - 1, dfile, force, rx, |
|
584c47d8c93f
compileall used the ctime of bytecode and source to determine if the bytecode
Brett Cannon <bcannon@gmail.com>
parents:
45657
diff
changeset
|
91 quiet): |
|
17559
28c14a79ad22
Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
92 success = 0 |
|
10498
fe8645e49314
When run as a script, report failures in the exit code as well.
Fred Drake <fdrake@acm.org>
parents:
9664
diff
changeset
|
93 return success |
|
7126
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
94 |
|
22374
2417694324ef
Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents:
17559
diff
changeset
|
95 def compile_path(skip_curdir=1, maxlevels=0, force=0, quiet=0): |
|
7126
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
96 """Byte-compile all module on sys.path. |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
97 |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
98 Arguments (all optional): |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
99 |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
100 skip_curdir: if true, skip current directory (default true) |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
101 maxlevels: max recursion level (default 0) |
|
9664
4eee061dac44
A mod whose author I forget. (I must've mislaid the email. If it's
Guido van Rossum <guido@python.org>
parents:
7755
diff
changeset
|
102 force: as for compile_dir() (default 0) |
|
22374
2417694324ef
Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents:
17559
diff
changeset
|
103 quiet: as for compile_dir() (default 0) |
|
7126
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
104 |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
105 """ |
|
10498
fe8645e49314
When run as a script, report failures in the exit code as well.
Fred Drake <fdrake@acm.org>
parents:
9664
diff
changeset
|
106 success = 1 |
|
7126
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
107 for dir in sys.path: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
108 if (not dir or dir == os.curdir) and skip_curdir: |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
109 print 'Skipping current directory' |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
110 else: |
|
22374
2417694324ef
Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents:
17559
diff
changeset
|
111 success = success and compile_dir(dir, maxlevels, None, |
|
2417694324ef
Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents:
17559
diff
changeset
|
112 force, quiet=quiet) |
|
10498
fe8645e49314
When run as a script, report failures in the exit code as well.
Fred Drake <fdrake@acm.org>
parents:
9664
diff
changeset
|
113 return success |
|
1828
b464e1d0b2fb
New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 |
|
b464e1d0b2fb
New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 def main(): |
|
7126
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
116 """Script main program.""" |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
117 import getopt |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
118 try: |
|
22374
2417694324ef
Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents:
17559
diff
changeset
|
119 opts, args = getopt.getopt(sys.argv[1:], 'lfqd:x:') |
|
7126
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
120 except getopt.error, msg: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
121 print msg |
|
22374
2417694324ef
Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents:
17559
diff
changeset
|
122 print "usage: python compileall.py [-l] [-f] [-q] [-d destdir] " \ |
|
30223
c06dffb6a982
Fix typo in docstring: The switch is '-x', not '-s'.
Thomas Heller <theller@ctypes.org>
parents:
27263
diff
changeset
|
123 "[-x regexp] [directory ...]" |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
124 print "-l: don't recurse down" |
|
9664
4eee061dac44
A mod whose author I forget. (I must've mislaid the email. If it's
Guido van Rossum <guido@python.org>
parents:
7755
diff
changeset
|
125 print "-f: force rebuild even if timestamps are up-to-date" |
|
22374
2417694324ef
Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents:
17559
diff
changeset
|
126 print "-q: quiet operation" |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
127 print "-d destdir: purported directory name for error messages" |
|
17559
28c14a79ad22
Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
128 print " if no directory arguments, -l sys.path is assumed" |
|
28c14a79ad22
Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
129 print "-x regexp: skip files matching the regular expression regexp" |
| 45657 | 130 print " the regexp is searched for in the full path of the file" |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
131 sys.exit(2) |
|
7126
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
132 maxlevels = 10 |
|
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
133 ddir = None |
|
9664
4eee061dac44
A mod whose author I forget. (I must've mislaid the email. If it's
Guido van Rossum <guido@python.org>
parents:
7755
diff
changeset
|
134 force = 0 |
|
22374
2417694324ef
Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents:
17559
diff
changeset
|
135 quiet = 0 |
|
17559
28c14a79ad22
Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
136 rx = None |
|
7126
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
137 for o, a in opts: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
138 if o == '-l': maxlevels = 0 |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
139 if o == '-d': ddir = a |
|
9664
4eee061dac44
A mod whose author I forget. (I must've mislaid the email. If it's
Guido van Rossum <guido@python.org>
parents:
7755
diff
changeset
|
140 if o == '-f': force = 1 |
|
22374
2417694324ef
Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents:
17559
diff
changeset
|
141 if o == '-q': quiet = 1 |
|
17559
28c14a79ad22
Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
142 if o == '-x': |
|
28c14a79ad22
Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
143 import re |
|
28c14a79ad22
Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
144 rx = re.compile(a) |
|
7126
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
145 if ddir: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
146 if len(args) != 1: |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
147 print "-d destdir require exactly one directory argument" |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
148 sys.exit(2) |
|
10498
fe8645e49314
When run as a script, report failures in the exit code as well.
Fred Drake <fdrake@acm.org>
parents:
9664
diff
changeset
|
149 success = 1 |
|
7126
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
150 try: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
151 if args: |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
152 for dir in args: |
|
22374
2417694324ef
Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents:
17559
diff
changeset
|
153 if not compile_dir(dir, maxlevels, ddir, |
|
2417694324ef
Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents:
17559
diff
changeset
|
154 force, rx, quiet): |
|
17559
28c14a79ad22
Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
155 success = 0 |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
156 else: |
|
10498
fe8645e49314
When run as a script, report failures in the exit code as well.
Fred Drake <fdrake@acm.org>
parents:
9664
diff
changeset
|
157 success = compile_path() |
|
7126
d2c110acc60c
Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents:
3902
diff
changeset
|
158 except KeyboardInterrupt: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
7126
diff
changeset
|
159 print "\n[interrupt]" |
|
10498
fe8645e49314
When run as a script, report failures in the exit code as well.
Fred Drake <fdrake@acm.org>
parents:
9664
diff
changeset
|
160 success = 0 |
|
fe8645e49314
When run as a script, report failures in the exit code as well.
Fred Drake <fdrake@acm.org>
parents:
9664
diff
changeset
|
161 return success |
|
1828
b464e1d0b2fb
New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
162 |
|
b464e1d0b2fb
New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 if __name__ == '__main__': |
|
34201
a0c7df52ba41
Bugs item #1069409 C:\Python24\Lib\compileall.py returns False
Raymond Hettinger <python@rcn.com>
parents:
32391
diff
changeset
|
164 exit_status = int(not main()) |
|
17559
28c14a79ad22
Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
165 sys.exit(exit_status) |
