|
22 | 22 | from sphinx.domains.std import StandardDomain |
23 | 23 | from sphinx.environment import BuildEnvironment |
24 | 24 | from sphinx.ext import doctest as extdoctest |
| 25 | +from sphinx.ext.autodoc import ModuleDocumenter |
25 | 26 | from sphinx.locale import _, __ |
26 | 27 | from sphinx.roles import XRefRole |
27 | 28 | from sphinx.util import logging |
28 | 29 | from sphinx.util.console import bold # pylint: disable=no-name-in-module |
29 | 30 | from sphinx.writers.html import HTMLTranslator |
30 | 31 | from sphinx.writers.latex import LaTeXTranslator |
31 | 32 |
|
| 33 | +from graphtik.fnop import FnOp |
| 34 | + |
32 | 35 | from .. import __version__ |
33 | 36 |
|
34 | 37 | try: |
@@ -501,10 +504,24 @@ def _validate_and_apply_configs(app: Sphinx, config: Config): |
501 | 504 | ) |
502 | 505 |
|
503 | 506 |
|
| 507 | +def _teach_documenter_about_operations(FuncDocClass): |
| 508 | + original__can_document_member = FuncDocClass.can_document_member |
| 509 | + |
| 510 | + def patched__can_document_member(cls, member, membername, isattr, parent): |
| 511 | + return original__can_document_member(member, membername, isattr, parent) or ( |
| 512 | + isinstance(member, FnOp) and isinstance(parent, ModuleDocumenter) |
| 513 | + ) |
| 514 | + |
| 515 | + FuncDocClass.can_document_member = classmethod(patched__can_document_member) |
| 516 | + |
| 517 | + |
504 | 518 | def setup(app: Sphinx): |
505 | 519 | setup.app = app |
506 | 520 | app.require_sphinx("2.0") |
507 | 521 | app.setup_extension("sphinx.ext.doctest") |
| 522 | + app.setup_extension("sphinx.ext.autodoc") |
| 523 | + |
| 524 | + _teach_documenter_about_operations(app.registry.documenters["function"]) |
508 | 525 |
|
509 | 526 | app.add_config_value( |
510 | 527 | "graphtik_graph_formats_by_builder", |
|
0 commit comments