Coding style.
- Tidy up gut tool.
This commit is contained in:
parent
2da603c5bf
commit
f32a97cbbf
1 changed files with 11 additions and 17 deletions
|
|
@ -335,7 +335,7 @@ def python_coverage(path):
|
||||||
return status, _colorize_coverage_report(lines)
|
return status, _colorize_coverage_report(lines)
|
||||||
|
|
||||||
|
|
||||||
def _function_body_lines(module_contents):
|
def _function_body_lines(python_source):
|
||||||
ranges = []
|
ranges = []
|
||||||
class FuncNodeVisitor(ast.NodeVisitor):
|
class FuncNodeVisitor(ast.NodeVisitor):
|
||||||
|
|
||||||
|
|
@ -347,28 +347,22 @@ def _function_body_lines(module_contents):
|
||||||
|
|
||||||
def visit_AsyncFunctionDef(self, node):
|
def visit_AsyncFunctionDef(self, node):
|
||||||
ranges.append(self._line_range(node.body))
|
ranges.append(self._line_range(node.body))
|
||||||
visitor = FuncNodeVisitor()
|
tree = ast.parse(python_source)
|
||||||
tree = ast.parse(module_contents)
|
FuncNodeVisitor().visit(tree)
|
||||||
visitor.visit(tree)
|
|
||||||
return ranges
|
return ranges
|
||||||
|
|
||||||
|
|
||||||
def _gut_module(module_contents):
|
|
||||||
ranges = _function_body_lines(module_contents)
|
|
||||||
lines = module_contents.splitlines(keepends=True)
|
|
||||||
deleted = 0
|
|
||||||
for start_line, end_line in ranges:
|
|
||||||
del lines[start_line-deleted:end_line-deleted]
|
|
||||||
deleted += (end_line - start_line)
|
|
||||||
return "".join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
@deps(url="https://github.com/ahamilton/eris")
|
@deps(url="https://github.com/ahamilton/eris")
|
||||||
def python_gut(path):
|
def python_gut(path):
|
||||||
with open(path) as module_file:
|
with open(path) as module_file:
|
||||||
output = _gut_module(module_file.read())
|
python_source = module_file.read()
|
||||||
source_widget = _syntax_highlight_using_path(_fix_input(output), path)
|
lines = python_source.splitlines(keepends=True)
|
||||||
return Status.normal, source_widget
|
deleted = 0
|
||||||
|
for start_line, end_line in _function_body_lines(python_source):
|
||||||
|
del lines[start_line-deleted:end_line-deleted]
|
||||||
|
deleted += (end_line - start_line)
|
||||||
|
gutted_source = "".join(lines)
|
||||||
|
return Status.normal, _syntax_highlight_using_path(gutted_source, path)
|
||||||
|
|
||||||
|
|
||||||
def _get_mccabe_line_score(line):
|
def _get_mccabe_line_score(line):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue