Commit d5f9bf5e authored by Barry Warsaw's avatar Barry Warsaw

- 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).
parent fd2bfb02
...@@ -138,19 +138,35 @@ def main(args=None): ...@@ -138,19 +138,35 @@ def main(args=None):
not specified) are compiled and the resulting bytecode is cached not specified) are compiled and the resulting bytecode is cached
in the normal manner. This function does not search a directory in the normal manner. This function does not search a directory
structure to locate source files; it only compiles files named 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: if args is None:
args = sys.argv[1:] args = sys.argv[1:]
rv = 0 rv = 0
for filename in args: if args == ['-']:
try: while True:
compile(filename, doraise=True) filename = sys.stdin.readline()
except PyCompileError as err: if not filename:
# return value to indicate at least one failure break
rv = 1 filename = filename.rstrip('\n')
sys.stderr.write(err.msg) 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 return rv
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -293,6 +293,11 @@ C-API ...@@ -293,6 +293,11 @@ C-API
Library Library
------- -------
- 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).
- Backwards incompatible change: Unicode codepoints line tabulation (0x0B) and - Backwards incompatible change: Unicode codepoints line tabulation (0x0B) and
form feed (0x0C) are now considered linebreaks, as specified in Unicode form feed (0x0C) are now considered linebreaks, as specified in Unicode
Standard Annex #14. See issue #7643. Standard Annex #14. See issue #7643.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment