Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation pipeline #32

Merged
merged 14 commits into from
Feb 8, 2024
33 changes: 33 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Docs

on:
push:
branches:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should run on prs too, but just not update the gh-pages branch. See https://github.com/mrc-ide/hipercow/blob/main/.github/workflows/pkgdown.yaml for how we do this on R builds.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

- main
pull_request:
branches:
- main

jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install hatch
- name: Generate Docs
run: |
hatch run generate-docs
- name: Deploy Docs
uses: JamesIves/github-pages-deploy-action@v4.4.1
if: github.event_name != 'pull_request'
with:
clean: false
branch: gh-pages
folder: docs/_build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ example/.outpack/index/outpack.rds
example/draft/
.idea
/dist
docs/_build
25 changes: 25 additions & 0 deletions docs/code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Code examples

Giving a short explanation here for function:

(add_function)=
## Add Function

```python
def add(x, y):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is not actually run yet, right? I could have syntactically nonsense code and that'd be fine? Do we have a ticket for working out how to integrate quarto or similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep can make a ticket, so before doing this PR i had a play around with code executing packages, sphinx doctest unfortunately will not be good for us because while it does execute code, it does not attach the output to the next line. There is one other package I found called autorun and that is like having a python console and will have the output of the code on the next line but each code block is like a different python console so no setup code. I had a look at the autorun source code and it doesnt seem super difficult, I think we should just make our own code executing sphinx extension

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a quick demo, see #34 for a automatic code execution docs example and let me know what you think!

return x + y
```

just like normal markdown baby

```{warning}
Easy there buckaroo
```

```{error}
No can do
```

```{note}
For your information
```
49 changes: 49 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
import outpack.__about__ as info

project = info.__name__
copyright = "2023-present Imperial College of Science, Technology and Medicine"
author = "Rich FitzJohn"
release = info.__version__

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
"sphinx_rtd_theme",
"autoapi.extension",
"myst_parser",
"sphinx.ext.autosectionlabel",
"sphinx_copybutton",
]

autoapi_dirs = ["../src"]
autoapi_options = [
"members",
"undoc-members",
"show-inheritance",
"show-module-summary",
"special-members",
"imported-members",
]

copybutton_prompt_text = (
r">>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
)
copybutton_prompt_is_regexp = True

templates_path = ["_templates"]
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = "sphinx_rtd_theme"
html_static_path = ["_static"]
18 changes: 18 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Welcome to outpack-py's documentation!

```{toctree}
:maxdepth: 2
:caption: 'Contents:'

readme
code
```

% uses MyST markdown format https://jupyterbook.org/en/stable/content/myst.html
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're using ReST 🤮 the extension should be .rst not .md

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is using MyST, which sounds like it is slightly different? And they use .md in their docs. https://myst-parser.readthedocs.io/en/latest/intro.html#write-a-markdown-document

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep MyST is all .md files


Also inserting a reference to a function defined in the code file [here](add_function).

Alternative way of referencing is {ref}`Add Function` (each section has an automatic ref generated for it,
it matches the name of the section).

We can also link a document, here I will link {doc}`readme`
3 changes: 3 additions & 0 deletions docs/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```{include} ../README.md
:relative-images:
```
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ path = "src/outpack/__about__.py"
dependencies = [
"coverage[toml]>=6.5",
"pytest",
"sphinx",
"sphinx-rtd-theme",
"myst-parser",
"sphinx-copybutton",
"sphinx-autoapi"
]
[tool.hatch.envs.default.scripts]
test = "pytest {args:tests}"
Expand All @@ -63,7 +68,10 @@ cov-ci = [
"test-cov",
"cov-report-xml",
]

generate-docs = [
"sphinx-autogen ./docs/*.md",
"sphinx-build -b html ./docs ./docs/_build"
]

[[tool.hatch.envs.all.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
Expand Down
1 change: 1 addition & 0 deletions src/outpack/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
#
# SPDX-License-Identifier: MIT
__version__ = "0.0.1"
__name__ = "outpack-py"
Loading