12
12
from mypy import stats
13
13
14
14
15
- reporter_classes = {} # type: Dict[str, Callable[[Reports, str], AbstractReporter]]
15
+ reporter_classes = {} # type: Dict[str, Callable[[Reports, str], AbstractReporter]]
16
16
17
17
18
18
class Reports :
19
19
def __init__ (self , main_file : str , data_dir : str , report_dirs : Dict [str , str ]) -> None :
20
20
self .main_file = main_file
21
21
self .data_dir = data_dir
22
- self .reporters = [] # type: List[AbstractReporter]
23
- self .named_reporters = {} # type: Dict[str, AbstractReporter]
22
+ self .reporters = [] # type: List[AbstractReporter]
23
+ self .named_reporters = {} # type: Dict[str, AbstractReporter]
24
24
25
25
for report_type , report_dir in sorted (report_dirs .items ()):
26
26
self .add_report (report_type , report_dir )
@@ -57,6 +57,7 @@ def on_file(self, tree: MypyFile, type_map: Dict[Node, Type]) -> None:
57
57
def on_finish (self ) -> None :
58
58
pass
59
59
60
+
60
61
class OldHtmlReporter (AbstractReporter ):
61
62
"""Old HTML reporter.
62
63
@@ -71,6 +72,7 @@ def on_finish(self) -> None:
71
72
stats .generate_html_index (self .output_dir )
72
73
reporter_classes ['old-html' ] = OldHtmlReporter
73
74
75
+
74
76
class FileInfo :
75
77
def __init__ (self , name : str , module : str ) -> None :
76
78
self .name = name
@@ -83,6 +85,7 @@ def total(self) -> int:
83
85
def attrib (self ) -> Dict [str , str ]:
84
86
return {name : str (val ) for name , val in zip (stats .precision_names , self .counts )}
85
87
88
+
86
89
class MemoryXmlReporter (AbstractReporter ):
87
90
"""Internal reporter that generates XML in memory.
88
91
@@ -100,8 +103,8 @@ def __init__(self, reports: Reports, output_dir: str) -> None:
100
103
self .css_html_path = os .path .join (reports .data_dir , 'xml' , 'mypy-html.css' )
101
104
xsd_path = os .path .join (reports .data_dir , 'xml' , 'mypy.xsd' )
102
105
self .schema = etree .XMLSchema (etree .parse (xsd_path ))
103
- self .last_xml = None # type: etree._ElementTree
104
- self .files = [] # type: List[FileInfo]
106
+ self .last_xml = None # type: etree._ElementTree
107
+ self .files = [] # type: List[FileInfo]
105
108
106
109
def on_file (self , tree : MypyFile , type_map : Dict [Node , Type ]) -> None :
107
110
import lxml .etree as etree
@@ -133,7 +136,8 @@ def on_file(self, tree: MypyFile, type_map: Dict[Node, Type]) -> None:
133
136
# Assumes a layout similar to what XmlReporter uses.
134
137
xslt_path = os .path .relpath ('mypy-html.xslt' , path )
135
138
xml_pi = etree .ProcessingInstruction ('xml' , 'version="1.0" encoding="utf-8"' )
136
- transform_pi = etree .ProcessingInstruction ('xml-stylesheet' , 'type="text/xsl" href="%s"' % cgi .escape (xslt_path , True ))
139
+ transform_pi = etree .ProcessingInstruction ('xml-stylesheet' ,
140
+ 'type="text/xsl" href="%s"' % cgi .escape (xslt_path , True ))
137
141
root .addprevious (xml_pi )
138
142
root .addprevious (transform_pi )
139
143
self .schema .assertValid (doc )
@@ -145,7 +149,7 @@ def on_finish(self) -> None:
145
149
import lxml .etree as etree
146
150
147
151
self .last_xml = None
148
- index_path = os .path .join (self .output_dir , 'index.xml' )
152
+ # index_path = os.path.join(self.output_dir, 'index.xml')
149
153
output_files = sorted (self .files , key = lambda x : x .module )
150
154
151
155
root = etree .Element ('mypy-report-index' , name = self .main_file )
@@ -159,7 +163,8 @@ def on_finish(self) -> None:
159
163
module = file_info .module )
160
164
xslt_path = os .path .relpath ('mypy-html.xslt' , '.' )
161
165
xml_pi = etree .ProcessingInstruction ('xml' , 'version="1.0" encoding="utf-8"' )
162
- transform_pi = etree .ProcessingInstruction ('xml-stylesheet' , 'type="text/xsl" href="%s"' % cgi .escape (xslt_path , True ))
166
+ transform_pi = etree .ProcessingInstruction ('xml-stylesheet' ,
167
+ 'type="text/xsl" href="%s"' % cgi .escape (xslt_path , True ))
163
168
root .addprevious (xml_pi )
164
169
root .addprevious (transform_pi )
165
170
self .schema .assertValid (doc )
@@ -168,6 +173,7 @@ def on_finish(self) -> None:
168
173
169
174
reporter_classes ['memory-xml' ] = MemoryXmlReporter
170
175
176
+
171
177
class AbstractXmlReporter (AbstractReporter ):
172
178
"""Internal abstract class for reporters that work via XML."""
173
179
@@ -178,6 +184,7 @@ def __init__(self, reports: Reports, output_dir: str) -> None:
178
184
# The dependency will be called first.
179
185
self .memory_xml = cast (MemoryXmlReporter , memory_reporter )
180
186
187
+
181
188
class XmlReporter (AbstractXmlReporter ):
182
189
"""Public reporter that exports XML.
183
190
@@ -211,6 +218,7 @@ def on_finish(self) -> None:
211
218
212
219
reporter_classes ['xml' ] = XmlReporter
213
220
221
+
214
222
class XsltHtmlReporter (AbstractXmlReporter ):
215
223
"""Public reporter that exports HTML via XSLT.
216
224
@@ -251,6 +259,7 @@ def on_finish(self) -> None:
251
259
252
260
reporter_classes ['xslt-html' ] = XsltHtmlReporter
253
261
262
+
254
263
class XsltTxtReporter (AbstractXmlReporter ):
255
264
"""Public reporter that exports TXT via XSLT.
256
265
0 commit comments