diff options
author | Barry Warsaw <barry@python.org> | 2010-03-31 21:36:22 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2010-03-31 21:36:22 (GMT) |
commit | d5f9bf5ecfcab58605d8070b285b47ffb18b99a2 (patch) | |
tree | 07d9eeeb72c1ef11205d25028d5a880d1ba0b8cd /Lib | |
parent | fd2bfb02db1a5b4d06b054ce578b565cca1fd085 (diff) | |
download | cpython-d5f9bf5ecfcab58605d8070b285b47ffb18b99a2.zip cpython-d5f9bf5ecfcab58605d8070b285b47ffb18b99a2.tar.gz cpython-d5f9bf5ecfcab58605d8070b285b47ffb18b99a2.tar.bz2 |
- Issue #8233: When run as a script, py_compile.py optionally takes a single
argument `-` which tells it to read files to compile from stdin. Each line
is read on demand and the named file is compiled immediately. (Original
patch by Piotr Ożarowski).
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/py_compile.py | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/Lib/py_compile.py b/Lib/py_compile.py index 9f34a0b..9361875 100644 --- a/Lib/py_compile.py +++ b/Lib/py_compile.py @@ -138,19 +138,35 @@ def main(args=None): 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 as 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 as error: + rv = 1 + sys.stderr.write("%s\n" % error.msg) + except IOError as error: + rv = 1 + sys.stderr.write("%s\n" % error) + else: + for filename in args: + try: + compile(filename, doraise=True) + except PyCompileError as err: + # return value to indicate at least one failure + rv = 1 + sys.stderr.write(error.msg) return rv if __name__ == "__main__": |