Skip to content

Commit 40ed46b

Browse files
committed
Add pre-commit to CI
References: * casework/CASE-Utilities-Python#37 Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
1 parent a127294 commit 40ed46b

File tree

5 files changed

+57
-3
lines changed

5 files changed

+57
-3
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ jobs:
3131
uses: actions/setup-python@v2
3232
with:
3333
python-version: ${{ matrix.python-version }}
34+
- name: Pre-commit Checks
35+
run: |
36+
pip -q install pre-commit
37+
pre-commit run --all-files
3438
- name: Install Python virtualenv for Github runner
3539
run: |
3640
python -m pip install --upgrade pip

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*.swp
33
.DS_Store
44
.git_submodule_init.done.log
5+
.venv-pre-commit
56
__pycache__
67
build
78
dist

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 22.10.0
4+
hooks:
5+
- id: black
6+
- repo: https://github.com/pycqa/flake8
7+
rev: 5.0.4
8+
hooks:
9+
- id: flake8
10+
- repo: https://github.com/pycqa/isort
11+
rev: 5.10.1
12+
hooks:
13+
- id: isort
14+
name: isort (python)

Makefile

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ SHELL := /bin/bash
1515

1616
PYTHON3 ?= python3
1717

18-
# This recipe intentionally blank.
19-
all:
18+
all: \
19+
.venv-pre-commit/var/.pre-commit-built.log
2020

2121
.PHONY: \
2222
download
@@ -33,8 +33,32 @@ all:
3333
.git_submodule_init.done.log
3434
touch $@
3535

36+
# This virtual environment is meant to be built once and then persist, even through 'make clean'.
37+
# If a recipe is written to remove this flag file, it should first run `pre-commit uninstall`.
38+
.venv-pre-commit/var/.pre-commit-built.log:
39+
rm -rf .venv-pre-commit
40+
test -r .pre-commit-config.yaml \
41+
|| (echo "ERROR:Makefile:pre-commit is expected to install for this repository, but .pre-commit-config.yaml does not seem to exist." >&2 ; exit 1)
42+
$(PYTHON3) -m venv \
43+
.venv-pre-commit
44+
source .venv-pre-commit/bin/activate \
45+
&& pip install \
46+
--upgrade \
47+
pip \
48+
setuptools \
49+
wheel
50+
source .venv-pre-commit/bin/activate \
51+
&& pip install \
52+
pre-commit
53+
source .venv-pre-commit/bin/activate \
54+
&& pre-commit install
55+
mkdir -p \
56+
.venv-pre-commit/var
57+
touch $@
58+
3659
check: \
37-
.git_submodule_init.done.log
60+
.git_submodule_init.done.log \
61+
.venv-pre-commit/var/.pre-commit-built.log
3862
$(MAKE) \
3963
PYTHON3=$(PYTHON3) \
4064
--directory tests \

setup.cfg

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,14 @@ console_scripts =
2828

2929
[options.package_data]
3030
case_gnu_time = py.typed
31+
32+
[flake8]
33+
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8
34+
extend-ignore =
35+
E203
36+
E302
37+
E501
38+
39+
[isort]
40+
# https://pycqa.github.io/isort/docs/configuration/black_compatibility.html
41+
profile = black

0 commit comments

Comments
 (0)