From 18de60859bedff4c8a7ddf252dae2dbb9bba98ad Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Mon, 9 Sep 2024 14:24:19 +0200 Subject: [PATCH] :sparkles: change to py:percent notebooks - use "text" based (not json) format notebooks (py:percent) - done through jupytext --- .gitignore | 1 + docs/conf.py | 8 +++- docs/index.rst | 11 ++--- docs/tutorial/tutorial.ipynb | 83 ------------------------------------ docs/tutorial/tutorial.py | 21 +++++++++ pyproject.toml | 1 + 6 files changed, 34 insertions(+), 91 deletions(-) delete mode 100644 docs/tutorial/tutorial.ipynb create mode 100644 docs/tutorial/tutorial.py diff --git a/.gitignore b/.gitignore index fecbf78..84675af 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ _build _static _templates /docs/reference +/docs/jupyter_execute # MacOS automatically creates these files .DS_Store diff --git a/docs/conf.py b/docs/conf.py index 2bf9101..4b85843 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -56,13 +56,19 @@ # Rendering nb_merge_streams = True +# https://myst-nb.readthedocs.io/en/latest/authoring/custom-formats.html#write-custom-formats +nb_custom_formats = { + ".py": ["jupytext.reads", {"fmt": "py:percent"}] +} + # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. -exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] +exclude_patterns = ["_build", "Thumbs.db", + ".DS_Store", "jupyter_execute", "conf.py",] # Intersphinx options diff --git a/docs/index.rst b/docs/index.rst index 7fac169..cdf5d7c 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,10 +1,5 @@ -.. mockup documentation master file, created by - sphinx-quickstart on Mon Aug 28 14:09:15 2023. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - The mockup package -================================== +================== Mockup is a Python package with some simple example code. To get started, explore the :class:`mockup.Circle` class. @@ -12,16 +7,18 @@ To get started, explore the :class:`mockup.Circle` class. .. toctree:: + :hidden: :maxdepth: 2 :caption: Tutorial tutorial/tutorial .. toctree:: + :hidden: :maxdepth: 2 :caption: Contents: - reference/modules + reference/mockup .. toctree:: :hidden: diff --git a/docs/tutorial/tutorial.ipynb b/docs/tutorial/tutorial.ipynb deleted file mode 100644 index 2cb608a..0000000 --- a/docs/tutorial/tutorial.ipynb +++ /dev/null @@ -1,83 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Mockup tutorial" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from mockup import mockup" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mockup.add_one(-11)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "list(mockup.flatten_ints([[9, 11], [12], [4, 5]]))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "c2 = mockup.Circle.from_circumference(100)\n", - "round(c2.radius, 3)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "c2 # repr" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "pathways", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.4" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/docs/tutorial/tutorial.py b/docs/tutorial/tutorial.py new file mode 100644 index 0000000..2379d13 --- /dev/null +++ b/docs/tutorial/tutorial.py @@ -0,0 +1,21 @@ +# %% [markdown] +# # Mockup tutorial + +# %% +from mockup import mockup + +# %% +mockup.add_one(-11) + +# %% +list(mockup.flatten_ints([[9, 11], [12], [4, 5]])) + +# %% +c2 = mockup.Circle.from_circumference(100) +round(c2.radius, 3) + +# %% +c2 # repr + +# %% [markdown] +# diff --git a/pyproject.toml b/pyproject.toml index 7c4bde6..1ca1dc2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,6 +29,7 @@ docs = [ "myst-nb", "ipywidgets", "sphinx-new-tab-link!=0.2.2", + "jupytext", ] # Configure the Ruff linter: Ignore error number 501