Пример #1
0
def run(project_directory):
	failures = {}
	count_errors = 0
	project = Project(project_directory)
	files = project.pycore.get_python_files()

	for file_num, resource in enumerate(files):
		if count_errors > 500:
			break
		pymodule = project.pycore.resource_to_pyobject(resource)

		source, node = pymodule.source_code, pymodule.get_ast()

		lines = SourceLinesAdapter(source)

		try:
			patchedast.patch_ast(node, source)
		except Exception as ex:
			print 'warning: can not read {}'.format(resource)
			continue

		for n in ast.walk(node):
			if hasattr(n, 'region') and hasattr(n, 'lineno') and n.region[0]:
				if abs(translate_to_offset(lines, n) - n.region[0]) > 1 :
					count_errors += 1
					fail = Highlight()
					fail.node = n
					fail.lines = lines
					fail.resource = resource

					failures.setdefault(n.__class__, [])
					failures[n.__class__].append(fail)

	return failures
Пример #2
0
 def _init_using_ast(self, node, source):
     self.source = source
     self._matched_asts = {}
     if not hasattr(node, "region"):
         patchedast.patch_ast(node, source)
     self.ast = node
Пример #3
0
 def _init_using_ast(self, node, source):
     self.source = source
     self._matched_asts = {}
     if not hasattr(node, 'region'):
         patchedast.patch_ast(node, source)
     self.ast = node
Пример #4
0
 def _init_using_ast(self, node, source):
     self.source = source
     self._matched_asts = {}
     if not hasattr(node, 'sorted_children'):
         self.ast = patchedast.patch_ast(node, source)
Пример #5
0
 def _calculate_scope_regions(self):
     source = self._get_source()
     patchedast.patch_ast(self.pyobject.get_ast(), source)