Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9065ea3

Browse files
committed
When run as a script, report failures in the exit code as well.
Patch largely based on changes by Andrew Dalke, as discussed in the distutils-sig.
1 parent 3527f59 commit 9065ea3

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

Lib/compileall.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def compile_dir(dir, maxlevels=10, ddir=None, force=0):
3636
print "Can't list", dir
3737
names = []
3838
names.sort()
39+
success = 1
3940
for name in names:
4041
fullname = os.path.join(dir, name)
4142
if ddir:
@@ -61,11 +62,13 @@ def compile_dir(dir, maxlevels=10, ddir=None, force=0):
6162
else: exc_type_name = sys.exc_type.__name__
6263
print 'Sorry:', exc_type_name + ':',
6364
print sys.exc_value
65+
success = 0
6466
elif maxlevels > 0 and \
6567
name != os.curdir and name != os.pardir and \
6668
os.path.isdir(fullname) and \
6769
not os.path.islink(fullname):
6870
compile_dir(fullname, maxlevels - 1, dfile, force)
71+
return success
6972

7073
def compile_path(skip_curdir=1, maxlevels=0, force=0):
7174
"""Byte-compile all module on sys.path.
@@ -77,11 +80,13 @@ def compile_path(skip_curdir=1, maxlevels=0, force=0):
7780
force: as for compile_dir() (default 0)
7881
7982
"""
83+
success = 1
8084
for dir in sys.path:
8185
if (not dir or dir == os.curdir) and skip_curdir:
8286
print 'Skipping current directory'
8387
else:
84-
compile_dir(dir, maxlevels, None, force)
88+
success = success and compile_dir(dir, maxlevels, None, force)
89+
return success
8590

8691
def main():
8792
"""Script main program."""
@@ -107,14 +112,17 @@ def main():
107112
if len(args) != 1:
108113
print "-d destdir require exactly one directory argument"
109114
sys.exit(2)
115+
success = 1
110116
try:
111117
if args:
112118
for dir in args:
113-
compile_dir(dir, maxlevels, ddir, force)
119+
success = success and compile_dir(dir, maxlevels, ddir, force)
114120
else:
115-
compile_path()
121+
success = compile_path()
116122
except KeyboardInterrupt:
117123
print "\n[interrupt]"
124+
success = 0
125+
return success
118126

119127
if __name__ == '__main__':
120-
main()
128+
sys.exit(not main())

0 commit comments

Comments
 (0)