Skip to content

Commit 4cd4c5e

Browse files
authored
Add demo (#12)
* Add demo, add launch buttons * Set module in pyproject.toml * Remove pandoc, add jupytext
1 parent 48cb670 commit 4cd4c5e

File tree

6 files changed

+76
-3
lines changed

6 files changed

+76
-3
lines changed

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# We create a simple docker file that install the necesseary dependencies for the package
2+
3+
FROM ubuntu:22.04
4+
5+
RUN apt-get update && \
6+
apt-get install -y python3-pip
7+
8+
# Use modern setuptools from pip instead of apt
9+
RUN pip3 install pip setuptools --upgrade
10+
11+
RUN apt-get purge python3-setuptools
12+
13+
# Create user with a home directory
14+
ARG NB_USER
15+
ARG NB_UID=1000
16+
ENV USER ${NB_USER}
17+
ENV HOME /home/${NB_USER}
18+
19+
# Copy home directory for usage in binder
20+
WORKDIR ${HOME}
21+
COPY . ${HOME}
22+
USER root
23+
RUN chown -R ${NB_UID} ${HOME}
24+
25+
USER ${NB_USER}
26+
ENTRYPOINT []

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
doc: # Generate Sphinx HTML documentation, including API docs
2-
cp README.md docs/README.md
2+
# We want to use the README.md file from the folder as the front page of the book.
3+
# It has been added to _toc.yml as root
4+
cp README.md docs/README.md
5+
# We want to use the demos in the book, we convert them with jupytext and copy them to the documentation
6+
jupytext --to=ipynb demos/demo.py --output=docs/demo.ipynb
37
jupyter book build docs
48

59
clean-pytest: # Remove output from pytest

demos/demo.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# + [markdown]
2+
# # An introduction to the light format
3+
#
4+
# Author: Jørgen S. Dokken
5+
#
6+
# SPDX-License-Identifier: MIT
7+
# -
8+
9+
# + [markdown]
10+
# We start a new cell explicitly by using the "+" sign and can explicitly end
11+
# it by using the "-" sign.
12+
# -
13+
14+
# If we do not use explicit indicators for starting or ending a cell, it creates a
15+
# new cell whenever there is a blank line
16+
17+
# This is a new cell
18+
19+
# Comments can be added to code by not adding a new line before the code
20+
import mypackage
21+
22+
# Next we define two numbers, `a` and `b`
23+
24+
a = 1
25+
b = 3
26+
27+
# and add them together
28+
29+
c = mypackage.addition(a, b)
30+
31+
# We check the result
32+
33+
assert c == a + b

docs/_config.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ sphinx:
2626
- 'sphinx.ext.viewcode'
2727

2828

29+
launch_buttons:
30+
notebook_interface: "jupyterlab" # The interface interactive links will activate ["classic", "jupyterlab"]
31+
binderhub_url: "https://mybinder.org"
32+
colab_url: "https://colab.research.google.com"
33+
34+
35+
2936
# Add GitHub buttons to your book
3037
# See https://jupyterbook.org/customize/config.html#add-a-link-to-your-repository
3138
html:

docs/_toc.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ format: jb-book
22
root: README
33

44
chapters:
5-
- file: "api"
5+
- file: "demo"
6+
- file: "api"

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[build-system]
22
requires = ["setuptools>=62.1.0", "wheel"]
33

4+
[tool.setuptools]
5+
py-modules = ["mypackage"]
46

57
[project]
68
name = "mypackage"
@@ -28,7 +30,7 @@ test = [
2830
docs = [
2931
"sphinx",
3032
"jupyter-book",
31-
"pandoc"
33+
"jupytext"
3234
]
3335

3436
[tool.mypy]

0 commit comments

Comments
 (0)