|
1 | 1 | from importlib import metadata |
2 | 2 |
|
| 3 | +from sphinx.addnodes import desc_signature |
| 4 | +from sphinx.application import Sphinx |
| 5 | +from sphinx.domains.python import PyFunction |
| 6 | +from sphinx.ext.autodoc import FunctionDocumenter |
| 7 | +from sphinx.util.typing import ExtensionMetadata |
| 8 | + |
3 | 9 | # Configuration file for the Sphinx documentation builder. |
4 | 10 | # |
5 | 11 | # For the full list of built-in configuration values, see the documentation: |
|
20 | 26 | "sphinx_click", |
21 | 27 | "myst_parser", |
22 | 28 | "sphinxcontrib.autodoc_pydantic", |
| 29 | + "sphinx.ext.autodoc", |
| 30 | + "sphinx.ext.intersphinx", |
23 | 31 | ] |
24 | 32 |
|
25 | 33 | # Recognized suffixes |
|
33 | 41 |
|
34 | 42 | language = "English" |
35 | 43 |
|
| 44 | +# references to Python stdlib and packaging |
| 45 | +intersphinx_mapping = { |
| 46 | + "python": ("https://docs.python.org/3", None), |
| 47 | + "packaging": ("https://packaging.pypa.io/en/stable/", None), |
| 48 | + "pyproject-hooks": ("https://pyproject-hooks.readthedocs.io/en/latest/", None), |
| 49 | +} |
| 50 | + |
36 | 51 | # -- Options for HTML output ------------------------------------------------- |
37 | 52 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output |
38 | 53 |
|
|
46 | 61 | autodoc_pydantic_model_show_config_summary = False |
47 | 62 | autodoc_pydantic_model_show_validator_summary = False |
48 | 63 | autodoc_pydantic_model_show_validator_members = False |
| 64 | + |
| 65 | +# autodoc_typehints_format = "fully-qualified" |
| 66 | + |
| 67 | + |
| 68 | +class FromagerHookDocumenter(FunctionDocumenter): |
| 69 | + """Documenter for 'autofromagehook' directive""" |
| 70 | + |
| 71 | + objtype = "fromagerhook" |
| 72 | + |
| 73 | + def format_name(self): |
| 74 | + name = super().format_name() |
| 75 | + if name.startswith("default_"): |
| 76 | + name = name[8:] |
| 77 | + return name |
| 78 | + |
| 79 | + |
| 80 | +class PyFromagerHook(PyFunction): |
| 81 | + """:py:fromagehook""" |
| 82 | + |
| 83 | + def handle_signature(self, sig: str, signode: desc_signature) -> tuple[str, str]: |
| 84 | + # hack to remove module prefix from output |
| 85 | + self.options["module"] = None |
| 86 | + return super().handle_signature(sig, signode) |
| 87 | + |
| 88 | + |
| 89 | +def setup(app: Sphinx) -> ExtensionMetadata: |
| 90 | + app.setup_extension("sphinx.ext.autodoc") |
| 91 | + app.add_directive_to_domain("py", FromagerHookDocumenter.objtype, PyFromagerHook) |
| 92 | + app.add_autodocumenter(FromagerHookDocumenter) |
| 93 | + |
| 94 | + return {"version": release, "parallel_read_safe": True} |
0 commit comments