|
16 | 16 | import os |
17 | 17 | import re |
18 | 18 | import sys |
| 19 | +from typing import Any, Dict |
19 | 20 |
|
20 | 21 | import sphinx |
| 22 | +import sphinx.application |
21 | 23 |
|
22 | 24 | import rdflib |
23 | 25 |
|
|
47 | 49 | "sphinx.ext.autosectionlabel", |
48 | 50 | ] |
49 | 51 |
|
| 52 | +# https://github.com/sphinx-contrib/apidoc/blob/master/README.rst#configuration |
50 | 53 | apidoc_module_dir = "../rdflib" |
51 | 54 | apidoc_output_dir = "apidocs" |
52 | 55 |
|
@@ -328,3 +331,50 @@ def find_version(filename): |
328 | 331 |
|
329 | 332 | if sys.version_info < (3, 8): |
330 | 333 | nitpick_ignore.extend([("py:class", "importlib_metadata.EntryPoint")]) |
| 334 | + |
| 335 | + |
| 336 | +def autodoc_skip_member_handler( |
| 337 | + app: sphinx.application.Sphinx, |
| 338 | + what: str, |
| 339 | + name: str, |
| 340 | + obj: Any, |
| 341 | + skip: bool, |
| 342 | + options: Dict[str, Any], |
| 343 | +): |
| 344 | + """ |
| 345 | + This function will be called by Sphinx when it is deciding whether to skip a |
| 346 | + member of a class or module. |
| 347 | + """ |
| 348 | + # https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#event-autodoc-skip-member |
| 349 | + if ( |
| 350 | + app.env.docname == "apidocs/rdflib" |
| 351 | + and what == "module" |
| 352 | + and type(obj).__name__.endswith("DefinedNamespaceMeta") |
| 353 | + ): |
| 354 | + # Don't document namespaces in the `rdflib` module, they will be |
| 355 | + # documented in the `rdflib.namespace` module instead and Sphinx does |
| 356 | + # not like when these are documented in two places. |
| 357 | + # |
| 358 | + # An example of the WARNINGS that occur without this is: |
| 359 | + # |
| 360 | + # "WARNING: duplicate object description of rdflib.namespace._SDO.SDO, |
| 361 | + # other instance in apidocs/rdflib, use :noindex: for one of them" |
| 362 | + logging.info( |
| 363 | + "Skipping %s %s in %s, it will be documented in ", |
| 364 | + what, |
| 365 | + name, |
| 366 | + app.env.docname, |
| 367 | + ) |
| 368 | + return True |
| 369 | + return None |
| 370 | + |
| 371 | + |
| 372 | +# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#skipping-members |
| 373 | +def setup(app: sphinx.application.Sphinx) -> None: |
| 374 | + """ |
| 375 | + Setup the Sphinx application. |
| 376 | + """ |
| 377 | + |
| 378 | + # Register a autodoc-skip-member handler so that certain members can be |
| 379 | + # skipped. |
| 380 | + app.connect("autodoc-skip-member", autodoc_skip_member_handler) |
0 commit comments