Skip to content

Commit 9acbdb8

Browse files
committed
conf: Build a json symbol index on build.
Ship it with the docs so we can parse it in Pybricks for namespace based lookup.
1 parent 7409057 commit 9acbdb8

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

doc/common/conf.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,35 @@ def on_missing_reference(
364364
return nodes.Text(f"{ret_type}: {ret_unit}")
365365

366366

367+
def on_build_finished(app: Sphinx, exception):
368+
if exception or app.builder.name != "html":
369+
return
370+
import json
371+
from sphinx.ext.intersphinx import InventoryFile
372+
373+
inv_path = os.path.join(app.outdir, "objects.inv")
374+
if not os.path.exists(inv_path):
375+
return
376+
377+
with open(inv_path, "rb") as f:
378+
inv = InventoryFile.load(f, "", lambda base, uri: base + uri)
379+
380+
index = {}
381+
for type_key, entries in inv.items():
382+
if not type_key.startswith("py:"):
383+
continue
384+
for name, (project, version, url, display) in entries.items():
385+
index[name] = url
386+
387+
out_path = os.path.join(app.outdir, "namespace_index.json")
388+
with open(out_path, "w") as f:
389+
json.dump(index, f, indent=2, sort_keys=True)
390+
391+
367392
def setup(app: Sphinx):
368393
app.add_directive("availability", AvailabilityDirective)
369394
app.connect("missing-reference", on_missing_reference)
395+
app.connect("build-finished", on_build_finished)
370396

371397

372398
# -- Python domain hacks ---------------------------------------------------

0 commit comments

Comments
 (0)