-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Expand file tree
/
Copy pathrcparams.py
More file actions
50 lines (42 loc) · 1.62 KB
/
rcparams.py
File metadata and controls
50 lines (42 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from docutils.parsers.rst import Directive
from matplotlib import rcsetup
class RcParamsDirective(Directive):
has_content = False
required_arguments = 0
optional_arguments = 0
final_argument_whitespace = False
option_spec = {}
def run(self):
"""
Generate rst documentation for rcParams.
Note: The style is very simple, but will be refined later.
"""
self.state.document.settings.env.note_dependency(__file__)
self.state.document.settings.env.note_dependency(rcsetup.__file__)
lines = []
for elem in rcsetup._DEFINITION:
if isinstance(elem, (rcsetup._Section, rcsetup._Subsection)):
title_char = '-' if isinstance(elem, rcsetup._Section) else '~'
lines += [
'',
elem.title,
title_char * len(elem.title),
'',
elem.description or "",
'',
]
elif isinstance(elem, rcsetup._Param):
if elem.name[0] == '_':
continue
lines += [
f'.. _rcparam_{elem.name.replace(".", "_")}:',
'',
f'{elem.name}: ``{elem.default!r}``',
f' {elem.description if elem.description else "*no description*"}'
]
self.state_machine.insert_input(lines, 'rcParams table')
return []
def setup(app):
app.add_directive("rcparams", RcParamsDirective)
metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
return metadata