Skip to content

Commit 9d7e3da

Browse files
committed
Add a CI check for the public API
This builds the docs in CI, and then checks the `lt` symbols against our top-level `__all__`. Hopefully, doing so will stop things getting out of date.
1 parent a91dc47 commit 9d7e3da

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

.github/workflows/docs.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Documentation
2+
3+
on:
4+
- pull_request
5+
6+
jobs:
7+
build-docs:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v3
12+
13+
- name: Set up Python
14+
uses: actions/setup-python@v4
15+
with:
16+
python-version: "3.11"
17+
18+
- name: Install Dependencies
19+
run: pip install -e . -r dev-requirements.txt
20+
21+
- name: Print installed packages
22+
run: pip freeze
23+
24+
- name: Build docs with Sphinx
25+
working-directory: ./docs/
26+
run: make html
27+
28+
- name: Check public API docs are complete
29+
working-directory: ./docs/
30+
run: python check_public_api.py

dev-requirements.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ attrs==25.3.0
2222
# via
2323
# jsonschema
2424
# referencing
25+
# sphobjinv
2526
autodocsumm==0.2.14
2627
# via sphinx-toolbox
2728
babel==2.17.0
@@ -37,6 +38,7 @@ certifi==2025.7.14
3738
# requests
3839
# sentry-sdk
3940
# sphinx-prompt
41+
# sphobjinv
4042
charset-normalizer==3.4.2
4143
# via requests
4244
click==8.2.1
@@ -140,7 +142,9 @@ jinja2==3.1.6
140142
# sphinx-autoapi
141143
# sphinx-jinja2-compat
142144
jsonschema==4.24.1
143-
# via labthings-fastapi (pyproject.toml)
145+
# via
146+
# labthings-fastapi (pyproject.toml)
147+
# sphobjinv
144148
jsonschema-specifications==2025.4.1
145149
# via jsonschema
146150
markdown-it-py==3.0.0
@@ -309,6 +313,8 @@ sphinxcontrib-qthelp==2.0.0
309313
# via sphinx
310314
sphinxcontrib-serializinghtml==2.0.0
311315
# via sphinx
316+
sphobjinv==2.4
317+
# via labthings-fastapi (pyproject.toml)
312318
starlette==0.47.1
313319
# via fastapi
314320
tabulate==0.9.0

docs/check_public_api.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""Check public API for completeness.
2+
3+
This module loads the intersphinx inventory, and checks that all the symbols from the
4+
top-level module are present. This should prevent that page from going out of date.
5+
"""
6+
7+
import sphobjinv as soi
8+
9+
import labthings_fastapi as lt
10+
11+
if __name__ == "__main__":
12+
inventory = soi.Inventory("build/html/objects.inv")
13+
14+
if not inventory.project == "labthings-fastapi":
15+
raise AssertionError(f"The inventory is for {inventory.project} not LabThings!")
16+
17+
published_lt_namespace = {}
18+
19+
for object in inventory.objects:
20+
if object.name.startswith("lt.") and object.domain == "py":
21+
published_lt_namespace[object.name] = object
22+
23+
missing = []
24+
25+
for name in lt.__all__:
26+
if f"lt.{name}" not in published_lt_namespace:
27+
missing.append(name)
28+
29+
if missing:
30+
msg = "Failure: the following symbols are missing from the `lt` namespace: \n\n"
31+
msg += "\n".join(missing)
32+
raise AssertionError(msg)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ dev = [
4141
"sphinx>=7.2",
4242
"sphinx-autoapi",
4343
"sphinx-toolbox",
44+
"sphobjinv",
4445
"tomli; python_version < '3.11'",
4546
"codespell",
4647
]

0 commit comments

Comments
 (0)