Skip to content

Commit 5c90c00

Browse files
docs: Add Sphinx autodoc generation
Signed-off-by: Bernhard Kaindl <[email protected]>
1 parent afa444f commit 5c90c00

26 files changed

+322
-1
lines changed

.readthedocs.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# .readthedocs.yml
2+
# Read the Docs configuration file
3+
version: 2
4+
5+
build:
6+
os: ubuntu-22.04
7+
tools:
8+
python: "3.12"
9+
10+
python:
11+
install:
12+
- requirements: docs/requirements.txt
13+
- method: pip
14+
path: .
15+
16+
sphinx:
17+
configuration: docs/source/conf.py
18+
19+
# Optionally, set the documentation type
20+
# formats:
21+
# - html
22+
# - pdf
23+
# - epub

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ For more information to debug `pytest` test suites see
202202
## Running GitHub actions locally using `act`
203203
204204
With `docker` (or `podman`) installed, [act](https://github.com/nektos/act) can be used to run
205-
the CI jobs configured in [.actrc](.actrc):
205+
the CI jobs configured in [`.actrc`](https://github.com/xenserver/python-libs/blob/master/.actrc):
206206
207207
- `act` uses `docker` (also mimicked by `podman-docker`) to run GitHub actions locally
208208
- While `act` does not use the same GitHub runner images, they are similar.

DOCUMENTING.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Documenting using Sphinx
2+
3+
This project uses **Google style docstrings** for Python code documentation. These docstrings are compatible with Sphinx (with the `sphinx.ext.napoleon` extension) and other documentation tools.
4+
5+
## Why Google Style Docstrings?
6+
7+
- Clear, readable format
8+
- Widely supported by documentation generators
9+
- Easy to maintain
10+
11+
## Example Google Style Docstring
12+
13+
```python
14+
def add(a: int, b: int) -> int:
15+
"""Add two integers.
16+
17+
Args:
18+
a (int): First integer.
19+
b (int): Second integer.
20+
21+
Returns:
22+
int: The sum of `a` and `b`.
23+
24+
Raises:
25+
ValueError: If either argument is not an integer.
26+
"""
27+
if not isinstance(a, int) or not isinstance(b, int):
28+
raise ValueError("Arguments must be integers.")
29+
return a + b
30+
```
31+
32+
## Steps to Document Your Code
33+
34+
1. **Write Google style docstrings** for all public modules, classes, and functions.
35+
2. **Include sections** such as `Args`, `Returns`, `Raises`, and `Examples` as needed.
36+
3. **Keep docstrings concise and informative.**
37+
38+
## Benefits of using Sphinx
39+
40+
- Supports docstring formats – such as Google-style, NumPy-style, and reST.
41+
- Autodoc extension – can automatically extract documentation from Python docstrings.
42+
- Integration with Read the Docs – makes it easy to publish and host documentation online.
43+
- Theme support – like Read the Docs theme or the modern Furo theme.
44+
45+
## Building the documentation
46+
47+
```bash
48+
pip install -r docs/requirements.txt
49+
make -C docs html
50+
```
51+
52+
Open `docs/html/index.html` in a web browser.
53+
54+
## References
55+
56+
- [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings)
57+
- [Sphinx Napoleon Documentation](https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html)

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 = source
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/requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sphinx
2+
sphinx-autodoc-typehints
3+
furo
4+
myst_parser

docs/source/accessor.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
xcp.accessor
2+
=============
3+
4+
.. automodule:: xcp.accessor
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

docs/source/bootloader.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
xcp.bootloader
2+
==============
3+
4+
.. automodule:: xcp.bootloader
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

docs/source/cmd.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
xcp.cmd
2+
=======
3+
4+
.. automodule:: xcp.cmd
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

docs/source/compat.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
xcp.compat
2+
==========
3+
4+
.. automodule:: xcp.compat
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

docs/source/conf.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
# -- Path setup -------------------------------------------------------------
3+
import logging
4+
import os
5+
import sys
6+
7+
# For the full list of built-in configuration values, see the documentation:
8+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
9+
10+
# Add project root to sys.path for autodoc to find xcp modules and it allows
11+
# to {include} the toplevel README.md files from their wrapper files here.
12+
sys.path.insert(0, os.path.abspath("../.."))
13+
14+
# Add stubs directory to sys.path for stubs (xcp/bootloader.py needs a branding.py)
15+
sys.path.insert(0, os.path.abspath("../../stubs"))
16+
17+
#
18+
# To support Markdown-based documentation, Sphinx can use MyST-Parser.
19+
# MyST-Parser is a Docutils bridge to markdown-it-py, a Python package
20+
# for parsing the CommonMark Markdown flavor.
21+
# See https://myst-parser.readthedocs.io/en/latest/ for details.
22+
# Set the log level of markdown-it log categories to INFO to disable DEBUG
23+
# logging and prevent flooding the logs with many 1000s of DEBUG messages:
24+
#
25+
logging.getLogger("markdown_it.rules_block").setLevel(logging.INFO)
26+
logging.getLogger("markdown_it.rules_inline").setLevel(logging.INFO)
27+
logging.getLogger("markdown_it").setLevel(logging.INFO)
28+
29+
# -- Project information -----------------------------------------------------
30+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
31+
32+
project = "python-libs"
33+
copyright = "2025, Citrix Inc."
34+
author = "Citrix Inc."
35+
from datetime import datetime
36+
37+
release = datetime.now().strftime("%Y.%m.%d-%H%M")
38+
39+
# -- General configuration ---------------------------------------------------
40+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
41+
42+
extensions = [
43+
"sphinx.ext.autodoc",
44+
"sphinx.ext.viewcode",
45+
"sphinx.ext.githubpages",
46+
"myst_parser",
47+
]
48+
49+
templates_path = ["_templates"]
50+
exclude_patterns = []
51+
52+
53+
# -- Options for HTML output -------------------------------------------------
54+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
55+
56+
html_theme = "furo"
57+
html_static_path = ["_static"]

0 commit comments

Comments
 (0)