From d5f9bf5ecfcab58605d8070b285b47ffb18b99a2 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Wed, 31 Mar 2010 21:36:22 +0000 Subject: =?UTF-8?q?-=20Issue=20#8233:=20When=20run=20as=20a=20script,=20py?= =?UTF-8?q?=5Fcompile.py=20optionally=20takes=20a=20single=20=20=20argumen?= =?UTF-8?q?t=20`-`=20which=20tells=20it=20to=20read=20files=20to=20compile?= =?UTF-8?q?=20from=20stdin.=20=20Each=20line=20=20=20is=20read=20on=20dema?= =?UTF-8?q?nd=20and=20the=20named=20file=20is=20compiled=20immediately.=20?= =?UTF-8?q?=20(Original=20=20=20patch=20by=20Piotr=20O=C5=BCarowski).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lib/py_compile.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'Lib/py_compile.py') diff --git a/Lib/py_compile.py b/Lib/py_compile.py index 9f34a0b38e..9361875846 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__": -- cgit v1.2.1