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
46
47
MODULE = 'module' # Build/run module as a script
47
48
PROGRAM_TEXT = 'program-text' # Build/run command-line argument as a script
48
49
TEST_BUILTINS = 'test-builtins' # Use stub builtins to speed up tests
50
+ DUMP_TYPE_STATS = 'dump-type-stats'
51
+ DUMP_INFER_STATS = 'dump-infer-stats'
49
52
50
53
# State ids. These describe the states a source file / module can be in a
51
54
# build.
@@ -96,7 +99,7 @@ def build(program_path: str,
96
99
output_dir : str = None ,
97
100
pyversion : int = 3 ,
98
101
custom_typing_module : str = None ,
99
- html_report_dir : str = None ,
102
+ report_dirs : Dict [ str , str ] = {} ,
100
103
flags : List [str ] = None ,
101
104
python_path : bool = False ) -> BuildResult :
102
105
"""Build a mypy program.
@@ -148,6 +151,8 @@ def build(program_path: str,
148
151
if alt_lib_path :
149
152
lib_path .insert (0 , alt_lib_path )
150
153
154
+ reports = Reports (data_dir , report_dirs )
155
+
151
156
# Construct a build manager object that performs all the stages of the
152
157
# build in the correct order.
153
158
#
@@ -156,7 +161,7 @@ def build(program_path: str,
156
161
pyversion = pyversion , flags = flags ,
157
162
ignore_prefix = os .getcwd (),
158
163
custom_typing_module = custom_typing_module ,
159
- html_report_dir = html_report_dir )
164
+ reports = reports )
160
165
161
166
if program_text is None :
162
167
program_path = program_path or lookup_program (module , lib_path )
@@ -171,8 +176,7 @@ def build(program_path: str,
171
176
# initial state of all files) to the manager. The manager will process the
172
177
# file and all dependant modules recursively.
173
178
result = manager .process (UnprocessedFile (info , program_text ))
174
- if 'html-report' in flags :
175
- stats .generate_html_index (html_report_dir )
179
+ reports .finish ()
176
180
return result
177
181
178
182
@@ -301,7 +305,7 @@ def __init__(self, data_dir: str,
301
305
flags : List [str ],
302
306
ignore_prefix : str ,
303
307
custom_typing_module : str ,
304
- html_report_dir : str ) -> None :
308
+ reports : Reports ) -> None :
305
309
self .data_dir = data_dir
306
310
self .errors = Errors ()
307
311
self .errors .set_ignore_prefix (ignore_prefix )
@@ -311,7 +315,7 @@ def __init__(self, data_dir: str,
311
315
self .pyversion = pyversion
312
316
self .flags = flags
313
317
self .custom_typing_module = custom_typing_module
314
- self .html_report_dir = html_report_dir
318
+ self .reports = reports
315
319
self .semantic_analyzer = SemanticAnalyzer (lib_path , self .errors ,
316
320
pyversion = pyversion )
317
321
self .semantic_analyzer_pass3 = ThirdPass (self .errors )
@@ -813,7 +817,7 @@ class PartiallySemanticallyAnalyzedFile(ParsedFile):
813
817
def process (self ) -> None :
814
818
"""Perform final pass of semantic analysis and advance state."""
815
819
self .semantic_analyzer_pass3 ().visit_file (self .tree , self .tree .path )
816
- if 'dump-type-stats' in self .manager .flags :
820
+ if DUMP_TYPE_STATS in self .manager .flags :
817
821
stats .dump_type_stats (self .tree , self .tree .path )
818
822
self .switch_state (SemanticallyAnalyzedFile (self .info (), self .tree ))
819
823
@@ -826,14 +830,10 @@ def process(self) -> None:
826
830
"""Type check file and advance to the next state."""
827
831
if self .manager .target >= TYPE_CHECK :
828
832
self .type_checker ().visit_file (self .tree , self .tree .path )
829
- if 'dump-infer-stats' in self .manager .flags :
833
+ if DUMP_INFER_STATS in self .manager .flags :
830
834
stats .dump_type_stats (self .tree , self .tree .path , inferred = True ,
831
835
typemap = self .manager .type_checker .type_map )
832
- elif 'html-report' in self .manager .flags :
833
- stats .generate_html_report (
834
- self .tree , self .tree .path ,
835
- type_map = self .manager .type_checker .type_map ,
836
- output_dir = self .manager .html_report_dir )
836
+ self .manager .reports .file (self .tree , type_map = self .manager .type_checker .type_map )
837
837
838
838
# FIX remove from active state list to speed up processing
839
839
0 commit comments