def on_finish(self) -> None: stats.generate_html_index(self.output_dir)
def build(program_path: str, target: int, module: str = None, program_text: Union[str, bytes] = None, alt_lib_path: str = None, bin_dir: str = None, pyversion: int = 3, custom_typing_module: str = None, html_report_dir: str = None, flags: List[str] = None, python_path: bool = False) -> BuildResult: """Analyze a program. A single call to build performs parsing, semantic analysis and optionally type checking for the program *and* all imported modules, recursively. Return BuildResult if successful; otherwise raise CompileError. Args: program_path: the path to the main source file (if module argument is given, this can be None => will be looked up) target: select passes to perform (a build target constant, e.g. C) module: name of the initial module; __main__ by default program_text: the main source file contents; if omitted, read from file alt_lib_dir: an additional directory for looking up library modules (takes precedence over other directories) bin_dir: directory containing the mypy script, used for finding data directories; if omitted, use '.' as the data directory pyversion: Python version (2 for 2.x or 3 for 3.x) custom_typing_module: if not None, use this module id as an alias for typing flags: list of build options (e.g. COMPILE_ONLY) """ flags = flags or [] module = module or '__main__' data_dir = default_data_dir(bin_dir) # Determine the default module search path. lib_path = default_lib_path(data_dir, target, pyversion, python_path) if TEST_BUILTINS in flags: # Use stub builtins (to speed up test cases and to make them easier to # debug). lib_path.insert(0, os.path.join('mypy', 'test', 'data', 'lib-stub')) elif program_path: # Include directory of the program file in the module search path. lib_path.insert(0, remove_cwd_prefix_from_path(dirname(program_path))) else: # Building/running a module. lib_path.insert(0, os.getcwd()) # If provided, insert the caller-supplied extra module path to the # beginning (highest priority) of the search path. if alt_lib_path: lib_path.insert(0, alt_lib_path) # Construct a build manager object that performs all the stages of the # build in the correct order. # # Ignore current directory prefix in error messages. manager = BuildManager(data_dir, lib_path, target, pyversion=pyversion, flags=flags, ignore_prefix=os.getcwd(), custom_typing_module=custom_typing_module, html_report_dir=html_report_dir) program_path = program_path or lookup_program(module, lib_path) if program_text is None: program_text = read_program(program_path) # Construct information that describes the initial file. __main__ is the # implicit module id and the import context is empty initially ([]). info = StateInfo(program_path, module, [], manager) # Perform the build by sending the file as new file (UnprocessedFile is the # initial state of all files) to the manager. The manager will process the # file and all dependant modules recursively. result = manager.process(UnprocessedFile(info, program_text)) if 'html-report' in flags: stats.generate_html_index(html_report_dir) return result
def on_finish(self) -> None: stats.generate_html_index(self.output_dir)
def build(program_path: str, target: int, module: str = None, program_text: str = None, alt_lib_path: str = None, bin_dir: str = None, output_dir: str = None, pyversion: int = 3, custom_typing_module: str = None, html_report_dir: str = None, flags: List[str] = None) -> BuildResult: """Build a mypy program. A single call to build performs parsing, semantic analysis and optionally type checking and other build passes for the program *and* all imported modules, recursively. Return BuildResult if successful; otherwise raise CompileError. Arguments: program_path: the path to the main source file (if module argument is given, this can be None => will be looked up) target: select passes to perform (a build target constant, e.g. C) Optional arguments: module: name of the initial module; __main__ by default program_text: the main source file contents; if omitted, read from file alt_lib_dir: an additional directory for looking up library modules (takes precedence over other directories) bin_dir: directory containing the mypy script, used for finding data directories; if omitted, use '.' as the data directory output_dir: directory where the output (Python) is stored pyversion: Python version (2 for 2.x or 3 for 3.x) custom_typing_module: if not None, use this module id as an alias for typing flags: list of build options (e.g. COMPILE_ONLY) """ flags = flags or [] module = module or '__main__' data_dir = default_data_dir(bin_dir) # Determine the default module search path. lib_path = default_lib_path(data_dir, target, pyversion) if TEST_BUILTINS in flags: # Use stub builtins (to speed up test cases and to make them easier to # debug). lib_path.insert(0, os.path.join('mypy', 'test', 'data', 'lib-stub')) elif program_path: # Include directory of the program file in the module search path. lib_path.insert( 0, remove_cwd_prefix_from_path(dirname(program_path))) else: # Building/running a module. lib_path.insert(0, os.getcwd()) # If provided, insert the caller-supplied extra module path to the # beginning (highest priority) of the search path. if alt_lib_path: lib_path.insert(0, alt_lib_path) # Construct a build manager object that performs all the stages of the # build in the correct order. # # Ignore current directory prefix in error messages. manager = BuildManager(data_dir, lib_path, target, output_dir, pyversion=pyversion, flags=flags, ignore_prefix=os.getcwd(), custom_typing_module=custom_typing_module, html_report_dir=html_report_dir) program_path = program_path or lookup_program(module, lib_path) if program_text is None: program_text = read_program(program_path) # Construct information that describes the initial file. __main__ is the # implicit module id and the import context is empty initially ([]). info = StateInfo(program_path, module, [], manager) # Perform the build by sending the file as new file (UnprocessedFile is the # initial state of all files) to the manager. The manager will process the # file and all dependant modules recursively. result = manager.process(UnprocessedFile(info, program_text)) if 'html-report' in flags: stats.generate_html_index(html_report_dir) return result