# DP: Issue #8233: When run as a script, py_compile.py optionally takes a single # DP: argument `-`. Backport from the trunk. Index: Lib/py_compile.py =================================================================== --- ./Lib/py_compile.py (Revision 79532) +++ ./Lib/py_compile.py (Revision 79533) @@ -135,19 +135,35 @@ not specified) are compiled and the resulting bytecode is cached in the normal manner. This function does not search a directory structure to locate source files; it only compiles files named - explicitly. + explicitly. If '-' is the only parameter in args, the list of + files is taken from standard input. """ if args is None: args = sys.argv[1:] rv = 0 - for filename in args: - try: - compile(filename, doraise=True) - except PyCompileError, err: - # return value to indicate at least one failure - rv = 1 - sys.stderr.write(err.msg) + if args == ['-']: + while True: + filename = sys.stdin.readline() + if not filename: + break + filename = filename.rstrip('\n') + try: + compile(filename, doraise=True) + except PyCompileError, error: + rv = 1 + sys.stderr.write("%s\n" % error.msg) + except IOError, error: + rv = 1 + sys.stderr.write("%s\n" % error) + else: + for filename in args: + try: + compile(filename, doraise=True) + except PyCompileError, error: + # return value to indicate at least one failure + rv = 1 + sys.stderr.write(error.msg) return rv if __name__ == "__main__":