Skip to content

Commit f5b46dc

Browse files
committed
Add pre-commit
This implementation was copied from case-utils. A follow-on patch will apply pre-commit effects. References: * casework/CASE-Utilities-Python#37 Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
1 parent b2acea4 commit f5b46dc

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ jobs:
3232
uses: actions/setup-python@v2
3333
with:
3434
python-version: ${{ matrix.python-version }}
35+
- name: Pre-commit Checks
36+
run: |
37+
pip -q install pre-commit
38+
pre-commit run --all-files
3539
- name: Start from clean state
3640
run: make clean
3741
- name: Run tests

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*.swp
55
.generated-*
66
.pytest_cache
7+
.venv-pre-commit
78
__pycache__
89
build
910
catalog-v001.xml

.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.6.0
4+
hooks:
5+
- id: black
6+
- repo: https://github.com/pycqa/flake8
7+
rev: 4.0.1
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ PYTHON3 ?= $(shell which python3.9 2>/dev/null || which python3.8 2>/dev/null ||
1818
GSED ?= $(shell which gsed 2>/dev/null || which sed)
1919

2020
all: \
21+
.venv-pre-commit/var/.pre-commit-built.log \
2122
README.md
2223

2324
.PHONY: \
@@ -59,8 +60,32 @@ README.md: \
5960
--directory lib
6061
touch $@
6162

63+
# This virtual environment is meant to be built once and then persist, even through 'make clean'.
64+
# If a recipe is written to remove this flag file, it should first run `pre-commit uninstall`.
65+
.venv-pre-commit/var/.pre-commit-built.log:
66+
rm -rf .venv-pre-commit
67+
test -r .pre-commit-config.yaml \
68+
|| (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)
69+
$(PYTHON3) -m venv \
70+
.venv-pre-commit
71+
source .venv-pre-commit/bin/activate \
72+
&& pip install \
73+
--upgrade \
74+
pip \
75+
setuptools \
76+
wheel
77+
source .venv-pre-commit/bin/activate \
78+
&& pip install \
79+
pre-commit
80+
source .venv-pre-commit/bin/activate \
81+
&& pre-commit install
82+
mkdir -p \
83+
.venv-pre-commit/var
84+
touch $@
85+
6286
# After running unit tests, see if README.md needs to be regenerated.
6387
check: \
88+
.venv-pre-commit/var/.pre-commit-built.log \
6489
.lib.done.log
6590
$(MAKE) \
6691
PYTHON3=$(PYTHON3) \
@@ -80,7 +105,8 @@ clean:
80105
clean
81106

82107
download: \
83-
.lib.done.log
108+
.lib.done.log \
109+
.venv-pre-commit/var/.pre-commit-built.log
84110
$(MAKE) \
85111
PYTHON3=$(PYTHON3) \
86112
--directory tests \

setup.cfg

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,14 @@ python_requires = >=3.7
2525
[options.entry_points]
2626
console_scripts =
2727
case_shacl_inheritance_reviewer = case_shacl_inheritance_reviewer:main
28+
29+
[flake8]
30+
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8
31+
extend-ignore =
32+
E203
33+
E302
34+
E501
35+
36+
[isort]
37+
# https://pycqa.github.io/isort/docs/configuration/black_compatibility.html
38+
profile = black

0 commit comments

Comments
 (0)