Skip to content

Commit

Permalink
Merge pull request #229 from UCL/jupyter-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dpshelio authored Sep 27, 2023
2 parents b9a8bb9 + 49fd09d commit 14fa606
Show file tree
Hide file tree
Showing 163 changed files with 20,326 additions and 248,460 deletions.
23 changes: 22 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,32 @@ workflow/
vendor/
.sconsign.dblite
html/index.html
pdf
*pdf
*.pyc
*.ipynb
*.nbconvert.ipynb
*.swp
*.html
*.mp4
a.out
ch00*/learning_git
ch00*/somefile.md
ch01*/fourteen.py
ch01*/draw*
ch02*/my*
ch02*/maze*
ch02*/*csv
ch02*/*png
ch02*/greengraph
ch03*/DiffusionExample
ch03*/commands
ch03*/diffusion
ch03*/saskatchewan
ch03*/solutions*
ch04*/greetings*
ch04*/maze*
ch08*/*png
ch98*/*png
html/reveal/.DS_Store
html/reveal/assets/night-ucl-overlay.css
html/reveal/assets/solarized-ucl-overlay.css
Expand Down
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ ROOT=""
PANDOCARGS=-t revealjs -s -V theme=night --css=http://lab.hakim.se/reveal-js/css/theme/night.css \
--css=$(ROOT)/css/ucl_reveal.css --css=$(ROOT)/site-styles/reveal.css \
--default-image-extension=png --highlight-style=zenburn --mathjax -V revealjs-url=http://lab.hakim.se/reveal-js

PRENOTEBOOKS=$(wildcard ch*/*.ipynb.py)
NOTEBOOKS_DONE=$(PRENOTEBOOKS:.ipynb.py=.ipynb)
NOTEBOOKS=$(filter-out %.v2.ipynb %.nbconvert.ipynb,$(sort $(wildcard ch*/*.ipynb)))
SVGS=$(wildcard ch*/*.svg)

HTMLS=$(NOTEBOOKS:.ipynb=.html)
HTMLS=$(PRENOTEBOOKS:.ipynb.py=.html)

EXECUTED=$(NOTEBOOKS:.ipynb=.nbconvert.ipynb)
PNGS=$(SVGS:.svg=.png)
Expand Down Expand Up @@ -41,6 +42,9 @@ default: _site
%.v2.ipynb: %.nbconvert.ipynb
jupyter nbconvert --to notebook --nbformat 2 --stdout $< > $@

%.ipynb: %.ipynb.py
jupytext --to ipynb $< -o - > $@

%.nbconvert.ipynb: %.ipynb
jupyter nbconvert --to notebook --allow-errors --ExecutePreprocessor.timeout=120 --execute --stdout $< > $@

Expand Down Expand Up @@ -72,10 +76,14 @@ _site: ready
preview: ready
jekyll serve --verbose

worked: $(NOTEBOOKS_DONE)
find ./ -iname '*ipynb'

clean:
rm -f ch*/generated/*.png
rm -rf ch*/*.html
rm -f ch*/*.pyc
rm -f ch*/*.ipynb
rm -f index.html
rm -rf _site
rm -rf images js css _includes _layouts favicon* master.zip indigo-jekyll-master
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ You are required to bring your own laptop to the course as the classrooms we are

# Contributing to this repository

This repository contains the course notes as jupyter notebooks. This makes it a bit difficult to contribute and to review contributions. Please, only include changes in the cells modified and not other metadata that changes when running them.
This repository contains the course notes as Jupyter notebooks converted into `py:percent` format. This allows to edit the files as plain text as well as jupyter notebooks. To edit them as jupyter notebooks you'll need to have installed jupytext and open the `ipynb.py` files as notebooks via right-click and select "open with" and "notebook" on the Jupyter file browser.

⚠ Do not run `make` locally on your computer! ⚠

Expand Down Expand Up @@ -78,3 +78,16 @@ $ docker run --rm --volume="$PWD:/srv/jekyll" --volume="$PWD/vendor/bundle:/usr/

and open http://localhost:4000/rsd-engineeringcourse (or the link provided).
Note that this is mounting the `bundle` directory where `act` will create them.

# Migration from jupyter notebooks to py:percent

Using `jupytext` we've converted all the jupyter notebooks into plain text python files (py:percent) with:

```bash
# First cleaned all outputs and commited it
nbstripout --extra-keys metadata.kernelspec ch*/*ipynb
# convert them
find ./ -iname '*ipynb' -exec jupytext --opt notebook_metadata_filter="kernelspec,jupytext,jekyll" --to py:percent {} -o {}.py \;
# then deleted the ipynb
find ./ -iname '*ipynb' -delete
```
Loading

0 comments on commit 14fa606

Please sign in to comment.