##// END OF EJS Templates
Merge pull request #8484 from takluyver/docs-autogen-config-traitlets...
Matthias Bussonnier -
r21405:fe31d622 merge
parent child Browse files
Show More
@@ -1,54 +1,9 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2
2
3 from IPython.utils.text import indent, dedent
4
5 from IPython.terminal.ipapp import TerminalIPythonApp
3 from IPython.terminal.ipapp import TerminalIPythonApp
6 from IPython.kernel.zmq.kernelapp import IPKernelApp
4 from ipykernel.kernelapp import IPKernelApp
7
8 def document_config_options(classes):
9 lines = []
10 for cls in classes:
11 classname = cls.__name__
12 for k, trait in sorted(cls.class_traits(config=True).items()):
13 ttype = trait.__class__.__name__
14
15 termline = classname + '.' + trait.name
16
17 # Choices or type
18 if 'Enum' in ttype:
19 # include Enum choices
20 termline += ' : ' + '|'.join(repr(x) for x in trait.values)
21 else:
22 termline += ' : ' + ttype
23 lines.append(termline)
24
25 # Default value
26 try:
27 dv = trait.get_default_value()
28 dvr = repr(dv)
29 except Exception:
30 dvr = dv = None # ignore defaults we can't construct
31 if (dv is not None) and (dvr is not None):
32 if len(dvr) > 64:
33 dvr = dvr[:61]+'...'
34 # Double up backslashes, so they get to the rendered docs
35 dvr = dvr.replace('\\n', '\\\\n')
36 lines.append(' Default: `%s`' % dvr)
37 lines.append('')
38
39 help = trait.get_metadata('help')
40 if help is not None:
41 lines.append(indent(dedent(help), 4))
42 else:
43 lines.append(' No description')
44
45 lines.append('')
46 return '\n'.join(lines)
47
48 kernel_classes = IPKernelApp().classes
49
5
50 def write_doc(name, title, classes, preamble=None):
6 def write_doc(name, title, app, preamble=None):
51 configdoc = document_config_options(classes)
52 filename = '%s.rst' % name
7 filename = '%s.rst' % name
53 with open('source/config/options/%s' % filename, 'w') as f:
8 with open('source/config/options/%s' % filename, 'w') as f:
54 f.write(title + '\n')
9 f.write(title + '\n')
@@ -56,7 +11,7 b' def write_doc(name, title, classes, preamble=None):'
56 f.write('\n')
11 f.write('\n')
57 if preamble is not None:
12 if preamble is not None:
58 f.write(preamble + '\n\n')
13 f.write(preamble + '\n\n')
59 f.write(configdoc)
14 f.write(app.document_config_options())
60 with open('source/config/options/generated', 'a') as f:
15 with open('source/config/options/generated', 'a') as f:
61 f.write(filename + '\n')
16 f.write(filename + '\n')
62
17
@@ -66,8 +21,9 b" if __name__ == '__main__':"
66 with open('source/config/options/generated', 'w'):
21 with open('source/config/options/generated', 'w'):
67 pass
22 pass
68
23
69 write_doc('terminal', 'Terminal IPython options', TerminalIPythonApp().classes)
24 write_doc('terminal', 'Terminal IPython options', TerminalIPythonApp())
70 write_doc('kernel', 'IPython kernel options', kernel_classes,
25 write_doc('kernel', 'IPython kernel options', IPKernelApp(),
71 preamble="These options can be used in :file:`ipython_kernel_config.py`",
26 preamble=("These options can be used in :file:`ipython_kernel_config.py`. "
27 "The kernel also respects any options in `ipython_config.py`"),
72 )
28 )
73
29
General Comments 0
You need to be logged in to leave comments. Login now