-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathMakefile
More file actions
288 lines (257 loc) · 13.2 KB
/
Makefile
File metadata and controls
288 lines (257 loc) · 13.2 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
.PHONY: clean clean-gallery clean-prep clean-full spellcheck
SPHINXOPTS =
# Gallery path must be given relative to the docs/ folder
ifeq ($(GALLERY_PATH),)
GALLERY_PATH := ../../napari/examples
endif
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
current_dir := $(dir $(mkfile_path))
docs_dir := $(current_dir)docs
clean:
echo clean
echo $(current_dir)
ifeq ($(OS),Windows_NT)
@python -c "import shutil, pathlib, glob; shutil.rmtree('$(docs_dir)/_build', ignore_errors=True); [pathlib.Path(f).unlink(missing_ok=True) for f in glob.glob('$(docs_dir)/api/napari*.rst')]"
else
rm -rf $(docs_dir)/_build/
rm -rf $(docs_dir)/api/napari*.rst
endif
clean-prep: clean
ifeq ($(OS),Windows_NT)
@python -c "import pathlib, glob; pathlib.Path('$(docs_dir)/guides/preferences.md').unlink(missing_ok=True); [pathlib.Path(f).unlink(missing_ok=True) for f in glob.glob('$(docs_dir)/developers/architecture/ui_sections/*ui.md')]; [pathlib.Path(f).unlink(missing_ok=True) for f in glob.glob('$(docs_dir)/plugins/_npe2*.md')]"
else
rm -rf $(docs_dir)/guides/preferences.md
rm -rf $(docs_dir)/developers/architecture/ui_sections/*ui.md
rm -rf $(docs_dir)/plugins/_npe2*.md
endif
clean-gallery:
ifeq ($(OS),Windows_NT)
@python -c "import shutil, pathlib; [pathlib.Path(f).unlink(missing_ok=True) for f in pathlib.Path('$(docs_dir)/gallery').glob('*') if f.is_file()]; shutil.rmtree('$(docs_dir)/_tags', ignore_errors=True)"
else
rm -rf $(docs_dir)/gallery/*
rm -rf $(docs_dir)/_tags
endif
clean-full: clean-prep clean-gallery
prep-docs:
python $(docs_dir)/_scripts/prep_docs.py
# generate stubs in place of the files from prep_docs
# this will not overwrite existing files
prep-stubs:
python $(docs_dir)/_scripts/prep_docs.py --stubs
docs-build: prep-docs
ifeq ($(OS),Windows_NT)
set NAPARI_CONFIG=&& set NAPARI_APPLICATION_IPY_INTERACTIVE=0&& sphinx-build -M html docs/ docs/_build -WT --keep-going -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) $(SPHINXOPTS)
else
NAPARI_CONFIG="" NAPARI_APPLICATION_IPY_INTERACTIVE=0 sphinx-build -M html docs/ docs/_build -WT --keep-going -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) $(SPHINXOPTS)
endif
# build docs with xvfb (headless X server)
docs-xvfb: prep-docs
ifeq ($(OS),Windows_NT)
@echo "xvfb is not supported on Windows. Use 'make html' or 'make docs-build' instead."
@exit 1
else
NAPARI_CONFIG="" NAPARI_APPLICATION_IPY_INTERACTIVE=0 xvfb-run --auto-servernum sphinx-build -M html docs/ docs/_build -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) $(SPHINXOPTS)
endif
# build docs with xwfb (headless X server with Wayland support)
docs-xwfb: prep-docs
ifeq ($(OS),Windows_NT)
@echo "xwfb is not supported on Windows. Use 'make html' or 'make docs-build' instead."
@exit 1
else
NAPARI_CONFIG="" NAPARI_APPLICATION_IPY_INTERACTIVE=0 xwfb-run -- sphinx-build -M html docs/ docs/_build -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) $(SPHINXOPTS)
endif
# full docs (re)build
# cleans everything, starts from scratch
html: clean clean-gallery docs-build
# no gallery, no clean - call 'make clean' manually if needed
# will use stubs for autogenerated content if needed
# no initial build, so run a manual full or slim build first
# will rebuild notebooks and run cells in edited files
# autogenerated paths need to be ignored to prevent reload loops
html-noplot-live: prep-stubs
ifeq ($(OS),Windows_NT)
set NAPARI_APPLICATION_IPY_INTERACTIVE=0&& sphinx-autobuild -b html docs/ docs/_build/html -D plot_gallery=0 -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) --ignore $(docs_dir)"/_tags/*" --ignore $(docs_dir)"/api/napari*.rst" --ignore $(docs_dir)"/gallery/*" --ignore $(docs_dir)"/jupyter_execute/*" --open-browser --port=0 $(SPHINXOPTS)
else
NAPARI_APPLICATION_IPY_INTERACTIVE=0 \
sphinx-autobuild \
-b html \
docs/ \
docs/_build/html \
-D plot_gallery=0 \
-D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) \
--ignore $(docs_dir)"/_tags/*" \
--ignore $(docs_dir)"/api/napari*.rst" \
--ignore $(docs_dir)"/gallery/*" \
--ignore $(docs_dir)"/jupyter_execute/*" \
--open-browser \
--port=0 \
$(SPHINXOPTS)
endif
# full build, no gallery
# will not remove existing gallery files
html-noplot: clean prep-docs
ifeq ($(OS),Windows_NT)
set NAPARI_APPLICATION_IPY_INTERACTIVE=0&& sphinx-build -M html docs/ docs/_build -WT --keep-going -D plot_gallery=0 -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) $(SPHINXOPTS)
else
NAPARI_APPLICATION_IPY_INTERACTIVE=0 sphinx-build -M html docs/ docs/_build -WT --keep-going -D plot_gallery=0 -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) $(SPHINXOPTS)
endif
# just napari/docs
# no generation from prep_docs scripts, no gallery
# does run notebook cells
# will not remove existing gallery files
docs: clean prep-stubs
ifeq ($(OS),Windows_NT)
set NAPARI_APPLICATION_IPY_INTERACTIVE=0&& sphinx-build -M html docs/ docs/_build -WT --keep-going -D plot_gallery=0 -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) $(SPHINXOPTS)
else
NAPARI_APPLICATION_IPY_INTERACTIVE=0 sphinx-build -M html docs/ docs/_build -WT --keep-going -D plot_gallery=0 -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) $(SPHINXOPTS)
endif
# live variant of `docs`
docs-live: prep-stubs
ifeq ($(OS),Windows_NT)
set NAPARI_APPLICATION_IPY_INTERACTIVE=0&& sphinx-autobuild -M html docs/ docs/_build -D plot_gallery=0 -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) --ignore $(docs_dir)"/_tags/*" --ignore $(docs_dir)"/api/napari*.rst" --ignore $(docs_dir)"/gallery/*" --ignore $(docs_dir)"/jupyter_execute/*" --open-browser --port=0 -j auto $(SPHINXOPTS)
else
NAPARI_APPLICATION_IPY_INTERACTIVE=0 \
sphinx-autobuild -M html docs/ docs/_build -D plot_gallery=0 \
-D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) \
--ignore $(docs_dir)"/_tags/*" \
--ignore $(docs_dir)"/api/napari*.rst" \
--ignore $(docs_dir)"/gallery/*" \
--ignore $(docs_dir)"/jupyter_execute/*" \
--open-browser \
--port=0 \
-j auto $(SPHINXOPTS)
endif
# no notebook execution, no generation from prep_docs, no gallery
# will note remove existing gallery files
slim: clean prep-stubs
ifeq ($(OS),Windows_NT)
set NB_EXECUTION_MODE=off&& set NAPARI_APPLICATION_IPY_INTERACTIVE=0&& sphinx-build -M html docs/ docs/_build -WT --keep-going -D plot_gallery=0 -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) $(SPHINXOPTS)
else
NB_EXECUTION_MODE=off NAPARI_APPLICATION_IPY_INTERACTIVE=0 sphinx-build -M html docs/ docs/_build -WT --keep-going -D plot_gallery=0 -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) $(SPHINXOPTS)
endif
# slim, but uses -j auto to parallelize the build
slimfast: clean prep-stubs
ifeq ($(OS),Windows_NT)
set NB_EXECUTION_MODE=off&& set NAPARI_APPLICATION_IPY_INTERACTIVE=0&& sphinx-build -M html docs/ docs/_build -WT --keep-going -D plot_gallery=0 -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) -j auto $(SPHINXOPTS)
else
NB_EXECUTION_MODE=off NAPARI_APPLICATION_IPY_INTERACTIVE=0 sphinx-build -M html docs/ docs/_build -WT --keep-going -D plot_gallery=0 -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) -j auto $(SPHINXOPTS)
endif
# slimfast, but uses sphinx-autobuild to rebuild changed files
# this will run an initial build, because it's fast
# will not remove existing gallery files
slimfast-live: clean prep-stubs
ifeq ($(OS),Windows_NT)
set NB_EXECUTION_MODE=off&& set NAPARI_APPLICATION_IPY_INTERACTIVE=0&& sphinx-autobuild -M html docs/ docs/_build -D plot_gallery=0 -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) --ignore $(docs_dir)"/_tags/*" --ignore $(docs_dir)"/api/napari*.rst" --ignore $(docs_dir)"/gallery/*" --ignore $(docs_dir)"/jupyter_execute/*" --open-browser --port=0 -j auto $(SPHINXOPTS)
else
NB_EXECUTION_MODE=off NAPARI_APPLICATION_IPY_INTERACTIVE=0 \
sphinx-autobuild -M html docs/ docs/_build -D plot_gallery=0 \
-D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) \
--ignore $(docs_dir)"/_tags/*" \
--ignore $(docs_dir)"/api/napari*.rst" \
--ignore $(docs_dir)"/gallery/*" \
--ignore $(docs_dir)"/jupyter_execute/*" \
--open-browser \
--port=0 \
-j auto $(SPHINXOPTS)
endif
# slim, but with all gallery examples
# does not remove existing gallery files
slimgallery: clean clean-gallery prep-stubs
ifeq ($(OS),Windows_NT)
set NB_EXECUTION_MODE=off&& set NAPARI_APPLICATION_IPY_INTERACTIVE=0&& sphinx-build -M html docs/ docs/_build -WT --keep-going -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) $(SPHINXOPTS)
else
NB_EXECUTION_MODE=off NAPARI_APPLICATION_IPY_INTERACTIVE=0 \
sphinx-build -M html docs/ docs/_build -WT --keep-going \
-D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) \
$(SPHINXOPTS)
endif
# slimgallery, but uses sphinx-autobuild to rebuild any changed examples
# no clean - call 'make clean' and/or `make clean-gallery` manually
# does not remove existing gallery files
# will rebuild whole gallery if it's not present
slimgallery-live: prep-stubs
ifeq ($(OS),Windows_NT)
set NB_EXECUTION_MODE=off&& set NAPARI_APPLICATION_IPY_INTERACTIVE=0&& sphinx-autobuild -M html docs/ docs/_build -T --keep-going -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) --ignore $(docs_dir)"/_tags/*" --ignore $(docs_dir)"/api/napari*.rst" --ignore $(docs_dir)"/gallery/*" --ignore $(docs_dir)"/jupyter_execute/*" --ignore $(docs_dir)/sg_execution_times.rst --watch $(docs_dir)/$(GALLERY_PATH) --open-browser --port=0 $(SPHINXOPTS)
else
NB_EXECUTION_MODE=off NAPARI_APPLICATION_IPY_INTERACTIVE=0 \
sphinx-autobuild -M html docs/ docs/_build -T --keep-going \
-D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) \
--ignore $(docs_dir)"/_tags/*" \
--ignore $(docs_dir)"/api/napari*.rst" \
--ignore $(docs_dir)"/gallery/*" \
--ignore $(docs_dir)"/jupyter_execute/*" \
--ignore $(docs_dir)/sg_execution_times.rst \
--watch $(docs_dir)/$(GALLERY_PATH) \
--open-browser \
--port=0 \
$(SPHINXOPTS)
endif
# slimgallery-live, but only builds a single gallery example
# pass the name of the example without .py
# e.g. slimgallery-live-vortex for vortex.py
# because it's just 1 example, uses -j auto
# Does not require a full gallery build
# Does clean existing files first, to minimize warnings
# Makefile note: this needs to be first, as the matching rule is more specific
slimgallery-live-%:
$(MAKE) build-specific-example-live EXAMPLE_NAME=$*
# slimgallery, but only builds a single gallery example
# pass the name of the example without .py
# e.g. slimgallery-vortex for vortex.py
# because it's just 1 example, uses -j auto
# Does not require a full gallery build first
# Does clean the existing gallery to minimize warnings
slimgallery-%:
$(MAKE) build-specific-example EXAMPLE_NAME=$*
# a target for slimgallery-%
# runs slimgallery with a single example
build-specific-example: clean clean-gallery prep-stubs
ifeq ($(OS),Windows_NT)
set NB_EXECUTION_MODE=off&& set NAPARI_APPLICATION_IPY_INTERACTIVE=0&& sphinx-build -M html docs/ docs/_build -WT --keep-going -D sphinx_gallery_conf.filename_pattern=$(EXAMPLE_NAME)".py" -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) -j auto $(SPHINXOPTS)
else
NB_EXECUTION_MODE=off NAPARI_APPLICATION_IPY_INTERACTIVE=0 \
sphinx-build -M html docs/ docs/_build -WT --keep-going \
-D sphinx_gallery_conf.filename_pattern=$(EXAMPLE_NAME)".py" \
-D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) \
-j auto \
$(SPHINXOPTS)
endif
# a target for slimgallery-live-%
# runs slimgallery-live with a single example
build-specific-example-live: clean clean-gallery prep-stubs
ifeq ($(OS),Windows_NT)
set NB_EXECUTION_MODE=off&& set NAPARI_APPLICATION_IPY_INTERACTIVE=0&& sphinx-autobuild -M html docs/ docs/_build -T --keep-going -D sphinx_gallery_conf.filename_pattern=$(EXAMPLE_NAME)".py" -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) --ignore $(docs_dir)"/_tags/*" --ignore $(docs_dir)"/api/napari*.rst" --ignore $(docs_dir)"/gallery/*" --ignore $(docs_dir)"/jupyter_execute/*" --ignore $(docs_dir)/sg_execution_times.rst --watch $(docs_dir)/$(GALLERY_PATH)/$(EXAMPLE_NAME)".py" --open-browser --port=0 -j auto $(SPHINXOPTS)
else
NB_EXECUTION_MODE=off NAPARI_APPLICATION_IPY_INTERACTIVE=0 \
sphinx-autobuild -M html docs/ docs/_build -T --keep-going \
-D sphinx_gallery_conf.filename_pattern=$(EXAMPLE_NAME)".py" \
-D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) \
--ignore $(docs_dir)"/_tags/*" \
--ignore $(docs_dir)"/api/napari*.rst" \
--ignore $(docs_dir)"/gallery/*" \
--ignore $(docs_dir)"/jupyter_execute/*" \
--ignore $(docs_dir)/sg_execution_times.rst \
--watch $(docs_dir)/$(GALLERY_PATH)/$(EXAMPLE_NAME)".py" \
--open-browser \
--port=0 \
-j auto \
$(SPHINXOPTS)
endif
linkcheck-files: prep-docs
ifeq ($(OS),Windows_NT)
set NAPARI_APPLICATION_IPY_INTERACTIVE=0&& sphinx-build -b linkcheck -D plot_gallery=0 --color docs/ docs/_build/html ${FILES} -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) $(SPHINXOPTS)
else
NAPARI_APPLICATION_IPY_INTERACTIVE=0 sphinx-build -b linkcheck -D plot_gallery=0 --color docs/ docs/_build/html ${FILES} -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) $(SPHINXOPTS)
endif
fallback-videos:
for video in $(basename $(wildcard docs/_static/images/*.webm)); do \
if [ -a $$video.mp4 ]; then \
echo "skipping $$video.mp4"; \
continue; \
fi; \
ffmpeg -i $$video.webm -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -c:v libx264 -preset slow -crf 22 -c:a aac -b:a 128k -strict -2 -y $$video.mp4; \
done
fallback-videos-clean:
rm -f docs/_static/images/*.mp4
spellcheck:
pre-commit run --all-files codespell