From 63244306c3196db5c5b0845ec1e37756b575be30 Mon Sep 17 00:00:00 2001 From: Matt Love Date: Mon, 8 Jul 2019 01:20:37 -0700 Subject: [PATCH] Add pylint debug option for CI --- .travis.yml | 2 +- manage.py | 35 +++++++++++------------------------ 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index fc328f7..64b0beb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ before_script: - pip3 install -r ./tests/requirements_dev.txt - pylint --version - black --check hyperglass - - python3 ./manage.py pylint-check --integer-only True + - python3 ./manage.py pylint-check -e - python3 ./tests/ci_prepare.py script: - nohup python3 ./tests/ci_dev_server.py & diff --git a/manage.py b/manage.py index 89adc43..836be3a 100755 --- a/manage.py +++ b/manage.py @@ -42,27 +42,14 @@ def hg(): "-i", "--integer-only", "int_only", - type=bool, - default=False, + is_flag=True, help="Output Pylint score as integer", ) +@click.option("-b", "--badge", "create_badge", is_flag=True, help="Create Pylint badge") @click.option( - "-b", - "--badge", - "create_badge", - type=bool, - default=False, - help="Create Pylint badge", + "-e", "--print-errors", "errors", is_flag=True, help="Print pylint errors" ) -@click.option( - "-e", - "--print-errors", - "errors", - type=bool, - default=False, - help="Print pylint errors", -) -def pylint_check(int_only, create_badge): +def pylint_check(int_only, create_badge, errors): try: import re import anybadge @@ -73,6 +60,10 @@ def pylint_check(int_only, create_badge): pylint_score = re.search( r"Your code has been rated at (\d+\.\d+)\/10.*", pylint_output ).group(1) + if int_only: + click.echo(pylint_score) + if errors: + click.echo(pylint_output) if not pylint_score == "10.00": raise RuntimeError(f"Pylint score {pylint_score} not acceptable.") if create_badge: @@ -82,14 +73,10 @@ def pylint_check(int_only, create_badge): ab_thresholds = {1: "red", 10: "green"} badge = anybadge.Badge("pylint", pylint_score, thresholds=ab_thresholds) badge.write_badge("pylint.svg") - if not int_only: - click.secho( - f"Created Pylint badge for score: {pylint_score}", fg="blue", bold=True + click.echo( + click.style("Created Pylint badge for score: ", fg="white") + + click.style(pylint_score, fg="blue", bold=True) ) - if int_only: - click.echo(pylint_score) - if errors: - click.echo(pylint_output) except ImportError as error_exception: click.secho(f"Import error:\n{error_exception}", fg="red", bold=True)