Skip to content

Commit 3627f15

Browse files
committed
Various documentation improvements
- Hide special members - Use intersphinx to link Python and Pydantic docs - Fix documentation of type aliases (mostly)
1 parent 7ca6636 commit 3627f15

22 files changed

Lines changed: 33 additions & 32 deletions

docs/conf.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@
3737
"sphinx.ext.autodoc",
3838
"sphinx.ext.viewcode",
3939
"sphinx.ext.napoleon",
40+
"sphinx.ext.intersphinx",
4041
"sphinx_autodoc_typehints"
4142
]
4243

44+
intersphinx_mapping = {
45+
"python": ("https://docs.python.org/3", None),
46+
"pydantic": ("https://docs.pydantic.dev/latest", None)
47+
}
48+
4349
# Add any paths that contain templates here, relative to this directory.
4450
templates_path = [ "_templates" ]
4551

@@ -61,26 +67,34 @@
6167

6268
# -- Autodoc Configuration ---------------------------------------------------------------
6369

64-
# The following two options seem to be ignored...
70+
nitpicky = True
71+
6572
autodoc_typehints = "description"
66-
autodoc_type_aliases = { type_alias: f"{type_alias}" for type_alias in {
67-
"JSONObject"
73+
autodoc_type_aliases = { k: k for k in {
74+
"JSONObject",
75+
"SkippedMessageKeys"
6876
} }
6977

78+
# https://github.com/sphinx-doc/sphinx/issues/10785
79+
def resolve_type_aliases(app, env, node, contnode):
80+
"""Resolve :class: references to our type aliases as :attr: instead."""
81+
if (
82+
node["refdomain"] == "py"
83+
and node["reftype"] == "class"
84+
and node["reftarget"] in autodoc_type_aliases
85+
):
86+
return app.env.get_domain("py").resolve_xref(
87+
env, node["refdoc"], app.builder, "attr", node["reftarget"], node, contnode
88+
)
89+
7090
def autodoc_skip_member_handler(app, what, name, obj, skip, options):
7191
# Skip private members, i.e. those that start with double underscores but do not end in underscores
7292
if name.startswith("__") and not name.endswith("_"):
7393
return True
7494

75-
# Could be achieved using exclude-members, but this is more comfy
76-
if name in {
77-
"__abstractmethods__",
78-
"__dict__",
79-
"__module__",
80-
"__new__",
81-
"__weakref__",
82-
"_abc_impl"
83-
}: return True
95+
# Other fixed names to always skip
96+
if name in { "_abc_impl", "model_config" }:
97+
return True
8498

8599
# Skip __init__s without documentation. Those are just used for type hints.
86100
if name == "__init__" and obj.__doc__ is None:
@@ -90,3 +104,4 @@ def autodoc_skip_member_handler(app, what, name, obj, skip, options):
90104

91105
def setup(app):
92106
app.connect("autodoc-skip-member", autodoc_skip_member_handler)
107+
app.connect("missing-reference", resolve_type_aliases)

docs/doubleratchet/aead.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Module: aead
33

44
.. automodule:: doubleratchet.aead
55
:members:
6-
:special-members:
76
:private-members:
87
:undoc-members:
98
:member-order: bysource

docs/doubleratchet/diffie_hellman_ratchet.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Module: diffie_hellman_ratchet
33

44
.. automodule:: doubleratchet.diffie_hellman_ratchet
55
:members:
6-
:special-members:
76
:private-members:
87
:undoc-members:
98
:member-order: bysource

docs/doubleratchet/double_ratchet.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Module: double_ratchet
33

44
.. automodule:: doubleratchet.double_ratchet
55
:members:
6-
:special-members:
76
:private-members:
87
:undoc-members:
98
:member-order: bysource

docs/doubleratchet/kdf.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Module: kdf
33

44
.. automodule:: doubleratchet.kdf
55
:members:
6-
:special-members:
76
:private-members:
87
:undoc-members:
98
:member-order: bysource

docs/doubleratchet/kdf_chain.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Module: kdf_chain
33

44
.. automodule:: doubleratchet.kdf_chain
55
:members:
6-
:special-members:
76
:private-members:
87
:undoc-members:
98
:member-order: bysource

docs/doubleratchet/migrations.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Migrations between pydantic model versions, refer to :ref:`serialization_and_mig
55

66
.. automodule:: doubleratchet.migrations
77
:members:
8-
:special-members:
98
:private-members:
109
:undoc-members:
1110
:member-order: bysource

docs/doubleratchet/recommended/aead_aes_hmac.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Module: aead_aes_hmac
33

44
.. automodule:: doubleratchet.recommended.aead_aes_hmac
55
:members:
6-
:special-members:
76
:private-members:
87
:undoc-members:
98
:member-order: bysource

docs/doubleratchet/recommended/crypto_provider.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Module: crypto_provider
33

44
.. automodule:: doubleratchet.recommended.crypto_provider
55
:members:
6-
:special-members:
76
:private-members:
87
:undoc-members:
98
:member-order: bysource

docs/doubleratchet/recommended/crypto_provider_cryptography.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Module: crypto_provider_cryptography
33

44
.. automodule:: doubleratchet.recommended.crypto_provider_cryptography
55
:members:
6-
:special-members:
76
:private-members:
87
:undoc-members:
98
:member-order: bysource

0 commit comments

Comments
 (0)