def on_file(self, tree: MypyFile, type_map: Dict[Expression, Type]) -> None: self.last_xml = None path = os.path.relpath(tree.path) if stats.is_special_module(path): return if path.startswith('..'): return if 'stubs' in path.split('/'): return visitor = stats.StatisticsVisitor(inferred=True, typemap=type_map, all_nodes=True) tree.accept(visitor) root = etree.Element('mypy-report-file', name=path, module=tree._fullname) doc = etree.ElementTree(root) file_info = FileInfo(path, tree._fullname) with tokenize.open(path) as input_file: for lineno, line_text in enumerate(input_file, 1): status = visitor.line_map.get(lineno, stats.TYPE_EMPTY) file_info.counts[status] += 1 etree.SubElement(root, 'line', number=str(lineno), precision=stats.precision_names[status], content=line_text[:-1]) # Assumes a layout similar to what XmlReporter uses. xslt_path = os.path.relpath('mypy-html.xslt', path) transform_pi = etree.ProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="%s"' % cgi.escape(xslt_path, True)) root.addprevious(transform_pi) self.schema.assertValid(doc) self.last_xml = doc self.files.append(file_info)
def should_skip_path(path: str) -> bool: if stats.is_special_module(path): return True if path.startswith('..'): return True if 'stubs' in path.split('/') or 'stubs' in path.split(os.sep): return True return False
def on_file(self, tree: MypyFile, type_map: Dict[Expression, Type], options: Options) -> None: self.last_xml = None path = os.path.relpath(tree.path) if stats.is_special_module(path): return if path.startswith('..'): return if 'stubs' in path.split('/'): return visitor = stats.StatisticsVisitor(inferred=True, filename=tree.fullname(), typemap=type_map, all_nodes=True) tree.accept(visitor) root = etree.Element('mypy-report-file', name=path, module=tree._fullname) doc = etree.ElementTree(root) file_info = FileInfo(path, tree._fullname) with tokenize.open(path) as input_file: for lineno, line_text in enumerate(input_file, 1): status = visitor.line_map.get(lineno, stats.TYPE_EMPTY) file_info.counts[status] += 1 etree.SubElement(root, 'line', number=str(lineno), precision=stats.precision_names[status], content=line_text.rstrip('\n').translate( self.control_fixer), any_info=self._get_any_info_for_line( visitor, lineno)) # Assumes a layout similar to what XmlReporter uses. xslt_path = os.path.relpath('mypy-html.xslt', path) transform_pi = etree.ProcessingInstruction( 'xml-stylesheet', 'type="text/xsl" href="%s"' % pathname2url(xslt_path)) root.addprevious(transform_pi) self.schema.assertValid(doc) self.last_xml = doc self.files.append(file_info)
def on_file(self, tree: MypyFile, type_map: Dict[Node, Type]) -> None: import lxml.etree as etree self.last_xml = None path = os.path.relpath(tree.path) if stats.is_special_module(path): return if path.startswith('..'): return if 'stubs' in path.split('/'): return visitor = stats.StatisticsVisitor(inferred=True, typemap=type_map, all_nodes=True) tree.accept(visitor) root = etree.Element('mypy-report-file', name=path, module=tree._fullname) doc = etree.ElementTree(root) file_info = FileInfo(path, tree._fullname) with open(path) as input_file: for lineno, line_text in enumerate(input_file, 1): status = visitor.line_map.get(lineno, stats.TYPE_EMPTY) file_info.counts[status] += 1 etree.SubElement(root, 'line', number=str(lineno), precision=stats.precision_names[status], content=line_text[:-1]) # Assumes a layout similar to what XmlReporter uses. xslt_path = os.path.relpath('mypy-html.xslt', path) xml_pi = etree.ProcessingInstruction('xml', 'version="1.0" encoding="utf-8"') transform_pi = etree.ProcessingInstruction( 'xml-stylesheet', 'type="text/xsl" href="%s"' % cgi.escape(xslt_path, True)) root.addprevious(xml_pi) root.addprevious(transform_pi) self.schema.assertValid(doc) self.last_xml = doc self.files.append(file_info)