forked from TeamDevDev/debuggingbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
1400 lines (1170 loc) · 45.2 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
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Fuzzingbook/Debuggingbook Makefile
# HINT: This Makefile has hundreds of goals. The most important are:
# * To see the most important goals, do "make help"
# * To build the book HTML (in html/), do "make"
# * To build the book with all components (in docs/), do "make docs"
# This Makefile requires GNU make.
# Get chapter files
CHAPTERS_MAKEFILE = Chapters.makefile
include $(CHAPTERS_MAKEFILE)
# All source notebooks
SOURCE_FILES = \
$(FRONTMATTER) \
$(CHAPTERS) \
$(APPENDICES) \
$(EXTRAS)
# The bibliography file
BIB = fuzzingbook.bib
# The utilities folder
UTILS = bookutils
# The utilities in $(UTILS)
UTILITY_FILES = \
__init__.py \
PrettyTable.py \
README.md \
import_notebooks.py \
set_fixed_seed.py
# Where the notebooks are
NOTEBOOKS = notebooks
# Where the shared files are
SHARED = notebooks/shared/
# Derived versions including HTML, SVG, and text output cells (for Web)
FULL_NOTEBOOKS = full_notebooks
# Derived versions including PNG and text output cells,
# but without excursions (for LaTeX and PDF)
RENDERED_NOTEBOOKS = rendered
# Git repo
GITHUB_REPO = https://github.com/uds-se/$(PROJECT)/
BINDER_URL = https://mybinder.org/v2/gh/uds-se/$(PROJECT)/master?filepath=docs/beta/notebooks/00_Table_of_Contents.ipynb
PROJECT_URL = https://beta.$(PROJECT).org
# Sources in the notebooks folder
SOURCES = $(SOURCE_FILES:%=$(NOTEBOOKS)/%)
CHAPTER_SOURCES = $(CHAPTERS:%=$(NOTEBOOKS)/%)
ALL_CHAPTER_SOURCES = $(CHAPTERS:%=$(NOTEBOOKS)/%)
PUBLIC_SOURCES = $(PUBLIC_CHAPTERS:%=$(NOTEBOOKS)/%)
READY_SOURCES = $(READY_CHAPTERS:%=$(NOTEBOOKS)/%)
TODO_SOURCES = $(TODO_CHAPTERS:%=$(NOTEBOOKS)/%)
NEW_SOURCES = $(NEW_CHAPTERS:%=$(NOTEBOOKS)/%)
APPENDICES_SOURCES = $(APPENDICES:%=$(NOTEBOOKS)/%)
# Where to place the pdf, html, slides
PDF_TARGET = pdf/
NBPDF_TARGET = nbpdf/
HTML_TARGET = html/
SLIDES_TARGET = slides/
CODE_TARGET = code/
MYPY_TARGET = mypy/
MARKDOWN_TARGET = markdown/
WORD_TARGET = word/
EPUB_TARGET = epub/
DEPEND_TARGET = .depend/
DOCS_TARGET = docs/
# If BETA=y, we create files in the "beta" subdir. Use 'make docs-beta', 'make html-beta' to invoke
ifdef BETA
DOCS_TARGET := docs/beta/
HTML_TARGET := beta/$(HTML_TARGET)
SLIDES_TARGET := beta/$(SLIDES_TARGET)
CODE_TARGET := beta/$(CODE_TARGET)
BETA_FLAG = --include-ready --include-todo
endif
ifndef BETA
# Avoid warning: undefined variable `BETA_FLAG'
BETA_FLAG =
endif
# Files to appear in the table of contents
ifndef BETA
CHAPTER_SOURCES := $(PUBLIC_CHAPTERS:%=$(NOTEBOOKS)/%)
endif
ifdef BETA
PUBLIC_CHAPTERS := $(CHAPTERS)
endif
TOC_CHAPTERS := $(PUBLIC_CHAPTERS)
TOC_APPENDICES = $(APPENDICES)
# Files to appear on the Web page
DOCS = \
$(FRONTMATTER:%.ipynb=%) \
$(TOC_CHAPTERS:%.ipynb=%) \
$(APPENDICES:%.ipynb=%) \
$(EXTRAS:%.ipynb=%)
# Various derived files
TEXS = $(SOURCE_FILES:%.ipynb=$(PDF_TARGET)%.tex)
PDFS = $(SOURCE_FILES:%.ipynb=$(PDF_TARGET)%.pdf)
NBPDFS = $(SOURCE_FILES:%.ipynb=$(NBPDF_TARGET)%.pdf)
HTMLS = $(SOURCE_FILES:%.ipynb=$(HTML_TARGET)%.html)
SLIDES = $(SOURCE_FILES:%.ipynb=$(SLIDES_TARGET)%.slides.html)
PYS = $(SOURCE_FILES:%.ipynb=$(CODE_TARGET)%.py) \
$(CODE_TARGET)setup.py \
$(CODE_TARGET)__init__.py
MYPYS = $(SOURCE_FILES:%.ipynb=$(MYPY_TARGET)%.py)
WORDS = $(SOURCE_FILES:%.ipynb=$(WORD_TARGET)%.docx)
MARKDOWNS = $(SOURCE_FILES:%.ipynb=$(MARKDOWN_TARGET)%.md)
EPUBS = $(SOURCE_FILES:%.ipynb=$(EPUB_TARGET)%.epub)
FULLS = $(FULL_NOTEBOOKS)/$(UTILS) \
$(UTILITY_FILES:%=$(FULL_NOTEBOOKS)/$(UTILS)/%) \
$(SOURCE_FILES:%.ipynb=$(FULL_NOTEBOOKS)/%.ipynb)
RENDERS = $(SOURCE_FILES:%.ipynb=$(RENDERED_NOTEBOOKS)/%.ipynb)
DEPENDS = $(SOURCE_FILES:%.ipynb=$(DEPEND_TARGET)%.makefile)
CHAPTER_PYS = $(CHAPTERS:%.ipynb=$(CODE_TARGET)%.py)
PDF_FILES = $(SOURCE_FILES:%.ipynb=$(PDF_TARGET)%_files)
NBPDF_FILES = $(SOURCE_FILES:%.ipynb=$(NBPDF_TARGET)%_files)
HTML_FILES = $(SOURCE_FILES:%.ipynb=$(HTML_TARGET)%_files)
SLIDES_FILES = $(SOURCE_FILES:%.ipynb=$(SLIDES_TARGET)%_files)
SITEMAP_SVG = $(NOTEBOOKS)/PICS/Sitemap.svg
# Configuration
# The site
SITE = https://www.$(PROJECT).org
# What we use for production: nbpublish (preferred), bookbook, or nbconvert
PUBLISH ?= nbpublish
# What we use for LaTeX: latexmk (preferred), or pdflatex
LATEX ?= latexmk
## Tools
# Python
PYTHON ?= python3
# Python warning level
# Turn warnings into errors unless we're in C
ifeq ($(origin CI),environment)
PYTHON_WARNLEVEL =
else
PYTHON_WARNLEVEL = -W error
endif
# Jupyter
JUPYTER ?= jupyter
# The nbpublish tool (preferred; https://github.com/chrisjsewell/ipypublish)
# (see nbpublish -h for details)
NBPUBLISH ?= \
PYTHONPATH=$(SHARED) $(PYTHON) $(SHARED)bin/nbpublish
NBPUBLISH_OPTIONS ?= -log warning
# The bookbook tool (okay for chapters and books; but no citations yet)
# https://github.com/takluyver/bookbook
BOOKBOOK_LATEX ?= $(PYTHON) -m bookbook.latex
BOOKBOOK_HTML ?= $(PYTHON) -m bookbook.html
# The nbconvert alternative (okay for chapters; doesn't work for book; no citations)
NBCONVERT ?= $(JUPYTER) nbconvert
NBCONVERT_OPTIONS ?= --log-level=WARN
# Notebook merger
NBMERGE = $(PYTHON) utils/nbmerge.py
# LaTeX
PDFLATEX ?= pdflatex
XELATEX ?= xelatex
BIBTEX ?= bibtex
LATEXMK ?= latexmk
LATEXMK_OPTS ?= -xelatex -quiet -f -interaction=nonstopmode
# Word
PANDOC ?= pandoc
# Markdown (see https://github.com/aaren/notedown)
NOTEDOWN ?= notedown
# Style checks
PYCODESTYLE ?= pycodestyle
PYCODESTYLE_CFG = code/pycodestyle.cfg
AUTOPEP8 ?= autopep8
AUTOPEP8_CFG = code/autopep8.cfg
AUTOPEP8_OPTIONS = --global-config $(AUTOPEP8_CFG) --aggressive --in-place
NBAUTOPEP8 = $(PYTHON) utils/nbautopep8.py
# Program to open files after creating, say OPEN=open (default: ignore; "true" does nothing)
OPEN ?= true
# Make directory
MKDIR = mkdir -p
ifndef PUBLISH
# Determine publishing program
OUT := $(shell which $(NBPUBLISH) > /dev/null && echo yes)
ifeq ($(OUT),yes)
# We have nbpublish
PUBLISH = nbpublish
else
# Issue a warning message
OUT := $(shell $(NBPUBLISH) -h > /dev/null)
# We have nbconvert
PUBLISH = nbconvert
PUBLISH_PLUGINS =
endif
endif
ifndef LATEX
# Determine publishing program
OUT := $(shell which $(LATEXMK) > /dev/null && echo yes)
ifeq ($(OUT),yes)
# We have latexmk
LATEX = $(LATEXMK)
else
# Issue a warning message
OUT := $(shell $(LATEXMK) -h > /dev/null)
# We have pdflatex
LATEX = $(PDFLATEX)
endif
endif
# Book base name
BOOK = $(PROJECT)
ifeq ($(PUBLISH),bookbook)
# Use bookbook
CONVERT_TO_HTML = $(NBCONVERT) $(NBCONVERT_OPTIONS) --to html --output-dir=$(HTML_TARGET)
CONVERT_TO_TEX = $(NBCONVERT) $(NBCONVERT_OPTIONS) --to latex --template $(PROJECT).tplx --output-dir=$(PDF_TARGET)
BOOK_TEX = $(PDF_TARGET)$(BOOK).tex
BOOK_PDF = $(PDF_TARGET)$(BOOK).pdf
BOOK_HTML = $(HTML_TARGET)$(BOOK).html
BOOK_HTML_FILES = $(HTML_TARGET)$(BOOK)_files
BOOK_PDF_FILES = $(PDF_TARGET)$(BOOK)_files
PUBLISH_PLUGINS =
else
ifeq ($(PUBLISH),nbpublish)
# Use nbpublish
CONVERT_TO_HTML = $(NBPUBLISH) $(NBPUBLISH_OPTIONS) -f html_ipypublish_chapter --outpath $(HTML_TARGET)
CONVERT_TO_TEX = $(NBPUBLISH) $(NBPUBLISH_OPTIONS) -f latex_ipypublish_chapter --outpath $(PDF_TARGET)
# CONVERT_TO_SLIDES = $(NBPUBLISH) $(NBPUBLISH_OPTIONS) -f slides_ipypublish_all --outpath $(SLIDES_TARGET)
BOOK_TEX = $(PDF_TARGET)$(BOOK).tex
BOOK_PDF = $(PDF_TARGET)$(BOOK).pdf
BOOK_HTML = $(HTML_TARGET)$(BOOK).html
BOOK_HTML_FILES = $(HTML_TARGET)$(BOOK)_files
BOOK_PDF_FILES = $(PDF_TARGET)$(BOOK)_files
PUBLISH_PLUGINS = \
ipypublish_plugins/html_ipypublish_chapter.py \
ipypublish_plugins/latex_ipypublish_book.py \
ipypublish_plugins/latex_ipypublish_chapter.py
else
# Use standard Jupyter tools
CONVERT_TO_HTML = $(NBCONVERT) $(NBCONVERT_OPTIONS) --to html --output-dir=$(HTML_TARGET)
CONVERT_TO_TEX = $(NBCONVERT) $(NBCONVERT_OPTIONS) --to latex --template $(PROJECT).tplx --output-dir=$(PDF_TARGET)
# CONVERT_TO_SLIDES = $(NBCONVERT) $(NBCONVERT_OPTIONS) --to slides --output-dir=$(SLIDES_TARGET)
BOOK_TEX =
BOOK_PDF =
BOOK_HTML =
BOOK_HTML_FILES =
BOOK_PDF_FILES =
PUBLISH_PLUGINS =
endif
endif
# For Python, we use our own script that takes care of distinguishing
# main (script) code from definitions to be imported
CONVERT_TO_PYTHON = PYTHONPATH=notebooks:$$PYTHONPATH \
$(PYTHON) $(EXPORT_NOTEBOOK_CODE)
# This would be the Jupyter alternative
# CONVERT_TO_PYTHON = $(NBCONVERT) $(NBCONVERT_OPTIONS) --to python --output-dir=$(CODE_TARGET)
# For slides, we use the standard Jupyter tools
# Main reason: Jupyter has a neat interface to control slides/sub-slides/etc
CONVERT_TO_SLIDES = $(NBCONVERT) $(NBCONVERT_OPTIONS) --to slides --output-dir=$(SLIDES_TARGET)
REVEAL_JS = $(SLIDES_TARGET)reveal.js
# For Word .docx files, we start from the HTML version
CONVERT_TO_WORD = $(PANDOC)
# For Markdown .md files, we use markdown
# Note: adding --run re-executes all code
# CONVERT_TO_MARKDOWN = $(NOTEDOWN) --to markdown
CONVERT_TO_MARKDOWN = $(NBCONVERT) $(NBCONVERT_OPTIONS) --to markdown --output-dir=$(MARKDOWN_TARGET)
# Run
# fuzzingbook/WhenToStopFuzzing needs about 120 seconds to render
# debuggingbook/Tracing may need up to 10 minutes
EXECUTE_TIMEOUT ?= 140
EXECUTE_OPTIONS ?= --ExecutePreprocessor.timeout=$(EXECUTE_TIMEOUT)
EXECUTE_NOTEBOOK = $(TIME) $(NBCONVERT) $(NBCONVERT_OPTIONS) $(EXECUTE_OPTIONS) --to notebook --execute --output-dir=$(FULL_NOTEBOOKS)
# Render
RENDER_NOTEBOOK = RENDER_HTML=1 $(NBCONVERT) $(NBCONVERT_OPTIONS) $(EXECUTE_OPTIONS) --to notebook --execute --output-dir=$(RENDERED_NOTEBOOKS)
# Zip
ZIP ?= zip
ZIP_OPTIONS = -r
# Short targets
# Default target is to build everything needed for publishing,
# such that we can run "make -k" in a loop
.PHONY: chapters web default
web default: setup html code test-types test-code test-imports test-packages slides
chapters: html
# The book is recreated after any change to any source
.PHONY: book all and more
book $(PROJECT): book-html book-pdf
all: chapters pdf code slides book
and more: word markdown epub
# Individual targets
.PHONY: html pdf python code slides word doc docx md markdown epub
.PHONY: full-notebooks check-notebooks full fulls rendered-notebooks rendered renders book-pdf book-html
html: ipypublish-chapters $(HTMLS)
pdf: ipypublish-chapters $(PDFS)
nbpdf: ipypublish-chapters $(NBPDFS)
python code: $(PYS)
slides: $(SLIDES)
word doc docx: $(WORDS)
md markdown: $(MARKDOWNS)
epub: $(EPUBS)
full-notebooks check-notebooks full fulls: $(FULLS)
rendered-notebooks rendered renders: $(RENDERS)
book-pdf $(PROJECT)-pdf: ipypublish-book $(BOOK_PDF)
book-html $(PROJECT)-html: ipypublish-book $(BOOK_HTML)
.PHONY: ipypublish-book ipypublish-chapters
ifeq ($(PUBLISH),bookbook)
ipypublish-book:
ipypublish-chapters:
else
ifeq ($(PUBLISH),nbpublish)
ipypublish-book:
ipypublish-chapters:
else
ipypublish-book:
@echo "To create the book, you need the 'nbpublish' program."
@echo "This is part of the 'ipypublish' package"
@echo "at https://github.com/chrisjsewell/ipypublish"
ipypublish-chapters:
@echo "Warning: Using '$(NBCONVERT)' instead of '$(NBPUBLISH)'"
@echo "Documents will be created without citations and references"
@echo "Install the 'ipypublish' package"
@echo "from https://github.com/chrisjsewell/ipypublish"
endif
endif
.PHONY: edit jupyter lab notebook
# Invoke notebook and editor: `make jupyter lab`
edit notebook:
$(JUPYTER) notebook
lab:
$(JUPYTER) lab
jupyter:
# Help
.PHONY: help
help:
@echo "Welcome to the '$(PROJECT)' Makefile!"
@echo ""
@echo "* make chapters (default) -> HTML and code for all chapters (notebooks)"
@echo "* make (pdf|html|code|slides|word|markdown) -> given subcategory only"
@echo "* make book -> entire book in PDF and HTML"
@echo "* make all -> all inputs in all output formats"
@echo "* make reformat -> reformat notebook Python code according to PEP8 guidelines"
@echo "* make style -> style checker"
@echo "* make crossref -> cross reference checker"
@echo "* make stats -> report statistics"
@echo "* make clean -> delete all derived files"
@echo ""
@echo "Created files end here:"
@echo "* PDFs -> '$(PDF_TARGET)', HTML -> '$(HTML_TARGET)', Python code -> '$(CODE_TARGET)', Slides -> '$(SLIDES_TARGET)'"
@echo "* Web site files -> '$(DOCS_TARGET)'"
@echo ""
@echo "Publish:"
@echo "* make docs -> Create public version of current documents"
@echo "* make beta -> Create beta version of current documents"
@echo "* make publish-all -> Add docs to git, preparing for publication"
@echo ""
@echo "Settings:"
@echo "* Use make PUBLISH=(nbconvert|nbpublish|bookbook) to choose a converter"
@echo " (default: automatic)"
# Setup repo
.PHONY: setup
setup: .gitignore
.gitignore: shared/gitignore
$(RM) $@
cp $< $@
# Run a notebook, (re)creating all output cells
ADD_METADATA = $(SHARED)utils/add_metadata.py
NBAUTOSLIDE = $(SHARED)utils/nbautoslide.py
NBSYNOPSIS = $(SHARED)utils/nbsynopsis.py
NBSHORTEN = $(SHARED)utils/nbshorten.py
EXPORT_NOTEBOOK_CODE = $(SHARED)utils/export_notebook_code.py
# Commit new synopsis pics after a change (not during CI)
ifeq ($(origin CI),environment)
COMMIT_SYNOPSIS =
else
# COMMIT_SYNOPSIS = -git commit -m "Update synopsis" $(NOTEBOOKS)/PICS/*synopsis*
COMMIT_SYNOPSIS =
endif
# These notebooks can't be run under CI, as they interact with Firefox
# So we simply copy them instead
ifeq ($(origin CI),environment)
$(FULL_NOTEBOOKS)/Tracking.ipynb: $(NOTEBOOKS)/Tracking.ipynb
cp -r $< $@
$(FULL_NOTEBOOKS)/GUIFuzzer.ipynb: $(NOTEBOOKS)/GUIFuzzer.ipynb
cp -r $< $@
$(FULL_NOTEBOOKS)/FuzzingInTheLarge.ipynb: $(NOTEBOOKS)/FuzzingInTheLarge.ipynb
cp -r $< $@
endif
$(FULL_NOTEBOOKS)/%.ipynb: $(NOTEBOOKS)/%.ipynb $(DEPEND_TARGET)%.makefile $(ADD_METADATA) $(NBAUTOSLIDE) $(NBSYNOPSIS)
$(EXECUTE_NOTEBOOK) $< || $(EXECUTE_NOTEBOOK) $<
$(PYTHON) $(ADD_METADATA) --project $(PROJECT) $@ > $@~ && mv $@~ $@
$(PYTHON) $(NBAUTOSLIDE) --in-place $@
$(PYTHON) $(NBSYNOPSIS) --project $(PROJECT) --update $@
$(COMMIT_SYNOPSIS)
$(RENDERED_NOTEBOOKS)/%.ipynb: $(NOTEBOOKS)/%.ipynb \
$(DEPEND_TARGET)%.makefile $(ADD_METADATA) $(NBAUTOSLIDE) \
$(NBSYNOPSIS) $(NBSHORTEN) $(SHARED)$(UTILS)/__init__.py
$(RENDER_NOTEBOOK) $< || $(RENDER_NOTEBOOK) $<
$(PYTHON) $(ADD_METADATA) --project $(PROJECT) $@ > $@~ && mv $@~ $@
$(PYTHON) $(NBAUTOSLIDE) --in-place $@
RENDER_HTML=1 $(PYTHON) $(NBSYNOPSIS) --project $(PROJECT) --update $@
$(COMMIT_SYNOPSIS)
$(PYTHON) $(NBSHORTEN) --link-to "$(SITE)/html/" --in-place $@
$(FULL_NOTEBOOKS)/$(UTILS):
$(MKDIR) $(FULL_NOTEBOOKS)/$(UTILS)
$(FULL_NOTEBOOKS)/$(UTILS)/%: $(SHARED)$(UTILS)/%
@test -d $(FULL_NOTEBOOKS)/$(UTILS) || \
$(MKDIR) $(FULL_NOTEBOOKS)/$(UTILS)
cp -r $< $@
# Conversion rules - chapters
ifeq ($(LATEX),pdflatex)
# Use PDFLaTeX
$(PDF_TARGET)%.pdf: $(PDF_TARGET)%.tex $(BIB)
@echo Running LaTeX...
@-test -L $(PDF_TARGET)PICS || ln -s ../$(NOTEBOOKS)/PICS $(PDF_TARGET)
cd $(PDF_TARGET) && $(PDFLATEX) $*
-cd $(PDF_TARGET) && $(BIBTEX) $*
cd $(PDF_TARGET) && $(PDFLATEX) $*
cd $(PDF_TARGET) && $(PDFLATEX) $*
@cd $(PDF_TARGET) && $(RM) $*.aux $*.bbl $*.blg $*.log $*.out $*.toc $*.frm $*.lof $*.lot $*.fls
@cd $(PDF_TARGET) && $(RM) -r $*_files
@echo Created $@
@$(OPEN) $@
else
# Use LaTeXMK
$(PDF_TARGET)%.pdf: $(PDF_TARGET)%.tex $(BIB)
@echo Running LaTeXMK...
@-test -L $(PDF_TARGET)PICS || ln -s ../$(NOTEBOOKS)/PICS $(PDF_TARGET)
cd $(PDF_TARGET) && $(LATEXMK) $(LATEXMK_OPTS) $*
@cd $(PDF_TARGET) && $(RM) $*.aux $*.bbl $*.blg $*.log $*.out $*.toc $*.frm $*.lof $*.lot $*.fls $*.fdb_latexmk $*.xdv
@echo Created $@
@$(OPEN) $@
endif
# Keep the .tex files
.PRECIOUS: $(PDF_TARGET)%.tex
POST_TEX = utils/post_tex
$(PDF_TARGET)%.tex: $(RENDERED_NOTEBOOKS)/%.ipynb $(BIB) $(PUBLISH_PLUGINS) $(SHARED)$(ADD_METADATA) $(SHARED)$(POST_TEX)
$(eval TMPDIR := $(shell mktemp -d))
$(PYTHON) $(ADD_METADATA) --project $(PROJECT) --titlepage $< > $(TMPDIR)/$(notdir $<)
cp -r $(NOTEBOOKS)/PICS $(BIB) $(TMPDIR)
$(CONVERT_TO_TEX) $(TMPDIR)/$(notdir $<)
$(POST_TEX) $@ > $@~ && mv $@~ $@
@-$(RM) -fr $(TMPDIR)
@cd $(PDF_TARGET) && $(RM) $*.nbpub.log
# The psot-html.py script
POST_HTML ?= $(SHARED)utils/post_html.py
# Its options
POST_HTML_OPTIONS = $(BETA_FLAG) \
--project="$(PROJECT)" \
--title="$(BOOKTITLE)" \
--authors="$(AUTHORS)" \
--twitter="$(TWITTER)" \
--all-chapters="$(ALL_CHAPTER_SOURCES) $(APPENDICES_SOURCES)" \
--public-chapters="$(CHAPTER_SOURCES) $(APPENDICES_SOURCES)" \
--ready-chapters="$(READY_SOURCES)" \
--todo-chapters="$(TODO_SOURCES)" \
--new-chapters="$(NEW_SOURCES)"
HTML_DEPS = $(BIB) $(PUBLISH_PLUGINS) $(POST_HTML) \
$(CHAPTERS_MAKEFILE) $(BIBCHECK)
# Check bib
BIBER = biber
BIBCHECK = .$(BIB).ascii .$(BIB).python .$(BIB).biber
checkbib check-bib: $(BIBCHECK)
@echo "Check completed; $(BIB) is ok"
check-bib-ascii: .$(BIB).ascii
.$(BIB).ascii: $(BIB)
@echo "Checking $(BIB) for 7-bit ASCII encoding"
@if grep -Hn '[^[:print:]]' fuzzingbook.bib; then false; fi
@touch $@
check-bib-python: .$(BIB).python
.$(BIB).python: $(BIB)
@echo "Checking $(BIB) for Python usage with bibtexparser"
@$(PYTHON) -c 'import bibtexparser; fd = open("$(BIB)"); bibtexparser.load(fd); fd.close()'
@touch $@
check-bib-biber: .$(BIB).biber
.$(BIB).biber: $(BIB)
@echo "Checking $(BIB) for LaTeX usage with Biber"
@if which $(BIBER) > /dev/null; then $(BIBER) --tool --validate-datamodel --quiet $(BIB); else :; fi
@$(RM) fuzzingbook_bibertool.bib fuzzingbook.bib.blg
@touch .$(BIB).biber
.PHONY: checkbib check-bib check-bib-ascii check-bib-python check-bib-biber
# index.html comes with relative links (html/) such that the beta version gets the beta menu
$(DOCS_TARGET)index.html: \
$(FULL_NOTEBOOKS)/index.ipynb $(HTML_DEPS)
@test -d $(DOCS_TARGET) || $(MKDIR) $(DOCS_TARGET)
@test -d $(HTML_TARGET) || $(MKDIR) $(HTML_TARGET)
$(CONVERT_TO_HTML) $<
mv $(HTML_TARGET)index.html $@
@cd $(HTML_TARGET) && $(RM) -r index.nbpub.log index_files
@$(PYTHON) $(POST_HTML) --menu-prefix=html/ --home $(POST_HTML_OPTIONS)$(HOME_POST_HTML_OPTIONS) $@
@$(OPEN) $@
# 404.html comes with absolute links (/html/) such that it works anywhare
# https://help.github.com/articles/creating-a-custom-404-page-for-your-github-pages-site/
$(DOCS_TARGET)404.html: $(FULL_NOTEBOOKS)/404.ipynb $(HTML_DEPS)
@test -d $(DOCS_TARGET) || $(MKDIR) $(DOCS_TARGET)
@test -d $(HTML_TARGET) || $(MKDIR) $(HTML_TARGET)
$(CONVERT_TO_HTML) $<
mv $(HTML_TARGET)404.html $@
@cd $(HTML_TARGET) && $(RM) -r 404.nbpub.log 404_files
@$(PYTHON) $(POST_HTML) --menu-prefix=/html/ --home $(POST_HTML_OPTIONS) $@
(echo '---'; echo 'permalink: /404.html'; echo '---'; cat $@) > $@~ && mv $@~ $@
@$(OPEN) $@
$(DOCS_TARGET)html/00_Index.html: \
$(DOCS_TARGET)notebooks/00_Index.ipynb $(HTML_DEPS)
$(CONVERT_TO_HTML) $<
@cd $(HTML_TARGET) && $(RM) -r 00_Index.nbpub.log 00_Index_files
@cd $(DOCS_TARGET)html && $(RM) -r 00_Index.nbpub.log 00_Index_files
mv $(HTML_TARGET)00_Index.html $@
@$(PYTHON) $(POST_HTML) $(POST_HTML_OPTIONS) $@
$(DOCS_TARGET)html/00_Table_of_Contents.html: \
$(DOCS_TARGET)notebooks/00_Table_of_Contents.ipynb \
$(SITEMAP_SVG) $(HTML_DEPS)
$(CONVERT_TO_HTML) $<
@cd $(HTML_TARGET) && $(RM) -r 00_Table_of_Contents.nbpub.log 00_Table_of_Contents_files
@cd $(DOCS_TARGET)html && $(RM) -r 00_Table_of_Contents.nbpub.log 00_Table_of_Contents_files
mv $(HTML_TARGET)00_Table_of_Contents.html $@
@$(PYTHON) $(POST_HTML) $(POST_HTML_OPTIONS) $@
@$(OPEN) $@
$(HTML_TARGET)%.html: $(FULL_NOTEBOOKS)/%.ipynb $(HTML_DEPS)
@test -d $(HTML_TARGET) || $(MKDIR) $(HTML_TARGET)
$(CONVERT_TO_HTML) $<
@cd $(HTML_TARGET) && $(RM) $*.nbpub.log $*_files/$(BIB)
@$(PYTHON) $(POST_HTML) $(POST_HTML_OPTIONS) $@
@if grep -i '\[unresolved citation' $@; then false; fi
@-test -L $(HTML_TARGET)PICS || ln -s ../$(NOTEBOOKS)/PICS $(HTML_TARGET)
@$(OPEN) $@
$(SLIDES_TARGET)%.slides.html: $(FULL_NOTEBOOKS)/%.ipynb $(BIB) $(NBSHORTEN)
@test -d $(SLIDES_TARGET) || $(MKDIR) $(SLIDES_TARGET)
$(eval TMPDIR := $(shell mktemp -d))
sed 's/\.ipynb)/\.slides\.html)/g' $< > $(TMPDIR)/$(notdir $<)
$(PYTHON) $(NBSHORTEN) --skip-slides --in-place $(TMPDIR)/$(notdir $<)
$(CONVERT_TO_SLIDES) $(TMPDIR)/$(notdir $<)
@cd $(SLIDES_TARGET) && $(RM) $*.nbpub.log $*_files/$(BIB)
@-test -L $(HTML_TARGET)PICS || ln -s ../$(NOTEBOOKS)/PICS $(HTML_TARGET)
@-$(RM) -fr $(TMPDIR)
@$(OPEN) $@
# Rules for beta targets
.FORCE:
ifndef BETA
beta/%: .FORCE
@$(MAKE) BETA=beta $(@:beta/=)
$(DOCS_TARGET)beta/%: .FORCE
@$(MAKE) BETA=beta $(@:beta/=)
%-beta: .FORCE
@$(MAKE) BETA=beta $(@:-beta=)
%-all: % %-beta
@true
.PHONY: beta
beta: default-beta
else:
beta:
endif
# Reconstructing the reveal.js dir
.PHONY: reveal.js
$(REVEAL_JS) reveal.js: .FORCE
@-test -d "$(REVEAL_JS)" || (cd $(SLIDES_TARGET); \
git submodule add https://github.com/hakimel/reveal.js.git)
git submodule update --remote
-git commit -m "Update from source" $(REVEAL_JS)
$(CODE_TARGET)setup.py: $(CODE_TARGET)setup.py.in
cat $< > $@
chmod +x $@
$(CODE_TARGET)__init__.py: $(CODE_TARGET)__init__.py.in $(CHAPTERS_MAKEFILE)
cat $< > $@
(for module in $(IMPORTS); do echo "# from . import $$module"; done) | grep -v '^.*[0-9][0-9]_.*' >> $@
chmod +x $@
# For code, we use our own exporter
# In our CI environment, CI=true is set
ifeq ($(origin CI),environment)
# CI mode: Create code from local notebooks,
# such that we don't have to execute the notebooks
$(CODE_TARGET)%.py: $(NOTEBOOKS)/%.ipynb $(EXPORT_NOTEBOOK_CODE)
@test -d $(CODE_TARGET) || $(MKDIR) $(CODE_TARGET)
$(CONVERT_TO_PYTHON) --project $(PROJECT) $< > $@~ && mv $@~ $@
# $(AUTOPEP8) $(AUTOPEP8_OPTIONS) $@
-chmod +x $@
else
# Normal mode: Create code from full notebooks,
# such that we get the full outputs in the synopsis
$(CODE_TARGET)%.py: $(FULL_NOTEBOOKS)/%.ipynb $(EXPORT_NOTEBOOK_CODE)
@test -d $(CODE_TARGET) || $(MKDIR) $(CODE_TARGET)
$(CONVERT_TO_PYTHON) --project $(PROJECT) $< > $@~ && mv $@~ $@
# $(AUTOPEP8) $(AUTOPEP8_OPTIONS) $@
-chmod +x $@
endif
# mypy stuff always comes directly from notebooks
mypy: $(MYPYS)
$(MYPY_TARGET)%.py: $(NOTEBOOKS)/%.ipynb $(EXPORT_NOTEBOOK_CODE)
@test -d $(MYPY_TARGET) || $(MKDIR) $(MYPY_TARGET)
$(CONVERT_TO_PYTHON) --project $(PROJECT) --mypy $< > $@~ && mv $@~ $@
# Markdown
$(MARKDOWN_TARGET)%.md: $(RENDERED_NOTEBOOKS)/%.ipynb $(BIB)
$(RM) -r $(MARKDOWN_TARGET)$(basename $(notdir $<)).md \
$(MARKDOWN_TARGET)$(basename $(notdir $<))_files
$(CONVERT_TO_MARKDOWN) $<
# For word, we convert from the HTML file
$(WORD_TARGET)%.docx: $(HTML_TARGET)%.html $(WORD_TARGET)pandoc.css
$(PANDOC) --css=$(WORD_TARGET)pandoc.css $< -o $@
# Epub comes from the markdown file
$(EPUB_TARGET)%.epub: $(MARKDOWN_TARGET)%.md
cd $(MARKDOWN_TARGET); $(PANDOC) -o ../$@ ../$<
# NBPDF files - generated from HMTL, with embedded notebooks
# See instructions at https://github.com/betatim/notebook-as-pdf
HTMLTONBPDF = $(SHARED)utils/htmltonbpdf.py
$(NBPDF_TARGET)%.pdf: $(HTML_TARGET)/%.html $(RENDERED_NOTEBOOKS)/%.ipynb $(HTMLTONBPDF) $(HTML_TARGET)custom.css
@test -d $(NBPDF_TARGET) || $(MKDIR) $(NBPDF_TARGET)
$(PYTHON) $(HTMLTONBPDF) --attach --fix-html-links $${PWD}/$(HTML_TARGET)$(basename $(notdir $<)).html $(RENDERED_NOTEBOOKS)/$(basename $(notdir $<)).ipynb $@
sed "s!$(HTML_TARGET)!$(NBPDF_TARGET)!g" $@ > $@~ && mv $@~ $@
# Conversion rules - entire book
# We create a fuzzingbook/ or debuggingbook/ folder
# with the chapters ordered by number,
# and let the fuzzingbook converters run on this
ifeq ($(PUBLISH),nbpublish)
# With nbpublish
$(PDF_TARGET)$(BOOK).tex: $(RENDERS) $(BIB) $(PUBLISH_PLUGINS) $(CHAPTERS_MAKEFILE)
-$(RM) -r $(BOOK)
$(MKDIR) $(BOOK)
chapter=0; \
for file in $(SOURCE_FILES); do \
chnum=$$(printf "%02d" $$chapter); \
ln -s ../$(RENDERED_NOTEBOOKS)/$$file $(BOOK)/$$(echo $$file | sed 's/.*/Ch'$${chnum}'_&/g'); \
chapter=$$(expr $$chapter + 1); \
done
ln -s ../$(BIB) $(BOOK)
$(NBPUBLISH) $(NBPUBLISH_OPTIONS) -f latex_ipypublish_book --outpath $(PDF_TARGET) $(BOOK)
$(POST_TEX) $@ > $@~ && mv $@~ $@
$(RM) -r $(BOOK)
cd $(PDF_TARGET) && $(RM) $(BOOK).nbpub.log
@echo Created $@
$(HTML_TARGET)$(BOOK).html: $(FULLS) $(BIB) $(POST_HTML)
-$(RM) -r $(BOOK)
$(MKDIR) $(BOOK)
chapter=0; \
for file in $(SOURCE_FILES); do \
chnum=$$(printf "%02d" $$chapter); \
ln -s ../$(FULL_NOTEBOOKS)/$$file $(BOOK)/$$(echo $$file | sed 's/.*/Ch'$${chnum}'_&/g'); \
chapter=$$(expr $$chapter + 1); \
done
ln -s ../$(BIB) $(BOOK)
$(CONVERT_TO_HTML) $(BOOK)
$(PYTHON) $(SHARED)utils/nbmerge.py $(BOOK)/Ch*.ipynb > notebooks/$(BOOK).ipynb
@$(PYTHON) $(POST_HTML) $(BETA_FLAG) $(POST_HTML_OPTIONS) $@
$(RM) -r $(BOOK) notebooks/$(BOOK).ipynb
cd $(HTML_TARGET) && $(RM) $(BOOK).nbpub.log $(BOOK)_files/$(BIB)
@echo Created $@
else
# With bookbook
$(PDF_TARGET)$(BOOK).tex: $(RENDERS) $(BIB) $(PUBLISH_PLUGINS) $(CHAPTERS_MAKEFILE)
-$(RM) -r $(BOOK)
$(MKDIR) $(BOOK)
chapter=0; \
for file in $(SOURCE_FILES); do \
chnum=$$(printf "%02d" $$chapter); \
ln -s ../$(RENDERED_NOTEBOOKS)/$$file book/$$(echo $$file | sed 's/.*/'$${chnum}'-&/g'); \
chapter=$$(expr $$chapter + 1); \
done
cd book; $(BOOKBOOK_LATEX)
mv book/combined.tex $@
$(POST_TEX) $@ > $@~ && mv $@~ $@
$(RM) -r book
@echo Created $@
$(HTML_TARGET)book.html: $(FULLS) $(BIB) $(PUBLISH_PLUGINS)
-$(RM) -r book
$(MKDIR) book
for file in $(SOURCE_FILES); do \
ln -s ../$(FULL_NOTEBOOKS)/$$file book/$$(echo $$file | sed 's/[^-0-9]*\([-0-9][0-9]*\)_\(.*\)/\1-\2/g'); \
done
cd book; $(BOOKBOOK_HTML)
mv book/html/index.html $@
mv book/html/*.html $(HTML_TARGET)
$(RM) -r book
@echo Created $@
endif
## Some checks
# Style checks
.PHONY: style check-style checkstyle
style check-style checkstyle: $(PYS) $(PYCODESTYLE_CFG)
$(PYCODESTYLE) --config $(PYCODESTYLE_CFG) $(PYS)
@echo "All style checks passed."
# Automatic formatting
.PHONY: autopep8 reformat
autopep8 reformat: $(PYCODESTYLE_CFG)
$(NBAUTOPEP8) --split-cells --jobs -1 $(AUTOPEP8_OPTIONS) $(SOURCES)
@echo "Code reformatting complete. Use 'make full' to re-execute and test notebooks."
# List of Cross References
.PHONY: check-crossref crossref xref
check-crossref crossref xref: $(SOURCES)
@echo "Referenced notebooks (* = missing)"
@files=$$(grep '\.ipynb)' $(SOURCES) | sed 's/.*[(]\([a-zA-Z0-9_][a-zA-Z0-9_-]*\.ipynb\)[)].*/\1/' | grep -v http | sort | uniq); \
for file in $$files; do \
if [ -f $(NOTEBOOKS)/$$file ]; then \
echo ' ' $$file; \
else \
echo '* ' $$file "- in" $$(cd $(NOTEBOOKS); grep -l $$file $(SOURCE_FILES)); \
fi \
done
# Stats
.PHONY: stats
stats: $(SOURCES)
@cd $(NOTEBOOKS); ../$(SHARED)utils/nbstats.py $(SOURCE_FILES)
# Run all code. This should produce no failures.
PY_SUCCESS_MAGIC = "--- Code check passed ---"
PYS_OUT = $(SOURCE_FILES:%.ipynb=$(CODE_TARGET).%.py.out)
$(CODE_TARGET).%.py.out: $(CODE_TARGET)%.py
@echo Running $<...
@if $(PYTHON) $(PYTHON_WARNLEVEL) $< > $@ 2>&1; then \
echo $(PY_SUCCESS_MAGIC) >> $@; \
exit 0; \
else \
echo Re-running $<...; \
if $(PYTHON) $(PYTHON_WARNLEVEL) $< > $@ 2>&1; then \
echo $(PY_SUCCESS_MAGIC) >> $@; \
exit 0; \
else \
echo "Error while running $<" >> $@; \
tail $@; \
touch -r $< -A -010000 $@ 2> /dev/null || touch -r $< --date='-1 hour' $@; \
exit 1; \
fi; \
fi
# No need to check if these work; they are not run by users anyway
$(CODE_TARGET).Tracking.py.out: $(CODE_TARGET)Tracking.py
@echo Skipping $<...
@echo $(PY_SUCCESS_MAGIC) > $@
.PHONY: test-code
test-code: code $(PYS_OUT)
.PHONY: check-code
check-code: test-code
@files_with_errors=$$(grep --files-without-match -- $(PY_SUCCESS_MAGIC) $(PYS_OUT)); \
if [ -z "$$files_with_errors" ]; then \
echo "All code checks passed."; \
else \
echo "Check these files for errors: $$files_with_errors"; \
exit 1; \
fi
# Import all code. This should produce no output (or error messages).
IMPORTS = $(subst .ipynb,,$(CHAPTERS) $(APPENDICES))
IMPORTS_OUT = $(CODE_TARGET).import_all.py.out
.PHONY: test-import test-imports
test-import test-imports: code $(IMPORTS_OUT)
.PHONY: check-import check-imports
check-import check-imports: test-imports
@echo "All import checks passed."
$(IMPORTS_OUT): $(PYS)
@echo "#!/usr/bin/env $(PYTHON)" > import_all.py
@(for module in $(IMPORTS); do echo import code.$$module; done) | grep -v '^.*[0-9][0-9]_.*' >> import_all.py
$(PYTHON) import_all.py 2>&1 | tee $@
@$(RM) import_all.py
@test ! -s $@
# Same as above, but using Python standard packages only; import should work too
check-standard-imports: code
# PYTHONPATH= $(MAKE) check-imports
PACKAGES_OUT = $(CODE_TARGET).import_packages.py.out
.PHONY: test-packages
test-packages: $(PACKAGES_OUT)
check-package check-packages: test-packages
@echo "Package check passed."
$(PACKAGES_OUT): $(PYS)
@echo "#!/usr/bin/env $(PYTHON)" > import_packages.py
@(for module in $(IMPORTS); do echo import code.$$module; done) | grep -v '^import code.[0-9][0-9]' >> import_packages.py
$(PYTHON) import_packages.py 2>&1 | tee $@
@$(RM) import_packages.py
@test ! -s $@
# Static type checking
MYPY = mypy
# MYPYS = $(SOURCE_FILES:%.ipynb=$(MYPY_TARGET)%.py)
MYPYS_OUT = $(SOURCE_FILES:%.ipynb=$(MYPY_TARGET).%.py.out)
$(MYPY_TARGET).%.py.out: $(MYPY_TARGET)%.py $(MYPY_TARGET)mypy.ini
@echo Type-checking $<...
@if $(MYPY) --config-file $(MYPY_TARGET)mypy.ini $< > $@ 2>&1; then \
echo $(PY_SUCCESS_MAGIC) >> $@; \
exit 0; \
else \
echo "Error type checking $<" >> $@; \
cat $@; \
touch -r $< $@; \
touch -A -010000 $@; \
exit 1; \
fi
UTILS_MYPY_OUT = $(MYPY_TARGET).$(UTILS).py.out
$(UTILS_MYPY_OUT): $(UTILITY_FILES:%=$(SHARED)$(UTILS)/%) $(MYPY_TARGET)mypy.ini
@echo Type-checking $(SHARED)$(UTILS)...
@if $(MYPY) --config-file $(MYPY_TARGET)mypy.ini --follow-imports=skip $(SHARED)$(UTILS) > $@ 2>&1; then \
echo $(PY_SUCCESS_MAGIC) >> $@; \
exit 0; \
else \
echo "Error type checking $<" >> $@; \
cat $@; \
touch -r $< $@; \
touch -A -010000 $@; \
exit 1; \
fi
test-types: $(SOURCE_FILES:%.ipynb=$(MYPY_TARGET)%.py) \
$(UTILS_MYPY_OUT) $(MYPYS_OUT)
check-types: test-types
@files_with_errors=$$(grep --files-without-match -- $(PY_SUCCESS_MAGIC) $(MYPYS_OUT) $(UTILS_MYPY_OUT)); \
if [ -z "$$files_with_errors" ]; then \
echo "All type checks passed."; \
else \
echo "Check these files for errors: $$files_with_errors"; \
exit 1; \
fi
.PHONY: run
run: check-types check-imports check-standard-imports check-package check-code
# Todo checks
check-todo todo:
@grep '\\todo' $(ALL_CHAPTER_SOURCES); \
if [ $$? = 0 ]; then exit 1; else \
echo "No todos in $(PUBLIC_CHAPTERS:%.ipynb=%) $(READY_CHAPTERS:%.ipynb=%)"; exit 0; fi
# Spell checks
NBSPELLCHECK = $(SHARED)utils/nbspellcheck.py
.PHONY: spell spellcheck check-spell
spell spellcheck check-spell:
$(NBSPELLCHECK) $(SOURCES)
# All checks
.PHONY: check check-all
check check-all: check-import check-package check-types check-code check-style check-crossref check-todo
# Add notebook metadata (add table of contents, bib reference, etc.)
.PHONY: metadata
metadata: $(ADD_METADATA)
@for notebook in $(SOURCES); do \
echo "Adding metadata to $$notebook...\c"; \
$(PYTHON) $(ADD_METADATA) --project $(PROJECT) $$notebook > $$notebook~ || exit 1; \
if diff $$notebook $$notebook~; then \
echo "unchanged."; \
else \
mv $$notebook~ $$notebook; \
echo "done."; \
fi; \
$(RM) $$notebook~; \
done
## Publishing
.PHONY: docs
docs: publish-notebooks publish-index publish-html publish-code publish-dist \
publish-slides publish-pics \
$(DOCS_TARGET)index.html $(DOCS_TARGET)404.html README.md binder/postBuild
@echo "Now use 'make publish-all' to commit changes to docs."
# github does not like script and iframe tags;
# links to notebooks need to get adapted
README.md: $(MARKDOWN_TARGET)index.md Makefile BADGES.md
sed 's!<script.*</script>!!g' $< | \
sed '/<iframe.*/,/.*<\/iframe>/d' | \
sed 's!(\([_a-zA-Z0-9]*\).ipynb)!($(SITE)/html/\1.html)!g'> $@~
cat BADGES.md $@~ > $@
$(RM) $@~
.PHONY: publish
publish: run quick-publish
quick-publish: docs
git add $(DOCS_TARGET)* binder/postBuild README.md \
$(NOTEBOOKS)/PICS/*-synopsis-*
-git status
-git commit -m "Doc update"
@echo "Now use 'make push' to place docs on website and trigger a mybinder update"
# Add/update HTML code in Web pages
.PHONY: publish-html publish-html-setup
publish-html: html publish-html-setup \
$(DOCS_TARGET)html/00_Index.html \
$(DOCS_TARGET)html/00_Table_of_Contents.html \
$(DOCS_TARGET)html/custom.css \
$(DOCS_TARGET)html/favicon \
$(DOCS:%=$(DOCS_TARGET)html/%.html) \
$(DOCS:%=$(DOCS_TARGET)html/%_files)