Skip to content

Commit 5a5ac93

Browse files
committed
Add venv for only pre-commit
This dedicated virtual environment is intended to persist through `make clean`, not disrupting the ability to run regular Git commits if the "primary" virtual environment is removed. The `pre-commit` experience it produces should align make- and local-venv-oriented users with users who have a more global availability of `pre-commit`. References: * casework/CASE-Utilities-Python#37 Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
1 parent 23bb52e commit 5a5ac93

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
@@ -15,4 +15,5 @@ catalog-v001.xml
1515

1616
# Workflow files
1717
.*.done.log
18+
.venv-pre-commit
1819
venv

Makefile

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ SHELL := /bin/bash
1616
PYTHON3 ?= $(shell which python3.9 2>/dev/null || which python3.8 2>/dev/null || which python3.7 2>/dev/null || which python3.6 2>/dev/null || which python3)
1717

1818
all: \
19-
.dependencies.done.log
19+
.dependencies.done.log \
20+
.venv-pre-commit/var/.pre-commit-built.log
2021
$(MAKE) \
2122
--directory examples/illustrations
2223

@@ -64,6 +65,29 @@ all: \
6465
.lib.done.log
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 expect 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
.venv.done.log: \
6892
.git_submodule_init.done.log \
6993
requirements.txt
@@ -85,7 +109,8 @@ all: \
85109
touch $@
86110

87111
check: \
88-
.dependencies.done.log
112+
.dependencies.done.log \
113+
.venv-pre-commit/var/.pre-commit-built.log
89114
$(MAKE) \
90115
--directory examples/illustrations \
91116
check

0 commit comments

Comments
 (0)