@@ -18,11 +18,18 @@ ifeq ($(shell basename $(SHELL)),sh)
18
18
SHELL := $(shell which /bin/bash 2>/dev/null || which /usr/local/bin/bash)
19
19
endif
20
20
21
- all :
21
+ PYTHON3 ?= python3
22
+ ifeq ($(PYTHON3 ) ,)
23
+ $(error python3 not found)
24
+ endif
25
+
26
+ all : \
27
+ .venv-pre-commit/var/.pre-commit-built.log
22
28
23
29
.PHONY : \
24
30
check-mypy \
25
- check-supply-chain
31
+ check-supply-chain \
32
+ check-supply-chain-pre-commit
26
33
27
34
.git_submodule_init.done.log : .gitmodules
28
35
# Confirm dfxml_schema has been checked out at least once.
31
38
test -r dependencies/dfxml_schema/dfxml.xsd
32
39
touch $@
33
40
41
+ # This virtual environment is meant to be built once and then persist, even through 'make clean'.
42
+ # If a recipe is written to remove this flag file, it should first run `pre-commit uninstall`.
43
+ .venv-pre-commit/var/.pre-commit-built.log :
44
+ rm -rf .venv-pre-commit
45
+ test -r .pre-commit-config.yaml \
46
+ || (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)
47
+ $(PYTHON3 ) -m venv \
48
+ .venv-pre-commit
49
+ source .venv-pre-commit/bin/activate \
50
+ && pip install \
51
+ --upgrade \
52
+ pip \
53
+ setuptools \
54
+ wheel
55
+ source .venv-pre-commit/bin/activate \
56
+ && pip install \
57
+ pre-commit
58
+ source .venv-pre-commit/bin/activate \
59
+ && pre-commit install
60
+ mkdir -p \
61
+ .venv-pre-commit/var
62
+ touch $@
63
+
34
64
clean :
35
65
find . -name ' *~' -exec rm {} \;
36
66
$(MAKE ) \
37
67
--directory tests \
38
68
clean
39
69
40
70
check : \
41
- check-mypy
71
+ .git_submodule_init.done.log \
72
+ .venv-pre-commit/var/.pre-commit-built.log
42
73
$(MAKE) \
74
+ PYTHON3=$(PYTHON3) \
43
75
SHELL=$(SHELL) \
44
76
--directory tests \
45
77
check
46
78
47
79
check-mypy : \
48
80
.git_submodule_init.done.log
49
81
$(MAKE) \
82
+ PYTHON3=$(PYTHON3) \
50
83
SHELL=$(SHELL) \
51
84
--directory tests \
52
85
check-mypy
53
86
54
87
check-supply-chain : \
88
+ check-supply-chain-pre-commit \
55
89
check-mypy
56
90
91
+ # Update pre-commit configuration and use the updated config file to
92
+ # review code. Only have Make exit if 'pre-commit run' modifies files.
93
+ check-supply-chain-pre-commit : \
94
+ .venv-pre-commit/var/.pre-commit-built.log
95
+ source .venv-pre-commit/bin/activate \
96
+ && pre-commit autoupdate
97
+ git diff \
98
+ --exit-code \
99
+ .pre-commit-config.yaml \
100
+ || ( \
101
+ source .venv-pre-commit/bin/activate \
102
+ && pre-commit run \
103
+ --all-files \
104
+ --config .pre-commit-config.yaml \
105
+ ) \
106
+ || git diff \
107
+ --stat \
108
+ --exit-code \
109
+ || ( \
110
+ echo \
111
+ "WARNING:Makefile:pre-commit configuration can be updated. It appears the updated would change file formatting." \
112
+ >&2 \
113
+ ; exit 1 \
114
+ )
115
+ @git diff \
116
+ --exit-code \
117
+ .pre-commit-config.yaml \
118
+ || echo \
119
+ "INFO:Makefile:pre-commit configuration can be updated. It appears the update would not change file formatting." \
120
+ >&2
121
+
57
122
check-tools :
58
123
(cd tests/misc_object_tests; make check)
0 commit comments