From 74d3fd36a23b5151a9d39631570a7717793ff1f0 Mon Sep 17 00:00:00 2001 From: checktheroads Date: Sun, 16 Jun 2019 13:04:47 -0700 Subject: [PATCH] testing pre-commit --- .pre-commit-config.yaml | 6 ++++++ .travis.yml | 14 ++++++++++++++ manage.py | 24 ++++++++++++++++++++++++ requirements.txt | 1 - 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 .pre-commit-config.yaml create mode 100644 .travis.yml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..67f8bb4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,6 @@ +repos: +- repo: https://github.com/python/black + rev: stable + hooks: + - id: black + language_version: python3 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..db59eab --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: python +python: + - "3.6" +before_install: + - sudo apt-get update -q + - sudo apt-get install -y redis + - pip3 install black +install: + - pip3 install -r requirements.txt + - pip3 install gunicorn + - pip3 install pylint +before_script: + - black hyperglass/ + - pylint hyperglass/ diff --git a/manage.py b/manage.py index 52ded0c..5c4c4b0 100755 --- a/manage.py +++ b/manage.py @@ -33,6 +33,30 @@ def hg(): pass +@hg.command("pylint-badge", help="Runs Pylint and generates a badge for GitHub") +def pylint_badge(): + try: + import re + import anybadge + from pylint import epylint + + pylint_stdout, pylint_stderr = epylint.py_run("hyperglass", return_std=True) + pylint_score = re.search( + r"Your code has been rated at (\d+\.\d+)\/10 \(previous run:.*", + pylint_stdout.getvalue(), + ).group(1) + if not pylint_score == "10.00": + raise RuntimeError(f"Pylint score {pylint_score} not acceptable.") + ab_thresholds = {1: "red", 10: "green"} + badge = anybadge.Badge("pylint", pylint_score, thresholds=ab_thresholds) + badge.write_badge("pylint.svg") + click.secho( + f"Created Pylint badge for score: {pylint_score}", fg="blue", bold=True + ) + except ImportError as error_exception: + click.secho(f"Import error:\n{error_exception}", fg="red", bold=True) + + @hg.command("pre-check", help="Check hyperglass config & readiness") def pre_check(): if sys.version_info < (3, 6): diff --git a/requirements.txt b/requirements.txt index 9c6592a..31d46d5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ Flask Flask-Limiter -flask-caching Jinja2 toml netmiko