def check_output(response: Dict[str, Any], verbose: bool, junit_xml: Optional[str], perf_stats_file: Optional[str]) -> None: """Print the output from a check or recheck command. Call sys.exit() unless the status code is zero. """ if 'error' in response: fail(response['error']) try: out, err, status_code = response['out'], response['err'], response[ 'status'] except KeyError: fail("Response: %s" % str(response)) sys.stdout.write(out) sys.stderr.write(err) if verbose: show_stats(response) if junit_xml: # Lazy import so this import doesn't slow things down when not writing junit from mypy.util import write_junit_xml messages = (out + err).splitlines() write_junit_xml(response['roundtrip_time'], bool(err), messages, junit_xml, response['python_version'], response['platform']) if perf_stats_file: telemetry = response.get('stats', {}) with open(perf_stats_file, 'w') as f: json.dump(telemetry, f) if status_code: sys.exit(status_code)
def main(script_path: str) -> None: """Main entry point to the type checker. Args: script_path: Path to the 'mypy' script (used for finding data files). """ t0 = time.time() if script_path: bin_dir = find_bin_directory(script_path) else: bin_dir = None sys.setrecursionlimit(2**14) sources, options = process_options(sys.argv[1:]) serious = False try: res = type_check_only(sources, bin_dir, options) a = res.errors except CompileError as e: a = e.messages if not e.use_stdout: serious = True if options.junit_xml: t1 = time.time() util.write_junit_xml(t1 - t0, serious, a, options.junit_xml) if a: f = sys.stderr if serious else sys.stdout for m in a: f.write(m + '\n') sys.exit(1)
def check_output(response: Dict[str, Any], verbose: bool, junit_xml: Optional[str], perf_stats_file: Optional[str]) -> None: """Print the output from a check or recheck command. Call sys.exit() unless the status code is zero. """ if 'error' in response: fail(response['error']) try: out, err, status_code = response['out'], response['err'], response['status'] except KeyError: fail("Response: %s" % str(response)) sys.stdout.write(out) sys.stderr.write(err) if verbose: show_stats(response) if junit_xml: # Lazy import so this import doesn't slow things down when not writing junit from mypy.util import write_junit_xml messages = (out + err).splitlines() write_junit_xml(response['roundtrip_time'], bool(err), messages, junit_xml, response['python_version'], response['platform']) if perf_stats_file: telemetry = response.get('stats', {}) with open(perf_stats_file, 'w') as f: json.dump(telemetry, f) if status_code: sys.exit(status_code)
def maybe_write_junit_xml(td: float, serious: bool, messages: List[str], options: Options) -> None: if options.junit_xml: py_version = '{}_{}'.format(options.python_version[0], options.python_version[1]) util.write_junit_xml(td, serious, messages, options.junit_xml, py_version, options.platform)
def main(script_path: str) -> None: """Main entry point to the type checker. Args: script_path: Path to the 'mypy' script (used for finding data files). """ t0 = time.time() if script_path: bin_dir = find_bin_directory(script_path) else: bin_dir = None sources, options = process_options(sys.argv[1:]) serious = False try: res = type_check_only(sources, bin_dir, options) a = res.errors except CompileError as e: a = e.messages if not e.use_stdout: serious = True if options.junit_xml: t1 = time.time() util.write_junit_xml(t1 - t0, serious, a, options.junit_xml) if a: f = sys.stderr if serious else sys.stdout for m in a: f.write(m + '\n') sys.exit(1)
def check_output(response: Dict[str, Any], verbose: bool, junit_xml: Optional[str]) -> None: """Print the output from a check or recheck command. Call sys.exit() unless the status code is zero. """ if 'error' in response: sys.exit(response['error']) try: out, err, status_code = response['out'], response['err'], response[ 'status'] except KeyError: sys.exit("Response: %s" % str(response)) sys.stdout.write(out) sys.stderr.write(err) if verbose: show_stats(response) if junit_xml: # Lazy import so this import doesn't slow things down when not writing junit from mypy.util import write_junit_xml messages = (out + err).splitlines() write_junit_xml(response['roundtrip_time'], bool(err), messages, junit_xml) if status_code: sys.exit(status_code)
def main(script_path: Optional[str], args: Optional[List[str]] = None) -> None: """Main entry point to the type checker. Args: script_path: Path to the 'mypy' script (used for finding data files). args: Custom command-line arguments. If not given, sys.argv[1:] will be used. """ # Check for known bad Python versions. if sys.version_info[:2] < (3, 4): sys.exit("Running mypy with Python 3.3 or lower is not supported; " "please upgrade to 3.4 or newer") if sys.version_info[:3] == (3, 5, 0): sys.exit("Running mypy with Python 3.5.0 is not supported; " "please upgrade to 3.5.1 or newer") t0 = time.time() # To log stat() calls: os.stat = stat_proxy if script_path: bin_dir = find_bin_directory(script_path) # type: Optional[str] else: bin_dir = None sys.setrecursionlimit(2**14) if args is None: args = sys.argv[1:] sources, options = process_options(args) messages = [] def flush_errors(new_messages: List[str], serious: bool) -> None: messages.extend(new_messages) f = sys.stderr if serious else sys.stdout try: for msg in new_messages: f.write(msg + '\n') f.flush() except BrokenPipeError: sys.exit(2) serious = False blockers = False try: type_check_only(sources, bin_dir, options, flush_errors) except CompileError as e: blockers = True if not e.use_stdout: serious = True if options.warn_unused_configs and options.unused_configs: print("Warning: unused section(s) in %s: %s" % (options.config_file, ", ".join( "[mypy-%s]" % glob for glob in options.unused_configs.values())), file=sys.stderr) if options.junit_xml: t1 = time.time() util.write_junit_xml(t1 - t0, serious, messages, options.junit_xml) if messages: code = 2 if blockers else 1 sys.exit(code)
def main(script_path: Optional[str], args: Optional[List[str]] = None) -> None: """Main entry point to the type checker. Args: script_path: Path to the 'mypy' script (used for finding data files). args: Custom command-line arguments. If not given, sys.argv[1:] will be used. """ # Check for known bad Python versions. if sys.version_info[:2] < (3, 4): sys.exit("Running mypy with Python 3.3 or lower is not supported; " "please upgrade to 3.4 or newer") if sys.version_info[:3] == (3, 5, 0): sys.exit("Running mypy with Python 3.5.0 is not supported; " "please upgrade to 3.5.1 or newer") t0 = time.time() # To log stat() calls: os.stat = stat_proxy if script_path: bin_dir = find_bin_directory(script_path) # type: Optional[str] else: bin_dir = None sys.setrecursionlimit(2 ** 14) if args is None: args = sys.argv[1:] sources, options = process_options(args) messages = [] def flush_errors(new_messages: List[str], serious: bool) -> None: messages.extend(new_messages) f = sys.stderr if serious else sys.stdout try: for msg in new_messages: f.write(msg + '\n') f.flush() except BrokenPipeError: sys.exit(2) serious = False blockers = False try: type_check_only(sources, bin_dir, options, flush_errors) except CompileError as e: blockers = True if not e.use_stdout: serious = True if options.warn_unused_configs and options.unused_configs: print("Warning: unused section(s) in %s: %s" % (options.config_file, ", ".join("[mypy-%s]" % glob for glob in options.unused_configs.values())), file=sys.stderr) if options.junit_xml: t1 = time.time() util.write_junit_xml(t1 - t0, serious, messages, options.junit_xml) if messages: code = 2 if blockers else 1 sys.exit(code)
def generate_c(sources: List[BuildSource], options: Options, groups: emitmodule.Groups, fscache: FileSystemCache, compiler_options: CompilerOptions, ) -> Tuple[List[List[Tuple[str, str]]], str]: """Drive the actual core compilation step. The groups argument describes how modules are assigned to C extension modules. See the comments on the Groups type in mypyc.emitmodule for details. Returns the C source code and (for debugging) the pretty printed IR. """ t0 = time.time() # Do the actual work now serious = False result = None try: result = emitmodule.parse_and_typecheck( sources, options, compiler_options, groups, fscache) messages = result.errors except CompileError as e: messages = e.messages if not e.use_stdout: serious = True t1 = time.time() if compiler_options.verbose: print("Parsed and typechecked in {:.3f}s".format(t1 - t0)) if not messages and result: errors = Errors() modules, ctext = emitmodule.compile_modules_to_c( result, compiler_options=compiler_options, errors=errors, groups=groups) if errors.num_errors: messages.extend(errors.new_messages()) t2 = time.time() if compiler_options.verbose: print("Compiled to C in {:.3f}s".format(t2 - t1)) # ... you know, just in case. if options.junit_xml: py_version = "{}_{}".format( options.python_version[0], options.python_version[1] ) write_junit_xml( t2 - t0, serious, messages, options.junit_xml, py_version, options.platform ) if messages: print("\n".join(messages)) sys.exit(1) return ctext, '\n'.join(format_modules(modules))
def main(script_path: Optional[str], args: Optional[List[str]] = None) -> None: """Main entry point to the type checker. Args: script_path: Path to the 'mypy' script (used for finding data files). args: Custom command-line arguments. If not given, sys.argv[1:] will be used. """ t0 = time.time() # To log stat() calls: os.stat = stat_proxy if script_path: bin_dir = find_bin_directory(script_path) # type: Optional[str] else: bin_dir = None sys.setrecursionlimit(2 ** 14) if args is None: args = sys.argv[1:] sources, options = process_options(args) def flush_errors(a: List[str], serious: bool) -> None: f = sys.stderr if serious else sys.stdout try: for m in a: f.write(m + '\n') f.flush() except BrokenPipeError: pass serious = False try: res = type_check_only(sources, bin_dir, options, flush_errors) a = res.errors except CompileError as e: a = e.messages if not e.use_stdout: serious = True if options.warn_unused_configs and options.unused_configs: print("Warning: unused section(s) in %s: %s" % (options.config_file, ", ".join("[mypy-%s]" % glob for glob in options.unused_configs.values())), file=sys.stderr) if options.junit_xml: t1 = time.time() util.write_junit_xml(t1 - t0, serious, a, options.junit_xml) if a: sys.exit(1)
def main(script_path: Optional[str], args: Optional[List[str]] = None) -> None: """Main entry point to the type checker. Args: script_path: Path to the 'mypy' script (used for finding data files). args: Custom command-line arguments. If not given, sys.argv[1:] will be used. """ t0 = time.time() # To log stat() calls: os.stat = stat_proxy if script_path: bin_dir = find_bin_directory(script_path) # type: Optional[str] else: bin_dir = None sys.setrecursionlimit(2 ** 14) if args is None: args = sys.argv[1:] sources, options = process_options(args) serious = False try: res = type_check_only(sources, bin_dir, options) a = res.errors except CompileError as e: a = e.messages if not e.use_stdout: serious = True if options.warn_unused_configs and options.unused_configs: print("Warning: unused section(s) in %s: %s" % (options.config_file, ", ".join("[mypy-%s]" % glob for glob in options.unused_configs.values())), file=sys.stderr) if options.junit_xml: t1 = time.time() util.write_junit_xml(t1 - t0, serious, a, options.junit_xml) if a: f = sys.stderr if serious else sys.stdout try: for m in a: f.write(m + '\n') except BrokenPipeError: pass sys.exit(1)
def check_output(response: Dict[str, Any], verbose: bool, junit_xml: Optional[str]) -> None: """Print the output from a check or recheck command. Call sys.exit() unless the status code is zero. """ if 'error' in response: sys.exit(response['error']) try: out, err, status_code = response['out'], response['err'], response['status'] except KeyError: sys.exit("Response: %s" % str(response)) sys.stdout.write(out) sys.stderr.write(err) if verbose: show_stats(response) if junit_xml: messages = (out + err).splitlines() write_junit_xml(response['roundtrip_time'], bool(err), messages, junit_xml) if status_code: sys.exit(status_code)
def main(script_path: str, args: List[str] = None) -> None: """Main entry point to the type checker. Args: script_path: Path to the 'mypy' script (used for finding data files). args: Custom command-line arguments. If not given, sys.argv[1:] will be used. """ t0 = time.time() if script_path: bin_dir = find_bin_directory(script_path) else: bin_dir = None sys.setrecursionlimit(2**14) if args is None: args = sys.argv[1:] sources, options = process_options(args) serious = False try: res = type_check_only(sources, bin_dir, options) a = res.errors except CompileError as e: a = e.messages if not e.use_stdout: serious = True if options.junit_xml: t1 = time.time() util.write_junit_xml(t1 - t0, serious, a, options.junit_xml) if a: f = sys.stderr if serious else sys.stdout try: for m in a: f.write(m + '\n') except BrokenPipeError: pass sys.exit(1)
def main( script_path: Optional[str], stdout: TextIO, stderr: TextIO, args: Optional[List[str]] = None, ) -> None: """Main entry point to the type checker. Args: script_path: Path to the 'mypy' script (used for finding data files). args: Custom command-line arguments. If not given, sys.argv[1:] will be used. """ util.check_python_version('mypy') t0 = time.time() # To log stat() calls: os.stat = stat_proxy sys.setrecursionlimit(2**14) if args is None: args = sys.argv[1:] fscache = FileSystemCache() sources, options = process_options(args, stdout=stdout, stderr=stderr, fscache=fscache) messages = [] def flush_errors(new_messages: List[str], serious: bool) -> None: messages.extend(new_messages) f = stderr if serious else stdout try: for msg in new_messages: f.write(msg + '\n') f.flush() except BrokenPipeError: sys.exit(2) serious = False blockers = False res = None try: # Keep a dummy reference (res) for memory profiling below, as otherwise # the result could be freed. res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr) except CompileError as e: blockers = True if not e.use_stdout: serious = True if options.warn_unused_configs and options.unused_configs and not options.incremental: print("Warning: unused section(s) in %s: %s" % (options.config_file, ", ".join( "[mypy-%s]" % glob for glob in options.per_module_options.keys() if glob in options.unused_configs)), file=stderr) if options.junit_xml: t1 = time.time() py_version = '{}_{}'.format(options.python_version[0], options.python_version[1]) util.write_junit_xml(t1 - t0, serious, messages, options.junit_xml, py_version, options.platform) if MEM_PROFILE: from mypy.memprofile import print_memory_profile print_memory_profile() del res # Now it's safe to delete code = 0 if messages: code = 2 if blockers else 1 if options.fast_exit: # Exit without freeing objects -- it's faster. # # NOTE: We don't flush all open files on exit (or run other destructors)! util.hard_exit(code) elif code: sys.exit(code)
def main(script_path: Optional[str], args: Optional[List[str]] = None) -> None: """Main entry point to the type checker. Args: script_path: Path to the 'mypy' script (used for finding data files). args: Custom command-line arguments. If not given, sys.argv[1:] will be used. """ util.check_python_version('mypy') t0 = time.time() # To log stat() calls: os.stat = stat_proxy sys.setrecursionlimit(2 ** 14) if args is None: args = sys.argv[1:] fscache = FileSystemCache() sources, options = process_options(args, fscache=fscache) messages = [] def flush_errors(new_messages: List[str], serious: bool) -> None: messages.extend(new_messages) f = sys.stderr if serious else sys.stdout try: for msg in new_messages: f.write(msg + '\n') f.flush() except BrokenPipeError: sys.exit(2) serious = False blockers = False res = None try: # Keep a dummy reference (res) for memory profiling below, as otherwise # the result could be freed. res = build.build(sources, options, None, flush_errors, fscache) except CompileError as e: blockers = True if not e.use_stdout: serious = True if options.warn_unused_configs and options.unused_configs: print("Warning: unused section(s) in %s: %s" % (options.config_file, ", ".join("[mypy-%s]" % glob for glob in options.per_module_options.keys() if glob in options.unused_configs)), file=sys.stderr) if options.junit_xml: t1 = time.time() py_version = '{}_{}'.format(options.python_version[0], options.python_version[1]) util.write_junit_xml(t1 - t0, serious, messages, options.junit_xml, py_version, options.platform) if MEM_PROFILE: from mypy.memprofile import print_memory_profile print_memory_profile() del res # Now it's safe to delete code = 0 if messages: code = 2 if blockers else 1 if options.fast_exit: # Exit without freeing objects -- it's faster. # # NOTE: We don't flush all open files on exit (or run other destructors)! util.hard_exit(code) elif code: sys.exit(code)
def main(script_path: Optional[str], args: Optional[List[str]] = None) -> None: """Main entry point to the type checker. Args: script_path: Path to the 'mypy' script (used for finding data files). args: Custom command-line arguments. If not given, sys.argv[1:] will be used. """ # Check for known bad Python versions. if sys.version_info[:2] < (3, 4): sys.exit("Running mypy with Python 3.3 or lower is not supported; " "please upgrade to 3.4 or newer") if sys.version_info[:3] == (3, 5, 0): sys.exit("Running mypy with Python 3.5.0 is not supported; " "please upgrade to 3.5.1 or newer") t0 = time.time() # To log stat() calls: os.stat = stat_proxy if script_path: bin_dir = find_bin_directory(script_path) # type: Optional[str] else: bin_dir = None sys.setrecursionlimit(2 ** 14) if args is None: args = sys.argv[1:] fscache = FileSystemCache() sources, options = process_options(args, fscache=fscache) messages = [] def flush_errors(new_messages: List[str], serious: bool) -> None: messages.extend(new_messages) f = sys.stderr if serious else sys.stdout try: for msg in new_messages: f.write(msg + '\n') f.flush() except BrokenPipeError: sys.exit(2) serious = False blockers = False try: # Keep a dummy reference (res) for memory profiling below, as otherwise # the result could be freed. res = type_check_only(sources, bin_dir, options, flush_errors, fscache) # noqa except CompileError as e: blockers = True if not e.use_stdout: serious = True if options.warn_unused_configs and options.unused_configs: print("Warning: unused section(s) in %s: %s" % (options.config_file, ", ".join("[mypy-%s]" % glob for glob in options.per_module_options.keys() if glob in options.unused_configs)), file=sys.stderr) if options.junit_xml: t1 = time.time() util.write_junit_xml(t1 - t0, serious, messages, options.junit_xml) if MEM_PROFILE: from mypy.memprofile import print_memory_profile print_memory_profile() code = 0 if messages: code = 2 if blockers else 1 if options.fast_exit: # Exit without freeing objects -- it's faster. # # NOTE: We don't flush all open files on exit (or run other destructors)! util.hard_exit(code) elif code: sys.exit(code)