Skip to content

Commit dc8c560

Browse files
authored
Generate and publish API docs (#72)
The documentation is generated using MkDocs, using the Material theme plus mkdocstrings (and a few minor supporting extensions) to build the API documentation extracted from code comments.
2 parents 0cb59e1 + 5542c3d commit dc8c560

File tree

118 files changed

+1281
-1019
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+1281
-1019
lines changed

.github/labeler.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
"part:docs":
2323
- "**/*.md"
24+
- "docs/**"
2425
- LICENSE
2526

2627
"part:microgrid":
@@ -33,12 +34,16 @@
3334
- "tests/**"
3435

3536
"part:tooling":
37+
- "**/*.ini"
38+
- "**/*.toml"
39+
- "**/*.yaml"
40+
- "**/*.yml"
41+
- "*requirements*.txt"
3642
- ".git*"
3743
- ".git*/**"
38-
- "**/*.toml"
39-
- "**/*.ini"
4044
- CODEOWNERS
4145
- MANIFEST.in
42-
- "*requirements*.txt"
46+
- docs/mkdocstrings_autoapi.py
47+
- noxfile.py
4348
- setup.cfg
4449
- setup.py

.github/workflows/ci.yaml

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,118 @@ jobs:
6666
path: dist/
6767
if-no-files-found: error
6868

69-
create-github-release:
69+
generate-docs-pr:
70+
if: github.event_name == 'pull_request'
71+
runs-on: ubuntu-20.04
72+
steps:
73+
- name: Fetch sources
74+
uses: actions/checkout@v3
75+
76+
- name: Setup Git user and e-mail
77+
uses: frequenz-floss/setup-git-user@v1
78+
79+
- name: Set up Python
80+
uses: actions/setup-python@v4
81+
with:
82+
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
83+
84+
- name: Install build dependencies
85+
run: |
86+
python -m pip install -U pip
87+
python -m pip install .[docs]
88+
89+
- name: Generate the documentation
90+
env:
91+
MIKE_VERSION: pr-${{ github.event.number }}
92+
run: |
93+
mike deploy $MIKE_VERSION
94+
mike set-default $MIKE_VERSION
95+
96+
- name: Upload site
97+
uses: actions/upload-artifact@v3
98+
with:
99+
name: frequenz-channels-python-site
100+
path: site/
101+
if-no-files-found: error
102+
103+
publish-docs:
70104
needs: ["test", "build-dist"]
105+
if: github.event_name == 'push'
106+
runs-on: ubuntu-20.04
107+
permissions:
108+
contents: write
109+
steps:
110+
- name: Calculate and check version
111+
id: mike-metadata
112+
env:
113+
REF: ${{ github.ref }}
114+
REF_NAME: ${{ github.ref_name }}
115+
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
116+
run: |
117+
aliases=
118+
version=
119+
if test "$REF_NAME" = "$DEFAULT_BRANCH"
120+
then
121+
version=next
122+
# A tag that starts with vX.Y or X.Y
123+
elif echo "$REF" | grep -q '^refs/tags' && echo "$REF_NAME" | grep -Pq '^v?\d+\.\d+\.'
124+
then
125+
if echo "$REF_NAME" | grep -Pq -- "-" # pre-release
126+
then
127+
echo "::notice title=Documentation was not published::" \
128+
"The tag '$REF_NAME' looks like a pre-release."
129+
exit 0
130+
fi
131+
version=$(echo "$REF_NAME" | sed -r 's/^(v?[0-9]+\.[0-9]+)\..*$/\1/') # vX.Y
132+
major=$(echo "$REF_NAME" | sed -r 's/^(v?[0-9]+)\..*$/\1/') # vX
133+
default_major=$(echo "$DEFAULT_BRANCH" | sed -r 's/^(v?[0-9]+)\..*$/\1/') # vX
134+
aliases=$major
135+
if test "$major" = "$default_major"
136+
then
137+
aliases="$aliases latest"
138+
fi
139+
else
140+
echo "::warning title=Documentation was not published::" \
141+
"Don't know how to handle '$REF' to make 'mike' version."
142+
exit 0
143+
fi
144+
echo "version=$version" >> $GITHUB_OUTPUT
145+
echo "aliases=$aliases" >> $GITHUB_OUTPUT
146+
147+
- name: Fetch sources
148+
if: steps.mike-metadata.outputs.version
149+
uses: actions/checkout@v3
150+
151+
- name: Setup Git user and e-mail
152+
if: steps.mike-metadata.outputs.version
153+
uses: frequenz-floss/setup-git-user@v1
154+
155+
- name: Set up Python
156+
if: steps.mike-metadata.outputs.version
157+
uses: actions/setup-python@v4
158+
with:
159+
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
160+
161+
- name: Install build dependencies
162+
if: steps.mike-metadata.outputs.version
163+
run: |
164+
python -m pip install -U pip
165+
python -m pip install .[docs]
166+
167+
- name: Fetch the gh-pages branch
168+
if: steps.mike-metadata.outputs.version
169+
run: git fetch origin gh-pages --depth=1
170+
171+
- name: Publish site
172+
if: steps.mike-metadata.outputs.version
173+
env:
174+
VERSION: ${{ steps.mike-metadata.outputs.version }}
175+
ALIASES: ${{ steps.mike-metadata.outputs.aliases }}
176+
run: |
177+
mike deploy --push --update-aliases "$VERSION" $ALIASES
178+
179+
create-github-release:
180+
needs: ["publish-docs"]
71181
# Create a release only on tags creation
72182
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
73183
permissions:

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,7 @@ cython_debug/
140140

141141
# PyCharm
142142
.idea
143+
144+
# Automatically generated documentation
145+
docs/reference/
146+
site/

CONTRIBUTING.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,58 @@ python -m pip install pytest pytest-asyncio
4141
pytest tests/test_sdk.py
4242
```
4343

44+
To build the documentation, first install the dependencies:
45+
46+
```sh
47+
python -m pip install -e .[docs]
48+
```
49+
50+
Then you can build the documentation (it will be written in the `site/`
51+
directory):
52+
53+
```sh
54+
mkdocs build
55+
```
56+
57+
Or you can just serve the documentation without building it using:
58+
59+
```sh
60+
mkdocs serve
61+
```
62+
63+
Your site will be updated **live** when you change your files (provided that
64+
you used `pip install -e .`, beware of a common pitfall of using `pip install`
65+
without `-e`, in that case the API reference won't change unless you do a new
66+
`pip install`).
67+
68+
To build multi-version documentation, we use
69+
[mike](https://github.com/jimporter/mike). If you want to see how the
70+
multi-version sites looks like locally, you can use:
71+
72+
```sh
73+
mike deploy my-version
74+
mike set-default my-version
75+
mike serve
76+
```
77+
78+
`mike` works in mysterious ways. Some basic information:
79+
80+
* `mike deploy` will do a `mike build` and write the results to your **local**
81+
`gh-pages` branch. `my-version` is an arbitrary name for the local version
82+
you want to preview.
83+
* `mike set-default` is needed so when you serve the documentation, it goes to
84+
your newly produced documentation by default.
85+
* `mike serve` will serve the contents of your **local** `gh-pages` branch. Be
86+
aware that, unlike `mkdocs serve`, changes to the sources won't be shown
87+
live, as the `mike deploy` step is needed to refresh them.
88+
89+
Be careful not to use `--push` with `mike deploy`, otherwise it will push your
90+
local `gh-pages` branch to the `origin` remote.
91+
92+
That said, if you want to test the actual website in **your fork**, you can
93+
always use `mike deploy --push --remote your-fork-remote`, and then access the
94+
GitHub pages produced for your fork.
95+
4496
## Releasing
4597

4698
These are the steps to create a new release:

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Frequenz Python SDK
22

3+
[<img alt="GitHub Workflow Status" src="https://img.shields.io/github/workflow/status/frequenz-floss/frequenz-sdk-python/frequenz-sdk-python">](https://github.com/frequenz-floss/frequenz-sdk-python/actions/workflows/ci.yaml)
4+
[<img alt="PyPI" src="https://img.shields.io/pypi/v/frequenz-sdk">](https://pypi.org/project/frequenz-sdk/)
5+
[<img alt="PyPI" src="https://img.shields.io/badge/docs-latest-informational">](https://frequenz-floss.github.io/frequenz-sdk-python/)
6+
37
A development kit to interact with the Frequenz development platform.
48

59
## Supported Python versions
@@ -10,5 +14,4 @@ A development kit to interact with the Frequenz development platform.
1014
## Contributing
1115

1216
If you want to know how to build this project and contribute to it, please
13-
check out the [Contributing
14-
Guide](https://github.com/frequenz-floss/frequenz-sdk-python/CONTRIBUTING.md).
17+
check out the [Contributing Guide](CONTRIBUTING.md).

RELEASE_NOTES.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
## Summary
44

5-
<!-- Here goes a general summary of what this release is about -->
5+
The project has a new home!
6+
7+
https://frequenz-floss.github.io/frequenz-sdk-python/
8+
9+
For now the documentation is pretty scarce but we will be improving it with
10+
time.
611

712
## Upgrading
813

benchmarks/data_ingestion/benchmark_microgrid_data.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
"""Benchmark for microgrid data.
1+
# License: MIT
2+
# Copyright © 2022 Frequenz Energy-as-a-Service GmbH
23

3-
Copyright
4-
Copyright © 2022 Frequenz Energy-as-a-Service GmbH
5-
6-
License
7-
MIT
8-
"""
4+
"""Benchmark for microgrid data."""
95

106
import asyncio
117
import time

benchmarks/power_distribution/power_distributor.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
"""Check how long it takes to distribute power.
1+
# License: MIT
2+
# Copyright © 2022 Frequenz Energy-as-a-Service GmbH
23

3-
Copyright
4-
Copyright © 2022 Frequenz Energy-as-a-Service GmbH
5-
6-
License
7-
MIT
8-
"""
4+
"""Check how long it takes to distribute power."""
95

106
import asyncio
117
import csv

docs/CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--8<-- "CONTRIBUTING.md"

docs/SUMMARY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* [Home](index.md)
2+
* [API Reference](reference/)
3+
* [Development](CONTRIBUTING.md)

0 commit comments

Comments
 (0)