Commit 28a3e9f5 by Ben Patterson

Merge pull request #7178 from edx/benp/make-pep8-output-easier

Make pep8 failure output easier to understand.
parents ecbfe5c9 ff2dd934
...@@ -143,31 +143,32 @@ def _count_pylint_violations(report_file): ...@@ -143,31 +143,32 @@ def _count_pylint_violations(report_file):
@needs('pavelib.prereqs.install_python_prereqs') @needs('pavelib.prereqs.install_python_prereqs')
@cmdopts([ @cmdopts([
("system=", "s", "System to act on"), ("system=", "s", "System to act on"),
("limit=", "l", "limit for number of acceptable violations"),
]) ])
def run_pep8(options): def run_pep8(options):
""" """
Run pep8 on system code. When violations limit is passed in, Run pep8 on system code.
fail the task if too many violations are found. Fail the task if any violations are found.
""" """
num_violations = 0
systems = getattr(options, 'system', ALL_SYSTEMS).split(',') systems = getattr(options, 'system', ALL_SYSTEMS).split(',')
violations_limit = int(getattr(options, 'limit', -1))
report_dir = (Env.REPORT_DIR / 'pep8')
report_dir.rmtree(ignore_errors=True)
report_dir.makedirs_p()
for system in systems: for system in systems:
# Directory to put the pep8 report in. sh('pep8 {system} | tee {report_dir}/pep8.report -a'.format(system=system, report_dir=report_dir))
# This makes the folder if it doesn't already exist.
report_dir = (Env.REPORT_DIR / system).makedirs_p()
sh('pep8 {system} | tee {report_dir}/pep8.report'.format(system=system, report_dir=report_dir)) count = _count_pep8_violations(
num_violations = num_violations + _count_pep8_violations( "{report_dir}/pep8.report".format(report_dir=report_dir)
"{report_dir}/pep8.report".format(report_dir=report_dir)) )
print("Number of pep8 violations: " + str(num_violations)) print("Number of pep8 violations: {count}".format(count=count))
# Fail the task if the violations limit has been reached if count:
if num_violations > violations_limit > -1: raise Exception(
raise Exception("Failed. Too many pep8 violations. " "Too many pep8 violations. Number of violations found: {count}.".format(
"The limit is {violations_limit}.".format(violations_limit=violations_limit)) count=count
)
)
def _count_pep8_violations(report_file): def _count_pep8_violations(report_file):
......
...@@ -62,7 +62,6 @@ source scripts/jenkins-common.sh ...@@ -62,7 +62,6 @@ source scripts/jenkins-common.sh
# Violations thresholds for failing the build # Violations thresholds for failing the build
PYLINT_THRESHOLD=6000 PYLINT_THRESHOLD=6000
PEP8_THRESHOLD=0
# If the environment variable 'SHARD' is not set, default to 'all'. # If the environment variable 'SHARD' is not set, default to 'all'.
# This could happen if you are trying to use this script from # This could happen if you are trying to use this script from
...@@ -75,7 +74,7 @@ case "$TEST_SUITE" in ...@@ -75,7 +74,7 @@ case "$TEST_SUITE" in
"quality") "quality")
paver find_fixme > fixme.log || { cat fixme.log; EXIT=1; } paver find_fixme > fixme.log || { cat fixme.log; EXIT=1; }
paver run_pep8 -l $PEP8_THRESHOLD > pep8.log || { cat pep8.log; EXIT=1; } paver run_pep8 > pep8.log || { cat pep8.log; EXIT=1; }
paver run_pylint -l $PYLINT_THRESHOLD > pylint.log || { cat pylint.log; EXIT=1; } paver run_pylint -l $PYLINT_THRESHOLD > pylint.log || { cat pylint.log; EXIT=1; }
# Run quality task. Pass in the 'fail-under' percentage to diff-quality # Run quality task. Pass in the 'fail-under' percentage to diff-quality
paver run_quality -p 100 paver run_quality -p 100
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment