TU Cookbook Python Template

Martin Schobben

Project Status

WP Cookbook Development

  • Phase 1: Developer = Teacher β†’ Student
    • Demonstrator (Early 2026)
    • Focus on infrastructure and development
  • Phase 2: Developer β†’ Teacher β†’ Student
    • Focus on easy content creation

Teaching by example

  • Good and working code
    • Clear and well-designed
    • (Reviewed) open source software (pyopensci)
  • Best scientific practices
    • FAIR data
    • citing & attribution
    • …

Phase 1: Developers

  1. Code clarity
  2. Code quality
  3. Dependencies
  4. Code testing
  5. Attribution
  1. Citing
  2. Reviewing
  3. Packaging
  4. Publication

1. Code clarity

  • Notebook is the documentation
    • with 3:1 ratio prose vs code (Wagemann et al., 2022)
  • Abstraction of superfluous code as custom package
  • Type hinting and """docstrings""" for custom functions

Tools: pip, (mypy, ty?)

Automation: Responsibility of the cook

1. Code clarity

πŸ“ tu-cookbook-python/
β”œβ”€πŸ“„ Dockerfile
β”œβ”€πŸ‘‰notebooks/
β”‚ β”œβ”€βœοΈnotebook-template.ipynb
β”‚ β””β”€πŸ“„ how-to-cite.md
β”œβ”€πŸ“„ .gitignore
β”œβ”€πŸ“„ docker-compose.yml
β”œβ”€πŸ“„ CITATION.cff
β”œβ”€πŸ“„ CONTRIBUTING.md
β”œβ”€πŸ‘‰src/
β”‚ β””β”€πŸ‘‰tucookbook/
β”‚   β””β”€βœοΈ__init__.py
β”œβ”€πŸ“„ .pre-commit-config.yaml
β”œβ”€πŸ“„ CHANGELOG
β”œβ”€πŸ“„ .gitlab-ci.yml
β”œβ”€πŸ“„ README.md
β”œβ”€βœοΈpyproject.toml
β”œβ”€πŸ“„ COPYRIGHT.md
β”œβ”€πŸ“„ environment.yml
β”œβ”€πŸ“„ LICENSE
β””β”€πŸ“„ myst.yml

2. Code quality

  • Code style PEP8
  • Type checking
  • (Reviewed) open source software (pyopensci)
  • Runtime?

Tools: ruff

Automation: Assistance with pre-commit hooks

2. Code quality

πŸ“ tu-cookbook-python/
β”œβ”€πŸ“„ Dockerfile
β”œβ”€πŸ“ notebooks/
β”‚ β”œβ”€πŸ“„ notebook-template.ipynb
β”‚ β””β”€πŸ“„ how-to-cite.md
β”œβ”€πŸ“„ .gitignore
β”œβ”€πŸ“„ docker-compose.yml
β”œβ”€πŸ“„ CITATION.cff
β”œβ”€πŸ“„ CONTRIBUTING.md
β”œβ”€πŸ“ src/
β”‚ β””β”€πŸ“ tucookbook/
β”‚   β””β”€πŸ“„ __init__.py
β”œβ”€βœοΈ.pre-commit-config.yaml
β”œβ”€πŸ“„ CHANGELOG
β”œβ”€πŸ“„ .gitlab-ci.yml
β”œβ”€πŸ“„ README.md
β”œβ”€βœοΈpyproject.toml
β”œβ”€πŸ“„ COPYRIGHT.md
β”œβ”€πŸ“„ environment.yml
β”œβ”€πŸ“„ LICENSE
β””β”€πŸ“„ myst.yml

3. Dependencies

  • Prevent package version pinning
  • Conda for cross-platform usage (Windows)
  • Custom code as installable Python package (toml file)
  • Docker
    • complex system requirements
    • JupyterHub compatibility

Tools: conda, docker

Automation: Assistance with conda and docker-compose

3. Dependencies

πŸ“ tu-cookbook-python/
β”œβ”€βœοΈDockerfile
β”œβ”€πŸ“ notebooks/
β”‚ β”œβ”€πŸ“„ notebook-template.ipynb
β”‚ β””β”€πŸ“„ how-to-cite.md
β”œβ”€πŸ“„ .gitignore
β”œβ”€βœοΈdocker-compose.yml
β”œβ”€πŸ“„ CITATION.cff
β”œβ”€πŸ“„ CONTRIBUTING.md
β”œβ”€πŸ“ src/
β”‚ β””β”€πŸ“ tucookbook/
β”‚   β””β”€πŸ“„ __init__.py
β”œβ”€πŸ“„ .pre-commit-config.yaml
β”œβ”€πŸ“„ CHANGELOG
β”œβ”€πŸ“„ .gitlab-ci.yml
β”œβ”€πŸ“„ README.md
β”œβ”€βœοΈpyproject.toml
β”œβ”€πŸ“„ COPYRIGHT.md
β”œβ”€βœοΈenvironment.yml
β”œβ”€πŸ“„ LICENSE
β””β”€πŸ“„ myst.yml

