-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
296 lines (233 loc) · 10 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
################################################################################
# * Utilities
################################################################################
.PHONY: clean clean-test clean-pyc clean-build help
.DEFAULT_GOAL := help
define BROWSER_PYSCRIPT
import os, webbrowser, sys
from urllib.request import pathname2url
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
endef
export BROWSER_PYSCRIPT
define PRINT_HELP_PYSCRIPT
import re, sys
for line in sys.stdin:
match = re.match(r'^([a-zA-Z_/.-]+):.*?## (.*)$$', line)
if match:
target, help = match.groups()
print("%-20s %s" % (target, help))
endef
export PRINT_HELP_PYSCRIPT
BROWSER := python -c "$$BROWSER_PYSCRIPT"
help:
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts
clean-build: ## remove build artifacts
rm -fr build/
rm -fr docs/_build/
rm -fr dist/
rm -fr .eggs/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +
clean-pyc: ## remove Python file artifacts
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +
clean-test: ## remove test and coverage artifacts
rm -fr .nox/
rm -f .coverage
rm -fr htmlcov/
rm -fr .pytest_cache
################################################################################
# * Pre-commit
################################################################################
.PHONY: pre-commit-init pre-commit pre-commit-all
pre-commit-init: ## install pre-commit
pre-commit install
pre-commit: ## run pre-commit
pre-commit run
pre-commit-all: ## run pre-commit on all files
pre-commit run --all-files
.PHONY: pre-commit-lint pre-commit-lint-notebooks pre-commit-prettier pre-commit-lint-markdown
pre-commit-lint: ## run ruff and black on on all files
pre-commit run --all-files ruff
pre-commit run --all-files black
pre-commit run --all-files blacken-docs
pre-commit-lint-notebooks: ## Run nbqa linting
pre-commit run --all-files nbqa-ruff
pre-commit run --all-files nbqa-black
pre-commit-prettier: ## run prettier on all files.
pre-commit run --all-files prettier
pre-commit-lint-markdown: ## run markdown linter.
pre-commit run --all-files --hook-stage manual markdownlint-cli2
.PHONY: pre-commit-lint-extra pre-commit-mypy pre-commit-codespell
pre-commit-lint-extra: ## run all extra linting (isort, flake8, pyupgrade, nbqa isort and pyupgrade)
pre-commit run --all-files --hook-stage manual isort
pre-commit run --all-files --hook-stage manual flake8
pre-commit run --all-files --hook-stage manual pyupgrade
pre-commit run --all-files --hook-stage manual nbqa-pyupgrade
pre-commit run --all-files --hook-stage manual nbqa-isort
pre-commit-mypy: ## run mypy
pre-commit run --all-files --hook-stage manual mypy
pre-commit-pyright: ## run pyright
pre-commit run --all-files --hook-stage manual pyright
pre-commit-codespell: ## run codespell. Note that this imports allowed words from docs/spelling_wordlist.txt
pre-commit run --all-files --hook-stage manual codespell
################################################################################
# * User setup
################################################################################
.PHONY: user-venv user-autoenv-zsh user-all
user-venv: ## create .venv file with name of conda env
echo $${PWD}/.nox/cookiecutter-nist-python/envs/dev > .venv
user-autoenv-zsh: ## create .autoenv.zsh files
echo conda activate $$(cat .venv) > .autoenv.zsh
echo conda deactivate > .autoenv_leave.zsh
user-all: user-venv user-autoenv-zsh ## runs user scripts
################################################################################
# * Testing
################################################################################
.PHONY: test coverage
test: ## run tests quickly with the default Python
pytest -x -v
test-accept: ## run tests and accept doctest results. (using pytest-accept)
DOCFILLER_SUB=False pytest -v --accept
coverage: ## check code coverage quickly with the default Python
coverage run --source cookiecutter_nist_python -m pytest
coverage report -m
coverage html
$(BROWSER) htmlcov/index.html
################################################################################
# * Versioning
################################################################################
.PHONY: version-scm version-import version
version-scm: ## check/update version of package with setuptools-scm
python -m setuptools_scm
version-import: ## check version from python import
-python -c 'import cookiecutter_nist_python; print(cookiecutter_nist_python.__version__)'
version: version-scm version-import
################################################################################
# * Requirements/Environment files
################################################################################
.PHONY: requirements
requirements: ## rebuild all requirements/environment files
nox -s requirements
requirements/%.yaml: pyproject.toml requirements
requirements/%.txt: pyproject.toml requirements
################################################################################
# * NOX
###############################################################################
# NOTE: Below, we use requirement of the form "requirements/dev.txt"
# Since any of these files will trigger a rebuild of all requirements,
# the actual "txt" or "yaml" file doesn't matter
# ** dev
NOX=nox
.PHONY: dev-env
dev-env: requirements/dev.txt ## create development environment using nox
$(NOX) -e dev
# ** testing
.PHONY: test-all
test-all: requirements/test.txt ## run tests on every Python version with nox.
$(NOX) -s test
# ** docs
.PHONY: docs-build docs-release docs-clean docs-command
docs-build: ## build docs in isolation
$(NOX) -s docs -- -d build
docs-clean: ## clean docs
rm -rf docs/_build/*
rm -rf docs/generated/*
rm -rf docs/reference/generated/*
docs-clean-build: docs-clean docs-build ## clean and build
docs-release: ## release docs.
$(NOX) -s docs -- -d release
docs-command: ## run arbitrary command with command=...
$(NOX) -s docs -- --docs-run $(command)
.PHONY: .docs-spelling docs-nist-pages docs-open docs-livehtml docs-clean-build docs-linkcheck
docs-spelling: ## run spell check with sphinx
$(NOX) -s docs -- -d spelling
docs-livehtml: ## use autobuild for docs
$(NOX) -s docs -- -d livehtml
docs-open: ## open the build
$(NOX) -s docs -- -d open
docs-linkcheck: ## check links
$(NOX) -s docs -- -d linkcheck
docs-build docs-release docs-command docs-clean docs-livehtml docs-linkcheck: requirements/docs.txt
# ** typing
.PHONY: typing-mypy typing-pyright typing-pytype typing-all typing-command
typing-mypy: ## run mypy mypy_args=...
$(NOX) -s typing -- -m mypy
typing-pyright: ## run pyright pyright_args=...
$(NOX) -s typing -- -m pyright
typing-pytype: ## run pytype pytype_args=...
$(NOX) -s typing -- -m pytype
typing-all:
$(NOX) -s typing -- -m mypy pyright pytype
typing-command:
$(NOX) -s typing -- --typing-run $(command)
typing-mypy typing-pyright typing-pytype typing-all typing-command: requirements/typing.txt
# ** dist pypi
.PHONY: dist-pypi-build dist-pypi-testrelease dist-pypi-release dist-pypi-command
dist-pypi-build: ## build dist
$(NOX) -s dist-pypi -- -p build
dist-pypi-testrelease: ## test release on testpypi
$(NOX) -s dist-pypi -- -p testrelease
dist-pypi-release: ## release to pypi, can pass posargs=...
$(NOX) -s dist-pypi -- -p release
dist-pypi-command: ## run command with command=...
$(NOX) -s dist-pypi -- --dist-pypi-run $(command)
dist-pypi-build dist-pypi-testrelease dist-pypi-release dist-pypi-command: requirements/dist-pypi.txt
# ** dist conda
.PHONY: dist-conda-recipe dist-conda-build dist-conda-command
dist-conda-recipe: ## build conda recipe can pass posargs=...
$(NOX) -s dist-conda -- -c recipe
dist-conda-build: ## build conda recipe can pass posargs=...
$(NOX) -s dist-conda -- -c build
dist-conda-command: ## run command with command=...
$(NOX) -s dist-conda -- -dist-conda-run $(command)
dist-conda-build dist-conda-recipe dist-conda-command: requirements/dist-pypi.txt
# ** list all options
.PHONY: nox-list
nox-list:
$(NOX) --list
################################################################################
# * Installation
################################################################################
.PHONY: install install-dev
install: ## install the package to the active Python's site-packages (run clean?)
pip install . --no-deps
install-dev: ## install development version (run clean?)
pip install -e . --no-deps
################################################################################
# * Other tools
################################################################################
# Note that this requires `auto-changelog`, which can be installed with pip(x)
auto-changelog: ## autogenerate changelog and print to stdout
auto-changelog -u -r usnistgov -v unreleased --tag-prefix v --stdout --template changelog.d/templates/auto-changelog/template.jinja2
commitizen-changelog:
cz changelog --unreleased-version unreleased --dry-run --incremental
# tuna analyze load time:
.PHONY: tuna-analyze
tuna-import: ## Analyze load time for module
python -X importtime -c 'import cookiecutter_nist_python' 2> tuna-loadtime.log
tuna tuna-loadtime.log
rm tuna-loadtime.log
# nbqa-mypy
NOTEBOOKS ?= examples/usage
.PHONY: nbqa-mypy nbqa-pyright nbqa-typing
nbqa-mypy: ## run nbqa mypy
nbqa --nbqa-shell mypy $(NOTEBOOKS)
nbqa-pyright: ## run nbqa pyright
nbqa --nbqa-shell pyright $(NOTEBOOKS)
nbqa-typing: nbqa-mypy nbqa-pyright ## run nbqa mypy/pyright
.PHONY: pytest-nbval
pytest-nbval: ## run pytest --nbval
pytest --nbval --current-env --sanitize-with=config/nbval.ini $(NOTEBOOKS) -x
# cookiecutter stuff
BAKE_OPTIONS=--no-input
bake: ## generate project using defaults
cookiecutter $(BAKE_OPTIONS) . --overwrite-if-exists
watch: bake ## watchmedo bake
watchmedo shell-command -p '*.*' -c 'make bake -e BAKE_OPTIONS=$(BAKE_OPTIONS)' -W -R -D \{{cookiecutter.project_slug}}/
replay: BAKE_OPTIONS=--replay
replay: watch ## replay watch
;