Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e3776e9

Browse files
authored
DOC: Generate rcParams docs directly during build (#31028)
Using the extension from #28930, drop the static generated rcParams file, and move to a directive that gets generated on build. This avoids the table getting out of date as rcParams are changed. Note, that this also hides the private (`_`-prefixed) rcParams.
1 parent 2df0492 commit e3776e9

5 files changed

Lines changed: 42 additions & 1709 deletions

File tree

doc/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ def _parse_skip_subdirs_file():
132132
'sphinxext.math_symbol_table',
133133
'sphinxext.missing_references',
134134
'sphinxext.mock_gui_toolkits',
135-
'sphinxext.skip_deprecated',
135+
'sphinxext.rcparams',
136136
'sphinxext.redirect_from',
137+
'sphinxext.skip_deprecated',
137138
'sphinx_copybutton',
138139
'sphinx_design',
139140
'sphinx_tags',

doc/sphinxext/rcparams.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from docutils.parsers.rst import Directive
2+
3+
from matplotlib import rcsetup
4+
5+
6+
class RcParamsDirective(Directive):
7+
has_content = False
8+
required_arguments = 0
9+
optional_arguments = 0
10+
final_argument_whitespace = False
11+
option_spec = {}
12+
13+
def run(self):
14+
"""
15+
Generate rst documentation for rcParams.
16+
17+
Note: The style is very simple, but will be refined later.
18+
"""
19+
self.state.document.settings.env.note_dependency(__file__)
20+
self.state.document.settings.env.note_dependency(rcsetup.__file__)
21+
lines = []
22+
for param in rcsetup._params:
23+
if param.name[0] == '_':
24+
continue
25+
lines += [
26+
f'.. _rcparam_{param.name.replace(".", "_")}:',
27+
'',
28+
f'{param.name}: ``{param.default!r}``',
29+
f' {param.description if param.description else "*no description*"}'
30+
]
31+
self.state_machine.insert_input(lines, 'rcParams table')
32+
return []
33+
34+
35+
def setup(app):
36+
app.add_directive("rcparams", RcParamsDirective)
37+
38+
metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
39+
return metadata

0 commit comments

Comments
 (0)