4. Code testing

  • Restart kernel and execute all cells (β€œrinse and repeat”)
  • MyST Jupyter Book
myst build --execute --html
  • GitLab CI
    • Check the README β€œnightly build” badge

Tools: myst, gitlab-ci

Automation: Fully automated check and badge β€œnightly build”

4. Code testing

πŸ“ tu-cookbook-python/
β”œβ”€πŸ“„ Dockerfile
β”œβ”€πŸ“ notebooks/
β”‚ β”œβ”€πŸ“„ notebook-template.ipynb
β”‚ β””β”€πŸ“„ how-to-cite.md
β”œβ”€πŸ“„ .gitignore
β”œβ”€πŸ“„ docker-compose.yml
β”œβ”€πŸ“„ CITATION.cff
β”œβ”€πŸ“„ CONTRIBUTING.md
β”œβ”€πŸ“ src/
β”‚ β””β”€πŸ“ tucookbook/
β”‚   β””β”€πŸ“„ __init__.py
β”œβ”€πŸ“„ .pre-commit-config.yaml
β”œβ”€πŸ“„ CHANGELOG
β”œβ”€βœοΈ.gitlab-ci.yml
β”œβ”€πŸ“„ README.md
β”œβ”€πŸ“„ pyproject.toml
β”œβ”€πŸ“„ COPYRIGHT.md
β”œβ”€πŸ“„ environment.yml
β”œβ”€πŸ“„ LICENSE
β””β”€βœοΈmyst.yml

5. Attribution

  • Code license
  • Python package metadata (toml)
  • Content license

Tools: ?

Automation: Responsibility of the cook

5. Attribution

πŸ“ tu-cookbook-python/
β”œβ”€πŸ“„ Dockerfile
β”œβ”€πŸ“ notebooks/
β”‚ β”œβ”€πŸ“„ notebook-template.ipynb
β”‚ β””β”€πŸ“„ how-to-cite.md
β”œβ”€πŸ“„ .gitignore
β”œβ”€πŸ“„ docker-compose.yml
β”œβ”€πŸ“„ CITATION.cff
β”œβ”€πŸ“„ CONTRIBUTING.md
β”œβ”€πŸ“ src/
β”‚ β””β”€πŸ“ tucookbook/
β”‚   β””β”€πŸ“„ __init__.py
β”œβ”€πŸ“„ .pre-commit-config.yaml
β”œβ”€πŸ“„ CHANGELOG
β”œβ”€πŸ“„ .gitlab-ci.yml
β”œβ”€πŸ“„ README.md
β”œβ”€πŸ“„ pyproject.toml
β”œβ”€βœοΈCOPYRIGHT.md
β”œβ”€πŸ“„ environment.yml
β”œβ”€βœοΈLICENSE
β””β”€πŸ“„ myst.yml

6. Citing

  • Cite all third-party work
  • Explain how to cite the book
  • Zenodo DOI minting?

Tools: CITATION.cff

Automation: Responsibility of the cook

6. Citing

πŸ“ tu-cookbook-python/
β”œβ”€πŸ“„ Dockerfile
β”œβ”€πŸ“ notebooks/
β”‚ β”œβ”€πŸ“„ notebook-template.ipynb
β”‚ β””β”€βœοΈhow-to-cite.md
β”œβ”€πŸ“„ .gitignore
β”œβ”€πŸ“„ docker-compose.yml
β”œβ”€βœοΈCITATION.cff
β”œβ”€πŸ“„ CONTRIBUTING.md
β”œβ”€πŸ“ src/
β”‚ β””β”€πŸ“ tucookbook/
β”‚   β””β”€πŸ“„ __init__.py
β”œβ”€πŸ“„ .pre-commit-config.yaml
β”œβ”€πŸ“„ CHANGELOG
β”œβ”€πŸ“„ .gitlab-ci.yml
β”œβ”€πŸ“„ README.md
β”œβ”€πŸ“„ pyproject.toml
β”œβ”€πŸ“„ COPYRIGHT.md
β”œβ”€πŸ“„ environment.yml
β”œβ”€πŸ“„ LICENSE
β””β”€πŸ“„ myst.yml

