Skip to content

Commit bc8e59d

Browse files
author
Henry Webel
authored
Merge pull request #3 from RasmussenLab/docs
Add Sphinx template
2 parents 94e7990 + 1122dc8 commit bc8e59d

File tree

12 files changed

+400
-9
lines changed

12 files changed

+400
-9
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ build/
1515
dist/
1616
**.egg-info
1717

18+
# Sphinx documenter creates these
19+
_build
20+
_static
21+
_templates
22+
/docs/reference
23+
1824
# MacOS automatically creates these files
1925
.DS_Store
2026

.readthedocs.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# .readthedocs.yaml
2+
# Read the Docs configuration file
3+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4+
5+
# Required
6+
version: 2
7+
8+
# Set the OS, Python version and other tools you might need
9+
build:
10+
os: ubuntu-22.04
11+
tools:
12+
python: "3.11"
13+
# You can also specify other tool versions:
14+
# nodejs: "19"
15+
# rust: "1.64"
16+
# golang: "1.19"
17+
18+
# Build documentation in the "docs/" directory with Sphinx
19+
sphinx:
20+
configuration: docs/conf.py
21+
22+
# Optionally build your docs in additional formats such as PDF and ePub
23+
# formats:
24+
# - pdf
25+
# - epub
26+
27+
# Optional but recommended, declare the Python requirements required
28+
# to build your documentation
29+
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
30+
python:
31+
install:
32+
- method: pip
33+
path: .
34+
extra_requirements:
35+
- docs

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,20 @@ Install package so that new code is picked up in a restared python interpreter:
88
pip install -e .
99
```
1010

11+
## TestPyPI
12+
13+
Install vom [TestPyPI](https://test.pypi.org/project/rasmussenlab-mockup):
14+
15+
```
16+
pip install -i https://test.pypi.org/simple/ rasmussenlab-mockup
17+
```
18+
19+
> The package on PyPI is call `rasmussenlab-mockup` and not `mockup` as the package name is already taken. The import is still `import mockup`.
20+
21+
## Readthedocs
22+
23+
The documentation is build using readthedocs automatically. See
24+
[project on Readthedocs](https://readthedocs.org/projects/rasmussenlab-python-package/).
25+
26+
- make sure to enable build from PRs in the settings (advanded settings)
27+
- checkout configuration file: [`.readthedocs.yaml`](.readthedocs.yaml)

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Docs creation
2+
3+
In order to build the docs you need to
4+
5+
1. install sphinx and additional support packages
6+
2. build the package reference files
7+
3. run sphinx to create a local html version
8+
9+
The documentation is build using readthedocs automatically.
10+
11+
Install the docs dependencies of the package (as speciefied in toml):
12+
13+
```bash
14+
# in main folder
15+
pip install .[docs]
16+
```
17+
18+
## Build docs using Sphinx command line tools
19+
20+
Command to be run from `path/to/docs`, i.e. from within the `docs` package folder:
21+
22+
Options:
23+
- `--separate` to build separate pages for each (sub-)module
24+
25+
```bash
26+
# pwd: docs
27+
# apidoc
28+
sphinx-apidoc --force --implicit-namespaces --module-first -o reference ../src/mockup
29+
# build docs
30+
sphinx-build -n -W --keep-going -b html ./ ./_build/
31+
```

docs/conf.py

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
import os
14+
from importlib import metadata
15+
16+
17+
# -- Project information -----------------------------------------------------
18+
19+
project = "mockup"
20+
copyright = "2024, Jakob Nybo Nissen, Henry Webel"
21+
author = "Jakob Nybo Nissen, Henry Webel"
22+
PACKAGE_VERSION = metadata.version("rasmussenlab-mockup")
23+
version = PACKAGE_VERSION
24+
release = PACKAGE_VERSION
25+
26+
27+
# -- General configuration ---------------------------------------------------
28+
29+
# Add any Sphinx extension module names here, as strings. They can be
30+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
31+
# ones.
32+
extensions = [
33+
"sphinx.ext.autodoc",
34+
"sphinx.ext.autodoc.typehints",
35+
"sphinx.ext.viewcode",
36+
"sphinx.ext.napoleon",
37+
"sphinx.ext.intersphinx",
38+
"sphinx_new_tab_link",
39+
"myst_nb",
40+
]
41+
42+
# https://myst-nb.readthedocs.io/en/latest/computation/execute.html
43+
nb_execution_mode = "auto"
44+
45+
myst_enable_extensions = ["dollarmath", "amsmath"]
46+
47+
# Plolty support through require javascript library
48+
# https://myst-nb.readthedocs.io/en/latest/render/interactive.html#plotly
49+
html_js_files = [
50+
"https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"
51+
]
52+
53+
# https://myst-nb.readthedocs.io/en/latest/configuration.html
54+
# Execution
55+
nb_execution_raise_on_error = True
56+
# Rendering
57+
nb_merge_streams = True
58+
59+
# Add any paths that contain templates here, relative to this directory.
60+
templates_path = ["_templates"]
61+
62+
# List of patterns, relative to source directory, that match files and
63+
# directories to ignore when looking for source files.
64+
# This pattern also affects html_static_path and html_extra_path.
65+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
66+
67+
68+
# Intersphinx options
69+
intersphinx_mapping = {
70+
"python": ("https://docs.python.org/3", None),
71+
# "pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
72+
# "scikit-learn": ("https://scikit-learn.org/stable/", None),
73+
# "matplotlib": ("https://matplotlib.org/stable/", None),
74+
}
75+
76+
# -- Options for HTML output -------------------------------------------------
77+
78+
# The theme to use for HTML and HTML Help pages. See the documentation for
79+
# a list of builtin themes.
80+
# See:
81+
# https://github.com/executablebooks/MyST-NB/blob/master/docs/conf.py
82+
# html_title = ""
83+
html_theme = "sphinx_book_theme"
84+
# html_logo = "_static/logo-wide.svg"
85+
# html_favicon = "_static/logo-square.svg"
86+
html_theme_options = {
87+
"github_url": "https://github.com/RasmussenLab/python_package",
88+
"repository_url": "https://github.com/RasmussenLab/python_package",
89+
"repository_branch": "main",
90+
"home_page_in_toc": True,
91+
"path_to_docs": "docs",
92+
"show_navbar_depth": 1,
93+
"use_edit_page_button": True,
94+
"use_repository_button": True,
95+
"use_download_button": True,
96+
"launch_buttons": {
97+
"colab_url": "https://colab.research.google.com"
98+
# "binderhub_url": "https://mybinder.org",
99+
# "notebook_interface": "jupyterlab",
100+
},
101+
"navigation_with_keys": False,
102+
}
103+
104+
# Add any paths that contain custom static files (such as style sheets) here,
105+
# relative to this directory. They are copied after the builtin static files,
106+
# so a file named "default.css" will overwrite the builtin "default.css".
107+
# html_static_path = ["_static"]
108+
109+
110+
# -- Setup for sphinx-apidoc -------------------------------------------------
111+
112+
# Read the Docs doesn't support running arbitrary commands like tox.
113+
# sphinx-apidoc needs to be called manually if Sphinx is running there.
114+
# https://github.com/readthedocs/readthedocs.org/issues/1139
115+
116+
if os.environ.get("READTHEDOCS") == "True":
117+
from pathlib import Path
118+
119+
PROJECT_ROOT = Path(__file__).parent.parent
120+
PACKAGE_ROOT = PROJECT_ROOT / "src" / "mockup"
121+
122+
def run_apidoc(_):
123+
from sphinx.ext import apidoc
124+
125+
apidoc.main(
126+
[
127+
"--force",
128+
"--implicit-namespaces",
129+
"--module-first",
130+
"--separate",
131+
"-o",
132+
str(PROJECT_ROOT / "docs" / "reference"),
133+
str(PACKAGE_ROOT),
134+
str(PACKAGE_ROOT / "*.c"),
135+
str(PACKAGE_ROOT / "*.so"),
136+
]
137+
)
138+
139+
def setup(app):
140+
app.connect("builder-inited", run_apidoc)

docs/index.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.. mockup documentation master file, created by
2+
sphinx-quickstart on Mon Aug 28 14:09:15 2023.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
The mockup package
7+
==================================
8+
9+
Mockup is a Python package with some simple example code.
10+
To get started, explore the :class:`mockup.Circle` class.
11+
12+
13+
14+
.. toctree::
15+
:maxdepth: 2
16+
:caption: Tutorial
17+
18+
tutorial/tutorial
19+
20+
.. toctree::
21+
:maxdepth: 2
22+
:caption: Contents:
23+
24+
reference/modules
25+
26+
.. toctree::
27+
:hidden:
28+
:caption: Technical notes
29+
30+
README.md
31+
32+
33+
34+
Indices and tables
35+
==================
36+
37+
* :ref:`genindex`
38+
* :ref:`modindex`
39+
* :ref:`search`

docs/tutorial/tutorial.ipynb

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Mockup tutorial"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"from mockup import mockup"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": null,
22+
"metadata": {},
23+
"outputs": [],
24+
"source": [
25+
"mockup.add_one(-11)"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": null,
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"list(mockup.flatten_ints([[9, 11], [12], [4, 5]]))"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": null,
40+
"metadata": {},
41+
"outputs": [],
42+
"source": [
43+
"c2 = mockup.Circle.from_circumference(100)\n",
44+
"round(c2.radius, 3)"
45+
]
46+
},
47+
{
48+
"cell_type": "code",
49+
"execution_count": null,
50+
"metadata": {},
51+
"outputs": [],
52+
"source": [
53+
"c2 # repr"
54+
]
55+
},
56+
{
57+
"cell_type": "markdown",
58+
"metadata": {},
59+
"source": []
60+
}
61+
],
62+
"metadata": {
63+
"kernelspec": {
64+
"display_name": "pathways",
65+
"language": "python",
66+
"name": "python3"
67+
},
68+
"language_info": {
69+
"codemirror_mode": {
70+
"name": "ipython",
71+
"version": 3
72+
},
73+
"file_extension": ".py",
74+
"mimetype": "text/x-python",
75+
"name": "python",
76+
"nbconvert_exporter": "python",
77+
"pygments_lexer": "ipython3",
78+
"version": "3.11.4"
79+
}
80+
},
81+
"nbformat": 4,
82+
"nbformat_minor": 2
83+
}

0 commit comments

Comments
 (0)