-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathMakefile
More file actions
240 lines (207 loc) · 7.19 KB
/
Makefile
File metadata and controls
240 lines (207 loc) · 7.19 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
PACKAGE := miepython
GITHUB_USER := scottprahl
PY_VERSION ?= 3.14
VENV ?= .venv
UV ?= uv
RUN := $(UV) run --extra dev
RUN_DOCS := $(UV) run --extra docs
RUN_LITE := $(UV) run --extra lite
RM ?= rm -f
RMR ?= rm -rf
DOCS_DIR := docs
HTML_DIR := $(DOCS_DIR)/_build/html
OUT_ROOT := _site
OUT_DIR := $(OUT_ROOT)/$(PACKAGE)
STAGE_DIR := .lite_src
DOIT_DB := .jupyterlite.doit.db
LITE_CONFIG := $(PACKAGE)/jupyter_lite_config.json
# --- GitHub Pages deploy config ---
PAGES_BRANCH := gh-pages
WORKTREE := .gh-pages
REMOTE := origin
# --- server config (override on CLI if needed) ---
HOST := 127.0.0.1
PORT := 8000
PYTEST_OPTS :=
SPHINX_OPTS := -T -E -b html -d $(DOCS_DIR)/_build/doctrees -D language=en
PYLINT_TARGETS := $(PACKAGE)/*.py tests/*.py .github/scripts/update_citation.py
YAML_TARGETS := .github/workflows/citation.yaml .github/workflows/pypi.yaml .github/workflows/test.yaml .readthedocs.yaml
RST_TARGETS := README.rst CHANGELOG.rst $(DOCS_DIR)/changelog.rst $(DOCS_DIR)/index.rst
.PHONY: help
help:
@echo "Build Targets:"
@echo " dist - Build sdist+wheel locally"
@echo " html - Build Sphinx HTML documentation"
@echo " lab - Start jupyterlab"
@echo " speed - Quick test of jit and no-jit speeds"
@echo " readme_images - Regenerate docs/images/*.svg from examples"
@echo " sync - Sync uv environment with dev/docs/lite extras"
@echo ""
@echo "Test Targets:"
@echo " test - Run pytest on python files"
@echo " note-test - Test all notebooks for errors"
@echo ""
@echo "Packaging Targets:"
@echo " rcheck - Distribution release checks"
@echo " manifest-check - Validate MANIFEST"
@echo " pylint-check - Same as lint above"
@echo " pyroma-check - Validate overall packaging"
@echo " black-check - Check formatting with black"
@echo " rst-check - Validate all RST files"
@echo " ruff-check - Lint all .py and .ipynb files"
@echo " yaml-check - Validate YAML files"
@echo ""
@echo "JupyterLite Targets:"
@echo " lite - Build JupyterLite site into $(OUT_DIR)"
@echo " lite-serve - Serve $(OUT_DIR) at http://$(HOST):$(PORT)"
@echo " lite-deploy - Upload to github"
@echo ""
@echo "Clean Targets:"
@echo " clean - Remove build caches and docs output"
@echo " lite-clean - Remove JupyterLite outputs"
@echo " realclean - clean + remove $(VENV)"
.PHONY: venv
venv:
@$(UV) sync --python $(PY_VERSION) --extra dev --extra docs --extra lite
.PHONY: dist
dist:
$(RUN) python -m build
.PHONY: readme_images
readme:
cd docs/images && $(RUN) python make_readme_images.py
.PHONY: test
test:
$(RUN) pytest $(PYTEST_OPTS) tests --ignore=tests/test_all_notebooks.py
.PHONY: note-test
note-test:
$(RUN) pytest --verbose tests/test_all_notebooks.py
.PHONY: html
html:
@mkdir -p "$(HTML_DIR)"
$(RUN_DOCS) sphinx-build $(SPHINX_OPTS) "$(DOCS_DIR)" "$(HTML_DIR)"
@command -v open >/dev/null 2>&1 && open "$(HTML_DIR)/index.html" || true
.PHONY: pylint-check
pylint-check:
@$(RUN) pylint $(PYLINT_TARGETS)
.PHONY: yaml-check
yaml-check:
@$(RUN) yamllint $(YAML_TARGETS)
.PHONY: rst-check
rst-check:
@$(RUN) rstcheck $(RST_TARGETS)
@$(RUN) rstcheck --ignore-directives automodapi $(DOCS_DIR)/$(PACKAGE).rst
.PHONY: ruff-check
ruff-check:
@$(RUN) ruff check
.PHONY: black-check
black-check:
$(RUN) black --check .
.PHONY: manifest-check
manifest-check:
$(RUN) check-manifest
.PHONY: pyroma-check
pyroma-check:
$(RUN) pyroma -d .
.PHONY: rcheck
rcheck:
@echo "Running all release checks..."
@$(MAKE) realclean
@$(MAKE) ruff-check
@$(MAKE) black-check
@$(MAKE) pylint-check
@$(MAKE) rst-check
@$(MAKE) manifest-check
@$(MAKE) pyroma-check
@$(MAKE) html
@$(MAKE) lite
@$(MAKE) dist
@$(MAKE) test
@$(MAKE) note-test
@echo "✅ Release checks complete"
.PHONY: lite
lite: lite-clean $(LITE_CONFIG) dist
@echo "==> Staging notebooks from docs -> $(STAGE_DIR)"
mkdir -p "$(STAGE_DIR)"
cp $(DOCS_DIR)/*.ipynb "$(STAGE_DIR)"
$(RUN) python -m jupyter nbconvert --clear-output --inplace "$(STAGE_DIR)"/*.ipynb
mkdir -p "$(STAGE_DIR)/examples"
cp $(PACKAGE)/examples/*.py "$(STAGE_DIR)/examples"
mkdir -p "$(STAGE_DIR)/data"
cp docs/data/*.npy "$(STAGE_DIR)/data"
cp docs/data/scattnlay_reference_metadata.json "$(STAGE_DIR)/data"
@echo "==> Building JupyterLite"
@$(RUN_LITE) jupyter lite build \
--config="$(LITE_CONFIG)" \
--contents="$(STAGE_DIR)" \
--output-dir="$(OUT_DIR)"
@touch "$(OUT_DIR)/.nojekyll" # for GitHub pages
.PHONY: lite-serve
lite-serve:
@test -d "$(OUT_DIR)" || { echo "❌ run 'make lite' first"; exit 1; }
@echo "Serving at"
@echo " http://$(HOST):$(PORT)/$(PACKAGE)/?disableCache=1"
@echo ""
$(RUN) python -m http.server -d "$(OUT_ROOT)" --bind $(HOST) $(PORT)
.PHONY: lite-deploy
lite-deploy:
@echo "==> Sanity check"
@test -d "$(OUT_DIR)" || { echo "❌ Run 'make lite' first"; exit 1; }
@echo "==> Ensure $(PAGES_BRANCH) branch exists"
@if ! git show-ref --verify --quiet refs/heads/$(PAGES_BRANCH); then \
CURRENT=$$(git branch --show-current); \
git switch --orphan $(PAGES_BRANCH); \
git commit --allow-empty -m "Initialize $(PAGES_BRANCH)"; \
git switch $$CURRENT; \
fi
@echo "==> Setup deployment worktree"
@git worktree remove "$(WORKTREE)" --force 2>/dev/null || true
@git worktree prune || true
@$(RMR) "$(WORKTREE)"
@git worktree add "$(WORKTREE)" "$(PAGES_BRANCH)"
@git -C "$(WORKTREE)" pull "$(REMOTE)" "$(PAGES_BRANCH)" 2>/dev/null || true
@echo "==> Deploy $(OUT_DIR) -> $(WORKTREE)"
@rsync -a --delete --exclude ".git*" "$(OUT_DIR)/" "$(WORKTREE)/"
@touch "$(WORKTREE)/.nojekyll"
@date -u +"%Y-%m-%d %H:%M:%S UTC" > "$(WORKTREE)/.pages-ping"
@echo "==> Commit & push"
@cd "$(WORKTREE)" && \
git add -A && \
if git diff --quiet --cached; then \
echo "✅ No changes to deploy"; \
else \
git commit -m "Deploy $$(date -u +'%Y-%m-%d %H:%M:%S UTC')" && \
git push "$(REMOTE)" "$(PAGES_BRANCH)" && \
echo "✅ Deployed to https://$(GITHUB_USER).github.io/$(PACKAGE)/"; \
fi
.PHONY: lab
lab:
@echo "==> Launching JupyterLab with uv-managed environment"
$(RUN) python -m jupyter lab --ServerApp.root_dir="$(CURDIR)"
.PHONY: speed
speed:
-$(RUN) python tests/test_nojit_speed.py
-$(RUN) python tests/test_jit_speed.py
.PHONY: lite-clean
lite-clean:
@echo "==> Cleaning JupyterLite build artifacts"
@$(RMR) "$(STAGE_DIR)"
@$(RMR) "$(OUT_ROOT)"
@$(RMR) "$(DOIT_DB)"
@$(RMR) .cache dist $(PACKAGE).egg-info
.PHONY: clean
clean: lite-clean
@echo "==> Cleaning build artifacts"
@find . -name '__pycache__' -type d -exec $(RMR) {} +
@find . -name '.DS_Store' -type f -delete
@find . -name '.ipynb_checkpoints' -type d -prune -exec $(RMR) {} +
@find . -name '.pytest_cache' -type d -prune -exec $(RMR) {} +
@$(RMR) .ruff_cache
@$(RMR) docs/api docs/_build docs/.jupyter
.PHONY: realclean
realclean: clean
@echo "==> Deep cleaning: removing venv and deployment worktree"
@git worktree remove "$(WORKTREE)" --force 2>/dev/null || true
@git worktree prune || true
$(RMR) "$(WORKTREE)"
$(RMR) .venv
@$(RM) uv.lock