From 8919d3f8f7cb0dc19d21886efd0f7b00134ee18f Mon Sep 17 00:00:00 2001 From: Christine Lytwynec Date: Tue, 3 Mar 2015 09:37:18 -0500 Subject: [PATCH] Store count of pep8 and pylint violations to files in reports dir --- pavelib/quality.py | 26 ++++++++++++++++++++++++-- pavelib/utils/envs.py | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/pavelib/quality.py b/pavelib/quality.py index 3b80d60820..49d39871e8 100644 --- a/pavelib/quality.py +++ b/pavelib/quality.py @@ -75,6 +75,9 @@ def run_pylint(options): violations_limit = int(getattr(options, 'limit', -1)) errors = getattr(options, 'errors', False) systems = getattr(options, 'system', ALL_SYSTEMS).split(',') + + # Make sure the metrics subdirectory exists + Env.METRICS_DIR.makedirs_p() for system in systems: # Directory to put the pylint report in. @@ -114,7 +117,15 @@ def run_pylint(options): num_violations += _count_pylint_violations( "{report_dir}/pylint.report".format(report_dir=report_dir)) - print("Number of pylint violations: " + str(num_violations)) + # Print number of violations to log + violations_count_str = "Number of pylint violations: " + str(num_violations) + print(violations_count_str) + + # Also write the number of violations to a file + with open(Env.METRICS_DIR / "pylint", "w") as f: + f.write(violations_count_str) + + # Fail number of violations is greater than the limit if num_violations > violations_limit > -1: raise Exception("Failed. Too many pylint violations. " "The limit is {violations_limit}.".format(violations_limit=violations_limit)) @@ -154,6 +165,9 @@ def run_pep8(options): report_dir = (Env.REPORT_DIR / 'pep8') report_dir.rmtree(ignore_errors=True) report_dir.makedirs_p() + + # Make sure the metrics subdirectory exists + Env.METRICS_DIR.makedirs_p() for system in systems: sh('pep8 {system} | tee {report_dir}/pep8.report -a'.format(system=system, report_dir=report_dir)) @@ -162,7 +176,15 @@ def run_pep8(options): "{report_dir}/pep8.report".format(report_dir=report_dir) ) - print("Number of pep8 violations: {count}".format(count=count)) + # Print number of violations to log + violations_count_str = "Number of pep8 violations: {count}".format(count=count) + print(violations_count_str) + + # Also write the number of violations to a file + with open(Env.METRICS_DIR / "pep8", "w") as f: + f.write(violations_count_str) + + # Fail if any violations are found if count: raise Exception( "Too many pep8 violations. Number of violations found: {count}.".format( diff --git a/pavelib/utils/envs.py b/pavelib/utils/envs.py index 0ea5a22f60..855cfa1b58 100644 --- a/pavelib/utils/envs.py +++ b/pavelib/utils/envs.py @@ -20,6 +20,7 @@ class Env(object): # Reports Directory REPORT_DIR = REPO_ROOT / 'reports' + METRICS_DIR = REPORT_DIR / 'metrics' # Bok_choy dirs BOK_CHOY_DIR = REPO_ROOT / "common" / "test" / "acceptance"