def critique(ui, repo, entire=False, node=None, **kwargs): """Perform a critique of a changeset.""" with demandimport.deactivated(): from flake8.engine import get_style_guide from pycodestyle import DiffReport, parse_udiff style = get_style_guide(parse_argv=False, ignore='E128') ctx = repo[node] if not entire: diff = ''.join(ctx.diff()) style.options.selected_lines = {} for k, v in parse_udiff(diff).items(): if k.startswith('./'): k = k[2:] style.options.selected_lines[k] = v style.options.report = DiffReport(style.options) deleted = repo.status(ctx.p1().node(), ctx.node())[2] files = [ f for f in ctx.files() if f.endswith('.py') and f not in deleted ] for f in files: data = ctx.filectx(f).data() style.input_file(f, lines=data.splitlines())
def critique(ui, repo, entire=False, node=None, **kwargs): """Perform a critique of a changeset.""" # We run into weird import issues when running static analysis if the # demandimporter is enabled. with demandimport.deactivated(): from flake8.engine import get_style_guide from pycodestyle import DiffReport, parse_udiff style = get_style_guide(parse_argv=False, ignore='E128') ctx = repo[node] # Tell the reporter to ignore lines we didn't touch as part of this change. if not entire: diff = ''.join(ctx.diff()) style.options.selected_lines = {} for k, v in parse_udiff(diff).items(): if k.startswith('./'): k = k[2:] style.options.selected_lines[k] = v style.options.report = DiffReport(style.options) deleted = repo.status(ctx.p1().node(), ctx.node()).deleted files = [ f for f in ctx.files() if f.endswith('.py') and f not in deleted ] for f in files: data = ctx.filectx(f).data() style.input_file(f, lines=data.splitlines())