26
26
from mypy .errors import Errors , CompileError
27
27
from mypy import parse
28
28
from mypy import stats
29
+ from mypy .report import Reports
29
30
30
31
31
32
# We need to know the location of this file to load data, but
45
46
MODULE = 'module' # Build module as a script
46
47
PROGRAM_TEXT = 'program-text' # Build command-line argument as a script
47
48
TEST_BUILTINS = 'test-builtins' # Use stub builtins to speed up tests
49
+ DUMP_TYPE_STATS = 'dump-type-stats'
50
+ DUMP_INFER_STATS = 'dump-infer-stats'
48
51
49
52
# State ids. These describe the states a source file / module can be in a
50
53
# build.
@@ -94,7 +97,7 @@ def build(program_path: str,
94
97
bin_dir : str = None ,
95
98
pyversion : int = 3 ,
96
99
custom_typing_module : str = None ,
97
- html_report_dir : str = None ,
100
+ report_dirs : Dict [ str , str ] = {} ,
98
101
flags : List [str ] = None ,
99
102
python_path : bool = False ) -> BuildResult :
100
103
"""Analyze a program.
@@ -143,6 +146,8 @@ def build(program_path: str,
143
146
if alt_lib_path :
144
147
lib_path .insert (0 , alt_lib_path )
145
148
149
+ reports = Reports (data_dir , report_dirs )
150
+
146
151
# Construct a build manager object that performs all the stages of the
147
152
# build in the correct order.
148
153
#
@@ -151,7 +156,7 @@ def build(program_path: str,
151
156
pyversion = pyversion , flags = flags ,
152
157
ignore_prefix = os .getcwd (),
153
158
custom_typing_module = custom_typing_module ,
154
- html_report_dir = html_report_dir )
159
+ reports = reports )
155
160
156
161
if program_text is None :
157
162
program_path = program_path or lookup_program (module , lib_path )
@@ -166,8 +171,7 @@ def build(program_path: str,
166
171
# initial state of all files) to the manager. The manager will process the
167
172
# file and all dependant modules recursively.
168
173
result = manager .process (UnprocessedFile (info , program_text ))
169
- if 'html-report' in flags :
170
- stats .generate_html_index (html_report_dir )
174
+ reports .finish ()
171
175
return result
172
176
173
177
@@ -309,7 +313,7 @@ def __init__(self, data_dir: str,
309
313
flags : List [str ],
310
314
ignore_prefix : str ,
311
315
custom_typing_module : str ,
312
- html_report_dir : str ) -> None :
316
+ reports : Reports ) -> None :
313
317
self .data_dir = data_dir
314
318
self .errors = Errors ()
315
319
self .errors .set_ignore_prefix (ignore_prefix )
@@ -318,7 +322,7 @@ def __init__(self, data_dir: str,
318
322
self .pyversion = pyversion
319
323
self .flags = flags
320
324
self .custom_typing_module = custom_typing_module
321
- self .html_report_dir = html_report_dir
325
+ self .reports = reports
322
326
self .semantic_analyzer = SemanticAnalyzer (lib_path , self .errors ,
323
327
pyversion = pyversion )
324
328
self .semantic_analyzer_pass3 = ThirdPass (self .errors )
@@ -800,7 +804,7 @@ class PartiallySemanticallyAnalyzedFile(ParsedFile):
800
804
def process (self ) -> None :
801
805
"""Perform final pass of semantic analysis and advance state."""
802
806
self .semantic_analyzer_pass3 ().visit_file (self .tree , self .tree .path )
803
- if 'dump-type-stats' in self .manager .flags :
807
+ if DUMP_TYPE_STATS in self .manager .flags :
804
808
stats .dump_type_stats (self .tree , self .tree .path )
805
809
self .switch_state (SemanticallyAnalyzedFile (self .info (), self .tree ))
806
810
@@ -813,14 +817,10 @@ def process(self) -> None:
813
817
"""Type check file and advance to the next state."""
814
818
if self .manager .target >= TYPE_CHECK :
815
819
self .type_checker ().visit_file (self .tree , self .tree .path )
816
- if 'dump-infer-stats' in self .manager .flags :
820
+ if DUMP_INFER_STATS in self .manager .flags :
817
821
stats .dump_type_stats (self .tree , self .tree .path , inferred = True ,
818
822
typemap = self .manager .type_checker .type_map )
819
- elif 'html-report' in self .manager .flags :
820
- stats .generate_html_report (
821
- self .tree , self .tree .path ,
822
- type_map = self .manager .type_checker .type_map ,
823
- output_dir = self .manager .html_report_dir )
823
+ self .manager .reports .file (self .tree , type_map = self .manager .type_checker .type_map )
824
824
825
825
# FIX remove from active state list to speed up processing
826
826
0 commit comments