-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
323 lines (231 loc) · 9.48 KB
/
Makefile
File metadata and controls
323 lines (231 loc) · 9.48 KB
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
.PHONY: clean clean-pyc clean-test coverage dist docs help install lint lint/flake8 lint/black lint/mypy
.DEFAULT_GOAL := help
SHELL := /bin/bash
export NBW_ROOT=$(CURDIR)/build/nbw-root
define PROJECT
nb_wrangler
endef
export PROJECT
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
define TEST_OUTPUTS
output
references
endef
export TEST_OUTPUTS
help:
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
setup:
pip install .[dev]
# ==========================================================================================================
YAML_FILES := $(shell find sample-specs/fnc-test-spec.yaml sample-specs -name "*.yaml")
.PHONY: specs-update specs-curate specs-data-curate specs-validate
check-env:
@echo "PATH in recipe: $$PATH"
@which python || true
specs-update: $(YAML_FILES)
@for f in $^; do \
./nb-wrangler --spec-update "$$f"; \
done
specs-validate: $(YAML_FILES)
@for f in $^; do \
./nb-wrangler --spec-validate "$$f"; \
done
specs-curate: $(YAML_FILES)
@for f in $^; do \
./nb-wrangler --reset-curation "$$f"; \
./nb-wrangler --curate "$$f"; \
done
specs-data-curate: $(YAML_FILES)
@for f in $^; do \
./nb-wrangler --data-reset "$$f"; \
./nb-wrangler --data-curate "$$f"; \
done
# ==========================================================================================================
test-functional: setup functional data-functional data-clean test-advanced-mamba
test-advanced-mamba:
./tests/test-advanced-mamba.sh
functional: fnc-preclean fnc-bootstrap functional-develop functional-tests functional-reinstall functional-misc
functional-develop: fnc-curate
functional-reinstall: fnc-reinstall
functional-tests: fnc-test fnc-test-imports fnc-test-notebooks
functional-misc: fnc-compact fnc-env-pack fnc-packages-uninstall fnc-env-unpack \
fnc-env-unregister fnc-env-register fnc-env-delete fnc-spec-reset fnc-packages-compile \
fnc-env-kernel-cleanup fnc-spi-basic-workflow
fnc-preclean:
rm -rf ${NBW_ROOT} ./references
fnc-bootstrap: fnc-preclean
# curl https://raw.githubusercontent.com/spacetelescope/nb-wrangler/refs/heads/main/nb-wrangler >nb-wrangler
# chmod +x nb-wrangler
./nb-wrangler bootstrap
fnc-curate:
./nb-wrangler sample-specs/fnc-test-spec.yaml --curate
fnc-reinstall:
./nb-wrangler sample-specs/fnc-test-spec.yaml --reinstall
fnc-packages-uninstall: fnc-curate
./nb-wrangler sample-specs/fnc-test-spec.yaml --packages-uninstall
fnc-packages-install: fnc-curate fnc-packages-uninstall
./nb-wrangler sample-specs/fnc-test-spec.yaml --packages-install
fnc-env-pack: fnc-packages-install
./nb-wrangler sample-specs/fnc-test-spec.yaml --env-pack
fnc-env-unpack: fnc-packages-uninstall
./nb-wrangler sample-specs/fnc-test-spec.yaml --env-unpack
fnc-test-imports: fnc-packages-install
./nb-wrangler sample-specs/fnc-test-spec.yaml --test-imports
fnc-test-notebooks: fnc-packages-install
./nb-wrangler sample-specs/fnc-test-spec.yaml --test-notebooks zooniverse_view
fnc-test: fnc-packages-install
./nb-wrangler sample-specs/fnc-test-spec.yaml -t zooniverse_view
fnc-compact: fnc-packages-install
./nb-wrangler sample-specs/fnc-test-spec.yaml --env-compact
fnc-packages-compile: fnc-clone-repos
./nb-wrangler sample-specs/fnc-test-spec.yaml --packages-compile
fnc-clone-repos:
./nb-wrangler sample-specs/fnc-test-spec.yaml --clone-repos
fnc-env-init: fnc-packages-compile
./nb-wrangler sample-specs/fnc-test-spec.yaml --env-init
fnc-env-delete: fnc-env-init
./nb-wrangler sample-specs/fnc-test-spec.yaml --env-delete
fnc-env-register: fnc-env-init
./nb-wrangler sample-specs/fnc-test-spec.yaml --env-register
fnc-env-unregister: fnc-env-init
./nb-wrangler sample-specs/fnc-test-spec.yaml --env-unregister
fnc-env-kernel-cleanup: fnc-env-init
./nb-wrangler sample-specs/fnc-test-spec.yaml --env-kernel-cleanup
fnc-spi-basic-workflow: fnc-inject-spi
echo "--- Running basic SPI workflow test ---"
# Ensure clean state for git operations and remove previous test branches
cd inject-spi-references/science-platform-images && git checkout main && git branch -D test-spi-branch || true
# Run inject-spi with branch, commit, prune, build
./nb-wrangler sample-specs/fnc-test-spec.yaml --inject-spi --repos-dir inject-spi-references --overwrite-local-changes \
--spi-commit-message "Test SPI commit" \
--spi-branch test-spi-branch
echo "--- Verifying basic SPI workflow test results ---"
# Check if branch was created
git -C inject-spi-references/science-platform-images branch | grep "test-spi-branch"
# Check if there are committed changes on that branch
git -C inject-spi-references/science-platform-images log -1 --pretty=format:"%s" test-spi-branch | grep "Test SPI commit"
fnc-spec-reset: fnc-packages-compile
./nb-wrangler sample-specs/fnc-test-spec.yaml --spec-reset
git checkout -- sample-specs/fnc-test-spec.yaml
fnc-spec-validate: fnc-packages-compile
./nb-wrangler sample-specs/fnc-test-spec.yaml --spec-validate
git checkout -- sample-specs/fnc-test-spec.yaml
fnc-inject-spi:
rm -rf inject-spi-references
./nb-wrangler sample-specs/fnc-test-spec.yaml --curate --inject-spi --repos-dir inject-spi-references
# ==========================================================================================================
DATA_STEPS = data-collect data-validate data-download data-update data-unpack data-pack \
data-list data-delete data-select
DATA_WORKFLOWS = wrangler-spec-curate data-test-curate data-test-reinstall
DATA_SELECTED = 'pandeia|stpsf|other-spectra_multi_v2_sed'
DATA_CLEANUP = ../../nb-wrangler data-test-spec.yaml --data-delete both --data-select ${DATA_SELECTED}
data-clean:
source ./nb-wrangler environment && \
cd tests/data-functional && \
rm -rf references && \
git checkout -- data-test-spec.yaml
data-functional: data-clean wrangler-spec-curate data-test-workflows
wrangler-spec-curate:
source ./nb-wrangler environment && \
cd tests/data-functional && \
${DATA_CLEANUP} && \
../../nb-wrangler data-test-spec.yaml --spec-reset && \
../../nb-wrangler data-test-spec.yaml --curate
data-test-workflows: data-clean ${DATA_WORKFLOWS}
data-test-curate:
source ./nb-wrangler environment && \
cd tests/data-functional && \
${DATA_CLEANUP} && \
../../nb-wrangler data-test-spec.yaml --data-reset-spec && \
../../nb-wrangler data-test-spec.yaml --data-curate --data-select ${DATA_SELECTED}
data-test-reinstall:
source ./nb-wrangler environment && \
cd tests/data-functional && \
${DATA_CLEANUP} && \
../../nb-wrangler data-test-spec.yaml --data-reinstall --data-select ${DATA_SELECTED} && \
rm -rf references
# data-test-steps: ${DATA_STEPS}
# ==========================================================================================================
clean: clean-build clean-pyc clean-test clean-other ## remove all build, test, coverage and Python artifacts
clean-build: ## remove build artifacts
rm -fr 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 .tox/
rm -fr .pytest_cache nb_wranger/.pytest_cache
rm -fr $$TEST_OUTPUTS
clean-other:
rm -rf prof
rm -f .coverage
rm -fr htmlcov/
rm -rf .mypy_cache
rm -f nb-wrangler.log
rm -rf inject-spi-references
rm -f extra_pip_packages.txt
rm -f common_pip_packages.txt
rm -f common_mamba_packages.txt
rm -f extra_mamba_packages.txt
rm -f tests/data-functional/common_pip_packages.txt
lint/flake8: ## check style with flake8
find ${PROJECT} tests -name '*.py' | xargs flake8 --max-line-length 120 \
--ignore E302,E203,E305,W291,W503,W504,W391,E501,E226 --count --statistics
lint/black: ## check style with black
black --check ${PROJECT} tests
lint/bandit: ## check security with bandit
find ${PROJECT} tests -name '*.py' | xargs bandit -v -ll -ii --format txt
lint/mypy:
mypy --install-types --non-interactive ${PROJECT}
lint/radon-cc:
radon cc -nb --total nb_wrangler
lint/radon-mi:
radon mi -s nb_wrangler
lint/radon-hal:
radon hal nb_wrangler
lint/radon: lint/radon-cc lint/radon-mi
lint: lint/flake8 lint/mypy lint/black lint/bandit lint/radon ## check style, type annotations, whitespace
test-all: setup lint unit-test
test: functional data-functional unit-test
test-bootstrap: test-bootstrap-only test-bootstrap-spec
test-bootstrap-only:
rm -rf $NBW_ROOT
make clean
./nb-wrangler bootstrap
test-bootstrap-spec:
rm -rf $NBW_ROOT
make clean
./nb-wrangler bootstrap ./sample-specs/fnc-test-spec.yaml
unit-test: clean-test ## run tests quickly with the default Python
pytest --pdb --doctest-continue-on-failure -vv --profile tests
coverage: clean-test ## check code coverage quickly with the default Python
coverage run --source nb_wrangler -m pytests tests
coverage report -m
coverate html
$(BROWSER) htmlcov/index.html
dist: clean ## builds source and wheel package
python setup.py sdist
python setup.py bdist_wheel
ls -l dist
install: clean ## install the package to the active Python's site-packages
pip install .