diff options
author | shadchin <[email protected]> | 2022-04-18 12:39:32 +0300 |
---|---|---|
committer | shadchin <[email protected]> | 2022-04-18 12:39:32 +0300 |
commit | d4be68e361f4258cf0848fc70018dfe37a2acc24 (patch) | |
tree | 153e294cd97ac8b5d7a989612704a0c1f58e8ad4 /contrib/tools/python3/src/Lib/py_compile.py | |
parent | 260c02f5ccf242d9d9b8a873afaf6588c00237d6 (diff) |
IGNIETFERRO-1816 Update Python 3 from 3.9.12 to 3.10.4
ref:9f96be6d02ee8044fdd6f124b799b270c20ce641
Diffstat (limited to 'contrib/tools/python3/src/Lib/py_compile.py')
-rw-r--r-- | contrib/tools/python3/src/Lib/py_compile.py | 71 |
1 files changed, 34 insertions, 37 deletions
diff --git a/contrib/tools/python3/src/Lib/py_compile.py b/contrib/tools/python3/src/Lib/py_compile.py index a81f4937310..388614e51b1 100644 --- a/contrib/tools/python3/src/Lib/py_compile.py +++ b/contrib/tools/python3/src/Lib/py_compile.py @@ -173,43 +173,40 @@ def compile(file, cfile=None, dfile=None, doraise=False, optimize=-1, return cfile -def main(args=None): - """Compile several source files. - - The files named in 'args' (or on the command line, if 'args' is - 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. 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 - 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 OSError as error: - rv = 1 - sys.stderr.write("%s\n" % error) +def main(): + import argparse + + description = 'A simple command-line interface for py_compile module.' + parser = argparse.ArgumentParser(description=description) + parser.add_argument( + '-q', '--quiet', + action='store_true', + help='Suppress error output', + ) + parser.add_argument( + 'filenames', + nargs='+', + help='Files to compile', + ) + args = parser.parse_args() + if args.filenames == ['-']: + filenames = [filename.rstrip('\n') for filename in sys.stdin.readlines()] else: - for filename in args: - try: - compile(filename, doraise=True) - except PyCompileError as error: - # return value to indicate at least one failure - rv = 1 - sys.stderr.write("%s\n" % error.msg) - return rv + filenames = args.filenames + for filename in filenames: + try: + compile(filename, doraise=True) + except PyCompileError as error: + if args.quiet: + parser.exit(1) + else: + parser.exit(1, error.msg) + except OSError as error: + if args.quiet: + parser.exit(1) + else: + parser.exit(1, str(error)) + if __name__ == "__main__": - sys.exit(main()) + main() |