Skip to content

Commit 5bba490

Browse files
MortGronhaakonvt
andauthored
docs: improve readability of API method signatures (#2460)
Co-authored-by: Håkon V. Treider <haakonvt@gmail.com>
1 parent 09ae7b4 commit 5bba490

4 files changed

Lines changed: 149 additions & 103 deletions

File tree

docs/source/_static/css/custom.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* Source: https://github.com/readthedocs/sphinx_rtd_theme/issues/1529#issuecomment-1918561608*/
2+
3+
/* Take out pointless vertical whitespace in the signatures. */
4+
.rst-content dl .sig dl,
5+
.rst-content dl .sig dd {
6+
margin-bottom: 0;
7+
}
8+
9+
/* Make signature boxes full-width, with view-source and header links right-aligned. */
10+
.rst-content dl .sig {
11+
width: -webkit-fill-available;
12+
}
13+
.rst-content .viewcode-link {
14+
display: inline-flex;
15+
float: inline-end;
16+
margin-right: 1.5em;
17+
}
18+
.rst-content .headerlink {
19+
position: absolute;
20+
right: 0.5em;
21+
}

docs/source/conf.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
# If your documentation needs a minimal Sphinx version, state it here.
2525
#
26-
# needs_sphinx = '1.0'
26+
needs_sphinx = "7.2"
2727

2828
# Add any Sphinx extension module names here, as strings. They can be
2929
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
@@ -93,7 +93,8 @@
9393
# Add any paths that contain custom _static files (such as style sheets) here,
9494
# relative to this directory. They are copied after the builtin _static files,
9595
# so a file named "default.css" will overwrite the builtin "default.css".
96-
html_static_path = []
96+
html_static_path = ["_static"]
97+
html_css_files = ["css/custom.css"]
9798

9899
# Custom sidebar templates, must be a dictionary that maps document names
99100
# to template names.
@@ -159,3 +160,22 @@
159160
"Miscellaneous",
160161
)
161162
]
163+
164+
python_maximum_signature_line_length = 80
165+
166+
# Patch Sphinx to hide @overload signatures in docs
167+
# Sphinx's autodoc uses ModuleAnalyzer.overloads via the parser
168+
# We patch the analyze method to clear overloads after parsing
169+
# To see why, check out https://github.com/cognitedata/cognite-sdk-python/pull/2460
170+
from sphinx.pycode import ModuleAnalyzer # noqa: E402
171+
172+
analyze_fn = ModuleAnalyzer.analyze
173+
174+
175+
def analyze_but_skip_overloads(self):
176+
result = analyze_fn(self)
177+
self.overloads = {} # Clear overloads after analysis
178+
return result
179+
180+
181+
ModuleAnalyzer.analyze = analyze_but_skip_overloads

0 commit comments

Comments
 (0)