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
debug = False
41
42
VERBOSE = 'verbose' # More verbose messages (for troubleshooting)
42
43
MODULE = 'module' # Build/run module as a script
43
44
TEST_BUILTINS = 'test-builtins' # Use stub builtins to speed up tests
45
+ DUMP_TYPE_STATS = 'dump-type-stats'
46
+ DUMP_INFER_STATS = 'dump-infer-stats'
44
47
45
48
# State ids. These describe the states a source file / module can be in a
46
49
# build.
@@ -90,7 +93,7 @@ def build(program_path: str,
90
93
output_dir : str = None ,
91
94
pyversion : int = 3 ,
92
95
custom_typing_module : str = None ,
93
- html_report_dir : str = None ,
96
+ report_dirs : Dict [ str , str ] = {} ,
94
97
flags : List [str ] = None ,
95
98
python_path : bool = False ) -> BuildResult :
96
99
"""Build a mypy program.
@@ -142,6 +145,8 @@ def build(program_path: str,
142
145
if alt_lib_path :
143
146
lib_path .insert (0 , alt_lib_path )
144
147
148
+ reports = Reports (data_dir , report_dirs )
149
+
145
150
# Construct a build manager object that performs all the stages of the
146
151
# build in the correct order.
147
152
#
@@ -150,7 +155,7 @@ def build(program_path: str,
150
155
pyversion = pyversion , flags = flags ,
151
156
ignore_prefix = os .getcwd (),
152
157
custom_typing_module = custom_typing_module ,
153
- html_report_dir = html_report_dir )
158
+ reports = reports )
154
159
155
160
program_path = program_path or lookup_program (module , lib_path )
156
161
if program_text is None :
@@ -163,8 +168,7 @@ def build(program_path: str,
163
168
# initial state of all files) to the manager. The manager will process the
164
169
# file and all dependant modules recursively.
165
170
result = manager .process (UnprocessedFile (info , program_text ))
166
- if 'html-report' in flags :
167
- stats .generate_html_index (html_report_dir )
171
+ reports .finish ()
168
172
return result
169
173
170
174
@@ -288,7 +292,7 @@ def __init__(self, data_dir: str,
288
292
flags : List [str ],
289
293
ignore_prefix : str ,
290
294
custom_typing_module : str ,
291
- html_report_dir : str ) -> None :
295
+ reports : Reports ) -> None :
292
296
self .data_dir = data_dir
293
297
self .errors = Errors ()
294
298
self .errors .set_ignore_prefix (ignore_prefix )
@@ -298,7 +302,7 @@ def __init__(self, data_dir: str,
298
302
self .pyversion = pyversion
299
303
self .flags = flags
300
304
self .custom_typing_module = custom_typing_module
301
- self .html_report_dir = html_report_dir
305
+ self .reports = reports
302
306
self .semantic_analyzer = SemanticAnalyzer (lib_path , self .errors ,
303
307
pyversion = pyversion )
304
308
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