Skip to content

Instantly share code, notes, and snippets.

@grantmcconnaughey
Created January 5, 2017 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grantmcconnaughey/fc59963886b8dd8131a632911dd7cbff to your computer and use it in GitHub Desktop.
Save grantmcconnaughey/fc59963886b8dd8131a632911dd7cbff to your computer and use it in GitHub Desktop.
def lint_entire_project(self, local_repo_path):
"""Runs quality checks on the local repo and returns the output as a string."""
self.state = BUILD_RUNNING
self.save()
process = subprocess.Popen(['flake8', local_repo_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False)
stdout, stderr = process.communicate()
return stdout
def parse_results(self, local_repo_path, raw_results):
"""Parses flake8 output into a dict of files with issues."""
results = raw_results.replace(local_repo_path, '')
file_issues = collections.defaultdict(list)
regex = re.compile(r'^(?P<path>.*):(?P<line>\d+):(?P<column>\d+): (?P<code>\w\d+) (?P<message>.*)$')
for line in results.strip().splitlines():
clean_line = line.strip()
match = regex.match(clean_line)
if not match:
continue
path = match.group('path')
result = {
'line': int(match.group('line')),
'column': int(match.group('column')),
'code': match.group('code'),
'message': match.group('message')
}
violations[path].append(result)
return violations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment