Skip to content

Commit 375f6da

Browse files
authored
docs: Generate API reference using sphinx-autoapi (#14)
* pyproject.toml: Add docs dependency group * Update poetry.lock * waveform: Fix bulleted list formatting * docs: Add configuration and index page * github: Update check_nitypes.yml to generate docs * Remove Py3.8 Sphinx versioning * Update poetry.lock * github: Upload an artifact containing the generated docs * github: Split check_docs into a separate workflow file so it doesn't gate tests * waveform: Document warnings with "Raises" because "Warnings" displays a warning symbol * docs: Add GitHub issue link to TODO * pyproject.toml: Upgrade to latest Sphinx * Update poetry.lock * docs: Update copyright to use range of years
1 parent 4ae37e4 commit 375f6da

File tree

7 files changed

+736
-11
lines changed

7 files changed

+736
-11
lines changed

.github/workflows/CI.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ on:
1010

1111
jobs:
1212
check_nitypes:
13-
name: Check
13+
name: Check nitypes
1414
uses: ./.github/workflows/check_nitypes.yml
15+
check_docs:
16+
name: Check docs
17+
uses: ./.github/workflows/check_docs.yml
1518
run_unit_tests:
1619
name: Run unit tests
1720
uses: ./.github/workflows/run_unit_tests.yml

.github/workflows/check_docs.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Check docs
2+
3+
on:
4+
workflow_call:
5+
workflow_dispatch:
6+
7+
env:
8+
POETRY_VERSION: 1.8.2
9+
PYTHON_VERSION: 3.11.9
10+
11+
jobs:
12+
check_docs:
13+
name: Check docs
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Check out repo
17+
uses: actions/checkout@v4
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
id: setup-python
21+
with:
22+
python-version: ${{ env.PYTHON_VERSION }}
23+
- name: Set up Poetry
24+
uses: Gr1N/setup-poetry@v9
25+
with:
26+
poetry-version: ${{ env.POETRY_VERSION }}
27+
- name: Check for lock changes
28+
run: poetry check --lock
29+
- name: Cache virtualenv (with docs)
30+
uses: actions/cache@v4
31+
with:
32+
path: .venv
33+
key: nitypes-with-docs-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}
34+
- name: Install nitypes (with docs)
35+
run: poetry install -v --with docs
36+
- name: Generate docs
37+
run: poetry run sphinx-build docs docs/_build -b html -W --keep-going
38+
- name: Upload docs artifact
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: nitypes-docs
42+
path: docs/_build/

docs/conf.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
"""Sphinx Configuration File."""
2+
3+
import datetime
4+
import pathlib
5+
6+
import autoapi.extension
7+
import toml
8+
9+
# Add any Sphinx extension module names here, as strings. They can be
10+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
11+
# ones.
12+
extensions = [
13+
"autoapi.extension",
14+
"m2r2",
15+
"sphinx.ext.autodoc",
16+
"sphinx.ext.intersphinx",
17+
"sphinx.ext.napoleon",
18+
"sphinx.ext.viewcode",
19+
]
20+
21+
root_path = pathlib.Path(__file__).parent.parent
22+
pyproj_file = root_path / "pyproject.toml"
23+
proj_config = toml.loads(pyproj_file.read_text())
24+
25+
26+
project = proj_config["tool"]["poetry"]["name"]
27+
company = "National Instruments"
28+
copyright = f"2025-%Y, {company}"
29+
if datetime.datetime.now().year == 2025:
30+
copyright = f"%Y, {company}"
31+
32+
33+
# The version info for the project you're documenting, acts as replacement for
34+
# |version| and |release|, also used in various other places throughout the
35+
# built documents.
36+
#
37+
version = proj_config["tool"]["poetry"]["version"]
38+
release = ".".join(version.split(".")[:2])
39+
description = proj_config["tool"]["poetry"]["description"]
40+
41+
42+
htmlhelp_basename = f"{project}doc"
43+
44+
45+
# tell autoapi to doc the public options
46+
autoapi_options = list(autoapi.extension._DEFAULT_OPTIONS)
47+
autoapi_options.remove("private-members") # note: remove this to include "_" members in docs
48+
autoapi_dirs = [root_path / "src" / "nitypes"]
49+
autoapi_type = "python"
50+
autodoc_typehints = "description"
51+
52+
53+
# TODO: https://github.com/ni/nitypes-python/issues/16 - Update nitypes-python docs to use
54+
# :canonical: to resolve aliases (once supported by sphinx-autoapi)
55+
def skip_aliases(app, what, name, obj, skip, options):
56+
"""Skip documentation for classes that are exported from multiple modules."""
57+
# For names that are defined in a private sub-module and aliased into a
58+
# public package, hide the definition.
59+
if name.startswith("nitypes.time._") or name.startswith("nitypes.waveform._"):
60+
skip = True
61+
62+
return skip
63+
64+
65+
def setup(sphinx):
66+
"""Sphinx setup callback."""
67+
sphinx.connect("autoapi-skip-member", skip_aliases)
68+
69+
70+
# List of patterns, relative to source directory, that match files and
71+
# directories to ignore when looking for source files.
72+
# This patterns also effect to html_static_path and html_extra_path
73+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
74+
75+
76+
intersphinx_mapping = {
77+
"python": ("https://docs.python.org/3", None),
78+
}
79+
80+
81+
# -- Options for HTML output ----------------------------------------------
82+
83+
84+
# The theme to use for HTML and HTML Help pages. See the documentation for
85+
# a list of builtin themes.
86+
#
87+
html_theme = "sphinx_rtd_theme"
88+
html_theme_options = {
89+
"navigation_depth": -1,
90+
}
91+
92+
# Napoleon settings
93+
napoleon_numpy_docstring = False

docs/index.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Data Types for NI Python APIs
2+
=============================
3+
.. toctree::
4+
:maxdepth: 3
5+
6+
autoapi/index
7+
8+
Indices and tables
9+
------------------
10+
* :ref:`modindex`
11+
* :ref:`search`

0 commit comments

Comments
 (0)