Skip to content

Commit eaf8465

Browse files
committed
Add pre-commit, initially to normalize Python code styling
References: * casework/CASE-Utilities-Python#37 Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
1 parent 87debcd commit eaf8465

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ _site
66
.dependencies.done.log
77
.git_submodule_init.done.log
88
.venv.done.log
9+
.venv-pre-commit
910
vendor/bundle
1011
venv
1112
__pycache__

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 22.3.0
4+
hooks:
5+
- id: black

Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ $(error python3 not found)
2323
endif
2424

2525
all: \
26+
.venv-pre-commit/var/.pre-commit-built.log \
2627
all-examples \
2728
all-migration-0.2.0 \
2829
all-ontology
@@ -71,6 +72,30 @@ all: \
7172
--requirement requirements.txt
7273
touch $@
7374

75+
# This virtual environment is meant to be built once and then persist, even through 'make clean'.
76+
# If a recipe is written to remove this flag file, it should first run `pre-commit uninstall`.
77+
.venv-pre-commit/var/.pre-commit-built.log:
78+
rm -rf .venv-pre-commit
79+
test -r .pre-commit-config.yaml \
80+
|| (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)
81+
$(PYTHON3) -m venv \
82+
.venv-pre-commit
83+
source .venv-pre-commit/bin/activate \
84+
&& pip install \
85+
--upgrade \
86+
pip \
87+
setuptools \
88+
wheel
89+
source .venv-pre-commit/bin/activate \
90+
&& pip install \
91+
pre-commit
92+
source .venv-pre-commit/bin/activate \
93+
&& pre-commit install
94+
mkdir -p \
95+
.venv-pre-commit/var
96+
touch $@
97+
98+
7499
all-examples: \
75100
.dependencies.done.log
76101
$(MAKE) \
@@ -86,6 +111,7 @@ all-ontology: \
86111
--directory ontology
87112

88113
check: \
114+
.venv-pre-commit/var/.pre-commit-built.log \
89115
check-examples \
90116
check-migration-0.2.0 \
91117
check-ontology

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ exclude:
4949
- vendor/ruby/
5050
# customer excludes
5151
- .venv.done.log
52+
- .venv-pre-commit/
5253
- CONTRIBUTE.md
5354
- Makefile
5455
- README.md

0 commit comments

Comments
 (0)