Commit f73d92bf by Ben Patterson

Merge pull request #6064 from Stanford-Online/kluo/quality-compare-branch-option

Add compare-branch option to paver run_quality
parents 281be28f 2262906e
...@@ -126,14 +126,16 @@ def _count_pep8_violations(report_file): ...@@ -126,14 +126,16 @@ def _count_pep8_violations(report_file):
@task @task
@needs('pavelib.prereqs.install_python_prereqs') @needs('pavelib.prereqs.install_python_prereqs')
@cmdopts([ @cmdopts([
("compare-branch=", "b", "Branch to compare against, defaults to origin/master"),
("percentage=", "p", "fail if diff-quality is below this percentage"), ("percentage=", "p", "fail if diff-quality is below this percentage"),
]) ])
def run_quality(options): def run_quality(options):
""" """
Build the html diff quality reports, and print the reports to the console. Build the html diff quality reports, and print the reports to the console.
:param: b, the branch to compare against, defaults to origin/master
:param: p, diff-quality will fail if the quality percentage calculated is :param: p, diff-quality will fail if the quality percentage calculated is
below this percentage. For example, if p is set to 80, and diff-quality finds below this percentage. For example, if p is set to 80, and diff-quality finds
quality of the branch vs master is less than 80%, then this task will fail. quality of the branch vs the compare branch is less than 80%, then this task will fail.
This threshold would be applied to both pep8 and pylint. This threshold would be applied to both pep8 and pylint.
""" """
...@@ -142,6 +144,12 @@ def run_quality(options): ...@@ -142,6 +144,12 @@ def run_quality(options):
dquality_dir = (Env.REPORT_DIR / "diff_quality").makedirs_p() dquality_dir = (Env.REPORT_DIR / "diff_quality").makedirs_p()
diff_quality_percentage_failure = False diff_quality_percentage_failure = False
# Set the string, if needed, to be used for the diff-quality --compare-branch switch.
compare_branch = getattr(options, 'compare_branch', None)
compare_branch_string = ''
if compare_branch:
compare_branch_string = '--compare-branch={0}'.format(compare_branch)
# Set the string, if needed, to be used for the diff-quality --fail-under switch. # Set the string, if needed, to be used for the diff-quality --fail-under switch.
diff_threshold = int(getattr(options, 'percentage', -1)) diff_threshold = int(getattr(options, 'percentage', -1))
percentage_string = '' percentage_string = ''
...@@ -158,9 +166,10 @@ def run_quality(options): ...@@ -158,9 +166,10 @@ def run_quality(options):
try: try:
sh( sh(
"diff-quality --violations=pep8 {pep8_reports} {percentage_string} " "diff-quality --violations=pep8 {pep8_reports} {percentage_string} "
"--html-report {dquality_dir}/diff_quality_pep8.html".format( "{compare_branch_string} --html-report {dquality_dir}/diff_quality_pep8.html".format(
pep8_reports=pep8_reports, pep8_reports=pep8_reports,
percentage_string=percentage_string, percentage_string=percentage_string,
compare_branch_string=compare_branch_string,
dquality_dir=dquality_dir dquality_dir=dquality_dir
) )
) )
...@@ -185,12 +194,13 @@ def run_quality(options): ...@@ -185,12 +194,13 @@ def run_quality(options):
try: try:
sh( sh(
"{pythonpath_prefix} diff-quality --violations=pylint " "{pythonpath_prefix} diff-quality --violations=pylint "
"{pylint_reports} {percentage_string} " "{pylint_reports} {percentage_string} {compare_branch_string} "
"--html-report {dquality_dir}/diff_quality_pylint.html " "--html-report {dquality_dir}/diff_quality_pylint.html "
"--options='{pylint_options}'".format( "--options='{pylint_options}'".format(
pythonpath_prefix=pythonpath_prefix, pythonpath_prefix=pythonpath_prefix,
pylint_reports=pylint_reports, pylint_reports=pylint_reports,
percentage_string=percentage_string, percentage_string=percentage_string,
compare_branch_string=compare_branch_string,
dquality_dir=dquality_dir, dquality_dir=dquality_dir,
pylint_options="--disable=fixme", pylint_options="--disable=fixme",
) )
......
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