From c1cd5095fcbc4782b9f263e71b27b3064c8b78ca Mon Sep 17 00:00:00 2001 From: Drew Bednar Date: Sat, 16 Sep 2023 16:28:33 -0400 Subject: [PATCH] Updates for linting and CI --- .drone.yml | 13 +++++++------ pyproject.toml | 1 + scripts/run_lint_checks.sh | 14 ++++++++++++++ tasks.py | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 6 deletions(-) create mode 100755 scripts/run_lint_checks.sh diff --git a/.drone.yml b/.drone.yml index 27b9bb5..7140bd5 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,18 +1,19 @@ kind: pipeline type: docker -name: CI Test Pipeline +name: CI Test/Lint Pipeline steps: -- name: greeting - image: alpine - commands: - - echo "Welcome to drone\n" - - name: Unit Tests image: python:3.11-bullseye commands: - bash -c './scripts/run_unit_tests.sh' +- name: Lint Check + parallel: true + image: python:3.11-bullseye + commands: + - bash -c './scripts/run_lint_checks.sh' + trigger: event: - pull_request diff --git a/pyproject.toml b/pyproject.toml index caf0352..4447454 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,6 +3,7 @@ profile = "black" line_length = 120 force_single_line = true filter_files = true +skip_glob = ["env/*"] [tool.black] line-length = 120 diff --git a/scripts/run_lint_checks.sh b/scripts/run_lint_checks.sh new file mode 100755 index 0000000..ae1d533 --- /dev/null +++ b/scripts/run_lint_checks.sh @@ -0,0 +1,14 @@ +#! /usr/bin/env bash +set -exu + +# shellcheck source=/dev/null +source "$(dirname "$0")/_common.sh" + +if [ "${DRONE:-false}" == "true" ]; then + _setup_env + pip install -r dev-requirements.txt +fi + +pushd "$(dirname "$0")/../" +"${VIRTUAL_ENV}/bin/python" -m invoke lint --verbose +popd diff --git a/tasks.py b/tasks.py index 9cd39f3..2f96d15 100644 --- a/tasks.py +++ b/tasks.py @@ -1,3 +1,6 @@ +import sys + +from invoke import Failure from invoke import task @@ -18,3 +21,37 @@ def serve_dev(c, debugger=True, reload=True, threads=True, port=8888, host="0.0. def test(c): """executes test suite""" c.run("pytest -vvv tests/", pty=True) + + +@task +def lint(c, verbose=False): + """Executes linter checks""" + exit_code = 0 + c.run("echo 'Checking isort'") + try: + c.run(f"isort {'-v' if verbose else ''} --check .", pty=True) + except Failure: + exit_code = 1 + + c.run("echo 'Lint check black'") + try: + c.run(f"black {'-v' if verbose else ''} --check .", pty=True) + except Failure: + exit_code = 1 + + c.run("echo 'Lint check with ruff'") + try: + c.run(f"ruff check {'-v' if verbose else ''} .", pty=True) + except Failure: + exit_code = 1 + + if exit_code: + c.run("echo 'ERROR: failed lint checks' >&2 ") + sys.exit(exit_code) + + +@task +def delint(c): + """Runs code formaters isort, black""" + c.run("isort .", pty=True) + c.run("black .", pty=True)