Commit 95aac1aa authored by Matthieu Boileau's avatar Matthieu Boileau
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+11 −0
Original line number Diff line number Diff line
*.swp
.DS_Store
.ipynb_checkpoints
*.pyc
__pycache__/
.idea/
.vscode/
venv/
build/
notebooks/
 No newline at end of file

.gitlab-ci.yml

0 → 100644
+23 −0
Original line number Diff line number Diff line
variables:
    GIT_SUBMODULE_STRATEGY: recursive

pages:
  variables:
    COURSE_GITLAB_URL: $CI_PROJECT_URL
  tags:
    - docker
    - pages
  only:
    variables:
      - $CI_COMMIT_REF_NAME == $CI_PROJECT_NAMESPACE
      - $CI_COMMIT_REF_NAME == /^pub-.*$/
  image: boileaum/jupyter
  script:
    - make clean
    - make install
    - make -j 7 VARIABLES=$CI_PROJECT_NAMESPACE.yml
    - make archive
    - mv build public
  artifacts:
    paths:
      - public

.gitmodules

0 → 100644
+3 −0
Original line number Diff line number Diff line
[submodule "reveal.js"]
	path = reveal.js
	url = https://github.com/hakimel/reveal.js.git

LICENSE

0 → 100644
+7 −0
Original line number Diff line number Diff line
Copyright <YEAR> <COPYRIGHT HOLDER>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

0 → 100755
+95 −0
Original line number Diff line number Diff line
course_title := cours-python
notebook_dir := notebooks
notebooks := $(wildcard $(notebook_dir)/*.ipynb)
output_dir := build
theme_dir := theme/default
makefile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
project_dir := $(dir $(makefile_path))
template_dir :=  $(project_dir)/$(theme_dir)/templates/

local_reveal := False
ifeq ($(local_reveal),True)
# Useful for running in local with internet connexion
  revealprefix := "reveal.js"
else
# Needed for online publication by gitlab pages
  revealprefix := "https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.3.0"
endif

executed_notebooks := $(addprefix $(output_dir)/, $(notdir $(notebooks)))
html := $(addprefix $(output_dir)/, $(notdir $(subst .ipynb,.html,$(notebooks))))
slides := $(addprefix $(output_dir)/, $(notdir $(subst .ipynb,.slides.html,$(notebooks))))
archives := $(addprefix $(output_dir)/, $(subst .ipynb,.zip,$(notdir $(notebooks))))
pages_md := $(wildcard pages/*.md)
pages :=  $(output_dir)/index.html\
		  $(addprefix $(output_dir)/, $(notdir $(subst .md,.html,$(pages_md))))

.PHONY: all clean html slides executed_notebooks pages copy_to_build pdf archives archive install

all: $(output_dir) html slides pages archives pdf

help:
	@echo "Please use \`make <target>' where <target> is one of"
	@echo "  html      to make standalone HTML files"
	@echo "  slides    to make slideshows (use local_reveal=True \
to run them without internet connection)"
	@echo "  pdf       to compile all notebooks as a single PDF book"
	@echo "  archives  to make ##-notebook.zip files"
	@echo "  archive   to make course_title.zip file"
	@echo "  pages     to make index and other pages"
	@echo "Use \`make' to run all these targets"

install:
	pip install -U --user -r requirements.txt

executed_notebooks: copy_to_build $(executed_notebooks)
html: copy_to_build $(html)
slides: copy_reveal $(slides)
pages: copy_to_build $(pages)
pdf: copy_to_build $(output_dir)/$(course_title).pdf
archives: $(output_dir) $(archives)
archive: $(output_dir)/$(course_title).zip

define nbconvert
	jupyter nbconvert --to $(1) $< --output-dir=$(output_dir)
endef

$(output_dir):
	@mkdir -p $(output_dir)

copy_to_build: $(output_dir)
	rsync -ra --delete $(notebook_dir)/fig $(output_dir)/ --exclude ".*/" --exclude "__pycache__"
	rsync -ra --delete $(notebook_dir)/exos $(output_dir)/ --exclude ".*/" --exclude "__pycache__"
	rsync -ra --delete $(theme_dir)/css $(output_dir)/
	rsync -ra --delete $(theme_dir)/img $(output_dir)/

copy_reveal: $(output_dir)
	rsync -ra --delete reveal.js $(output_dir)/

$(executed_notebooks):  $(output_dir)/%.ipynb: $(notebook_dir)/%.ipynb
	$(call nbconvert,notebook,$<) --execute --allow-errors --ExecutePreprocessor.timeout=60

CONFIG?=nbcourse.yml
$(pages): $(pages_md) $(wildcard $(theme_dir)/img/*) $(wildcard $(theme_dir)/css/*) $(wildcard $(theme_dir)/templates/*) $(CONFIG)
	cd $(output_dir) && python3 $(project_dir)/nbcourse.py --config $(CONFIG)

$(output_dir)/%.html: $(output_dir)/%.ipynb
	$(call nbconvert,html,$<)

$(output_dir)/%.slides.html: $(output_dir)/%.ipynb
	$(call nbconvert,slides,$<) --reveal-prefix $(revealprefix)

$(output_dir)/$(course_title).tex: executed_notebooks $(template_dir)/book.tplx
	cd $(output_dir) && python3 -m bookbook.latex --output-file $(course_title) --template $(template_dir)/book.tplx

$(output_dir)/$(course_title).pdf: $(executed_notebooks) $(template_dir)/book.tplx
	cd $(output_dir) && python3 -m bookbook.latex --pdf --output-file $(course_title) --template $(template_dir)/book.tplx

$(output_dir)/%.zip: $(notebook_dir)/%.ipynb
	zip -r $@ $< $(notebook_dir)/fig $(notebook_dir)/exos --exclude "*/\.*" "*__pycache__*"

$(output_dir)/$(course_title).zip: all
	  cd $(output_dir) && zip -r $(course_title).zip * --exclude "*/\.*" "*__pycache__*" "*.e" "*.zip"

clean:
	rm -rf $(output_dir)