7. Reviewing

  • GitLab
    • Commit standard
    • Branching model
  • Never push notebooks with executed cells
  • Prevent pushing large files (50 Mb)
  • Contributing guidelines and changelogs

Tools: git, nbstripout, pre-commit

Automation: Assistance with pre-commit hooks

7. Reviewing

πŸ“ tu-cookbook-python/
β”œβ”€πŸ“„ Dockerfile
β”œβ”€πŸ“ notebooks/
β”‚ β”œβ”€πŸ“„ notebook-template.ipynb
β”‚ β””β”€πŸ“„ how-to-cite.md
β”œβ”€πŸ“„ .gitignore
β”œβ”€πŸ“„ docker-compose.yml
β”œβ”€πŸ“„ CITATION.cff
β”œβ”€βœοΈCONTRIBUTING.md
β”œβ”€πŸ“ src/
β”‚ β””β”€πŸ“ tucookbook/
β”‚   β””β”€πŸ“„ __init__.py
β”œβ”€βœοΈ.pre-commit-config.yaml
β”œβ”€βœοΈCHANGELOG
β”œβ”€πŸ“„ .gitlab-ci.yml
β”œβ”€πŸ“„ README.md
β”œβ”€πŸ“„ pyproject.toml
β”œβ”€πŸ“„ COPYRIGHT.md
β”œβ”€πŸ“„ environment.yml
β”œβ”€πŸ“„ LICENSE
β””β”€πŸ“„ myst.yml

8. Packaging

  • Creating an image for the TUWEL JupyterHub
  • Creating an image for the dataLAB BinderHub

Tools: docker, gitlab-ci

Automation: Fully automated image push to dataLAB registry

8. Packaging

πŸ“ tu-cookbook-python/
β”œβ”€βœοΈDockerfile
β”œβ”€πŸ“ notebooks/
β”‚ β”œβ”€πŸ“„ notebook-template.ipynb
β”‚ β””β”€πŸ“„ how-to-cite.md
β”œβ”€πŸ“„ .gitignore
β”œβ”€πŸ“„ docker-compose.yml
β”œβ”€πŸ“„ CITATION.cff
β”œβ”€πŸ“„ CONTRIBUTING.md
β”œβ”€πŸ“ src/
β”‚ β””β”€πŸ“ tucookbook/
β”‚   β””β”€πŸ“„ __init__.py
β”œβ”€πŸ“„ .pre-commit-config.yaml
β”œβ”€πŸ“„ CHANGELOG
β”œβ”€πŸ“„ .gitlab-ci.yml
β”œβ”€πŸ“„ README.md
β”œβ”€βœοΈpyproject.toml
β”œβ”€πŸ“„ COPYRIGHT.md
β”œβ”€πŸ“„ environment.yml
β”œβ”€πŸ“„ LICENSE
β””β”€πŸ“„ myst.yml

9. Publication

  • Deployment of myst Jupyter book to GitLab pages
  • Local testing
myst build --execute --html

Tools: myst, gitlab-ci

Automation: Fully automated myst build and publication on GitLab Pages

9. Publication

πŸ“ tu-cookbook-python/
β”œβ”€πŸ“„ Dockerfile
β”œβ”€πŸ“ notebooks/
β”‚ β”œβ”€πŸ“„ notebook-template.ipynb
β”‚ β””β”€πŸ“„ how-to-cite.md
β”œβ”€πŸ“„ .gitignore
β”œβ”€πŸ“„ docker-compose.yml
β”œβ”€πŸ“„ CITATION.cff
β”œβ”€πŸ“„ CONTRIBUTING.md
β”œβ”€πŸ“ src/
β”‚ β””β”€πŸ“ tucookbook/
β”‚   β””β”€πŸ“„ __init__.py
β”œβ”€πŸ“„ .pre-commit-config.yaml
β”œβ”€πŸ“„ CHANGELOG
β”œβ”€βœοΈ.gitlab-ci.yml
β”œβ”€πŸ“„ README.md
β”œβ”€πŸ“„ pyproject.toml
β”œβ”€πŸ“„ COPYRIGHT.md
β”œβ”€πŸ“„ environment.yml
β”œβ”€πŸ“„ LICENSE
β””β”€βœοΈmyst.yml

Next Steps

Phase 1:

  • Templates Cookbook/CI for R (and Julia?)
  • The big data issue

Phase 2:

  • More teacher assistance
  • Content creation best practices