From 5ca2d163589547cac2f569e0eaed259810673f00 Mon Sep 17 00:00:00 2001 From: Abe Coull <85974725+math411@users.noreply.github.com> Date: Fri, 15 Sep 2023 06:06:27 -0700 Subject: [PATCH] infra: update the pre-commit hook with linters (#678) * infra: update the pre-commit hook with linters and secrets check Co-authored-by: Abe Coull Co-authored-by: Cody Wang --- .git-template/hooks/pre-commit | 5 +++++ .pre-commit-config.yaml | 24 +++++++----------------- tox.ini | 29 +++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 .git-template/hooks/pre-commit diff --git a/.git-template/hooks/pre-commit b/.git-template/hooks/pre-commit new file mode 100644 index 000000000..6d8d24a1d --- /dev/null +++ b/.git-template/hooks/pre-commit @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +if [ -f .pre-commit-config.yaml ]; then + echo 'pre-commit configuration detected, but `pre-commit install` was never run' 1>&2 + exit 1 +fi diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d03e4d3d2..e9eea7581 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,18 +1,8 @@ repos: -- repo: local - hooks: - - id: tox - name: tox - stages: [push] - language: system - entry: tox - types: [python] - pass_filenames: false - - - id: tox_integ_tests - name: tox integ tests - stages: [push] - language: system - entry: tox -e integ-tests - types: [python] - pass_filenames: false + - repo: local + hooks: + - id: tox_linters + name: linters + entry: tox -e linters_check + language: system + types: [python] diff --git a/tox.ini b/tox.ini index 59de91a16..b49c673c0 100644 --- a/tox.ini +++ b/tox.ini @@ -41,6 +41,19 @@ commands = {[testenv:black]commands} {[testenv:flake8]commands} +# Read only linter env +[testenv:linters_check] +basepython = python3 +skip_install = true +deps = + {[testenv:isort_check]deps} + {[testenv:black_check]deps} + {[testenv:flake8]deps} +commands = + {[testenv:isort_check]commands} + {[testenv:black_check]commands} + {[testenv:flake8]commands} + [testenv:flake8] basepython = python3 skip_install = true @@ -60,6 +73,14 @@ deps = commands = isort . {posargs} +[testenv:isort_check] +basepython = python3 +skip_install = true +deps = + isort +commands = + isort . -c {posargs} + [testenv:black] basepython = python3 skip_install = true @@ -68,6 +89,14 @@ deps = commands = black ./ {posargs} +[testenv:black_check] +basepython = python3 +skip_install = true +deps = + black +commands = + black --check . {posargs} + [testenv:docs] basepython = python3 deps =