()
| 174 | |
| 175 | |
| 176 | def main(): |
| 177 | import argparse |
| 178 | |
| 179 | description = 'A simple command-line interface for py_compile module.' |
| 180 | parser = argparse.ArgumentParser(description=description, color=True) |
| 181 | parser.add_argument( |
| 182 | '-q', '--quiet', |
| 183 | action='store_true', |
| 184 | help='Suppress error output', |
| 185 | ) |
| 186 | parser.add_argument( |
| 187 | 'filenames', |
| 188 | nargs='+', |
| 189 | help='Files to compile', |
| 190 | ) |
| 191 | args = parser.parse_args() |
| 192 | if args.filenames == ['-']: |
| 193 | filenames = [filename.rstrip('\n') for filename in sys.stdin.readlines()] |
| 194 | else: |
| 195 | filenames = args.filenames |
| 196 | for filename in filenames: |
| 197 | cfilename = (None if sys.implementation.cache_tag |
| 198 | else f"{filename.rpartition('.')[0]}.pyc") |
| 199 | try: |
| 200 | compile(filename, cfilename, doraise=True) |
| 201 | except PyCompileError as error: |
| 202 | if args.quiet: |
| 203 | parser.exit(1) |
| 204 | else: |
| 205 | parser.exit(1, error.msg) |
| 206 | except OSError as error: |
| 207 | if args.quiet: |
| 208 | parser.exit(1) |
| 209 | else: |
| 210 | parser.exit(1, str(error)) |
| 211 | |
| 212 | |
| 213 | if __name__ == "__main__": |
no test coverage detected
searching dependent graphs…