Skip to content

Commit e9622d7

Browse files
authored
docs: Bootstrap documentation generation (#21)
* pyproject.toml: Add docs dependency group * docs: Add config and top page * github: Add docs workflow * Update poetry.lock
1 parent 3c7d248 commit e9622d7

File tree

6 files changed

+666
-2
lines changed

6 files changed

+666
-2
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_nipanel:
13-
name: Check
13+
name: Check nipanel
1414
uses: ./.github/workflows/check_nipanel.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: nipanel-with-docs-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}
34+
- name: Install nipanel (with docs)
35+
run: poetry install -v --only main,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: nipanel-docs
42+
path: docs/_build/

docs/conf.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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" / "nipanel"]
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("nipanel._"):
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+
# TODO: AB#3120159 - Update nipanel intersphinx mapping for nitypes
77+
intersphinx_mapping = {
78+
"grpc": ("https://grpc.github.io/grpc/python/", None),
79+
"measurement-plugin-python": (
80+
"https://measurement-plugin-python.readthedocs.io/en/latest/",
81+
None,
82+
),
83+
"numpy": ("https://numpy.org/doc/stable/", None),
84+
"protobuf": ("https://googleapis.dev/python/protobuf/latest/", None),
85+
"python": ("https://docs.python.org/3", None),
86+
}
87+
88+
89+
# -- Options for HTML output ----------------------------------------------
90+
91+
92+
# The theme to use for HTML and HTML Help pages. See the documentation for
93+
# a list of builtin themes.
94+
#
95+
html_theme = "sphinx_rtd_theme"
96+
html_theme_options = {
97+
"navigation_depth": -1,
98+
}
99+
100+
# Napoleon settings
101+
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+
NI Panel Python API
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)