Skip to content

Commit a170bb1

Browse files
committed
Add pre-commit and configure hook to review with Black
Disclaimer: Participation by NIST in the creation of the documentation of mentioned software is not intended to imply a recommendation or endorsement by the National Institute of Standards and Technology, nor is it intended to imply that any specific software is necessarily the best available for the purpose. References: * [AC-215] Evaluate pre-commit usage on casework repositories * [AC-216] Apply Black to all casework Python code bases * #37 Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
1 parent 91eeb00 commit a170bb1

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

.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
.idea/
5+
.venv-pre-commit/
56
__pycache__
67
build/
78
case_utils.egg-info/

Makefile

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ $(error Unable to determine CASE version)
2121
endif
2222

2323
all: \
24-
.ontology.done.log
24+
.ontology.done.log \
25+
.venv-pre-commit/var/.pre-commit-built.log
2526

2627
.PHONY: \
2728
download
@@ -64,8 +65,32 @@ all: \
6465
test -r case_utils/ontology/case-$(case_version)-subclasses.ttl
6566
touch $@
6667

68+
# This virtual environment is meant to be built once and then persist, even through 'make clean'.
69+
# If a recipe is written to remove this flag file, it should first run `pre-commit uninstall`.
70+
.venv-pre-commit/var/.pre-commit-built.log:
71+
rm -rf .venv-pre-commit
72+
test -r .pre-commit-config.yaml \
73+
|| (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)
74+
$(PYTHON3) -m venv \
75+
.venv-pre-commit
76+
source .venv-pre-commit/bin/activate \
77+
&& pip install \
78+
--upgrade \
79+
pip \
80+
setuptools \
81+
wheel
82+
source .venv-pre-commit/bin/activate \
83+
&& pip install \
84+
pre-commit
85+
source .venv-pre-commit/bin/activate \
86+
&& pre-commit install
87+
mkdir -p \
88+
.venv-pre-commit/var
89+
touch $@
90+
6791
check: \
68-
.ontology.done.log
92+
.ontology.done.log \
93+
.venv-pre-commit/var/.pre-commit-built.log
6994
$(MAKE) \
7095
PYTHON3=$(PYTHON3) \
7196
--directory tests \

0 commit comments

Comments
 (0)