##// END OF EJS Templates
Various improvements to generating config docs
Thomas Kluyver -
Show More
@@ -1,90 +1,87 b''
1 1 #!/usr/bin/env python
2 2
3 from IPython.utils.text import indent, wrap_paragraphs
3 from IPython.utils.text import indent, dedent
4 4
5 5 from IPython.terminal.ipapp import TerminalIPythonApp
6 6 from IPython.kernel.zmq.kernelapp import IPKernelApp
7 7 from IPython.html.notebookapp import NotebookApp
8 8
9 9 def document_config_options(classes):
10 10 lines = []
11 11 for cls in classes:
12 12 classname = cls.__name__
13 13 for k, trait in sorted(cls.class_traits(config=True).items()):
14 14 ttype = trait.__class__.__name__
15 15
16 16 termline = classname + '.' + trait.name
17 17
18 18 # Choices or type
19 19 if 'Enum' in ttype:
20 20 # include Enum choices
21 21 termline += ' : ' + '|'.join(repr(x) for x in trait.values)
22 22 else:
23 23 termline += ' : ' + ttype
24 24 lines.append(termline)
25 25
26 26 # Default value
27 27 try:
28 28 dv = trait.get_default_value()
29 29 dvr = repr(dv)
30 30 except Exception:
31 31 dvr = dv = None # ignore defaults we can't construct
32 32 if (dv is not None) and (dvr is not None):
33 33 if len(dvr) > 64:
34 34 dvr = dvr[:61]+'...'
35 35 # Double up backslashes, so they get to the rendered docs
36 36 dvr = dvr.replace('\\n', '\\\\n')
37 lines.append(' Default: ' + dvr)
37 lines.append(' Default: `%s`' % dvr)
38 38 lines.append('')
39 39
40 40 help = trait.get_metadata('help')
41 41 if help is not None:
42 help = '\n\n'.join(wrap_paragraphs(help, 76))
43 lines.append(indent(help, 4))
42 lines.append(indent(dedent(help), 4))
44 43 else:
45 44 lines.append(' No description')
46 45
47 46 lines.append('')
48 47 return '\n'.join(lines)
49 48
50 49 kernel_classes = IPKernelApp().classes
51 50
52 51 def write_doc(name, title, classes, preamble=None):
53 52 configdoc = document_config_options(classes)
54 53 filename = '%s.rst' % name
55 54 with open('source/config/options/%s' % filename, 'w') as f:
56 55 f.write(title + '\n')
57 56 f.write(('=' * len(title)) + '\n')
58 57 f.write('\n')
59 58 if preamble is not None:
60 59 f.write(preamble + '\n\n')
61 60 f.write(configdoc)
62 61 with open('source/config/options/generated', 'a') as f:
63 62 f.write(filename + '\n')
64 63
65 64
66 65 if __name__ == '__main__':
67 66 # create empty file
68 67 with open('source/config/options/generated', 'w'):
69 68 pass
70 69
71 70 write_doc('terminal', 'Terminal IPython options', TerminalIPythonApp().classes)
72 71 write_doc('kernel', 'IPython kernel options', kernel_classes,
73 72 preamble="These options can be used in :file:`ipython_kernel_config.py`",
74 73 )
75 nbclasses = set(NotebookApp().classes) - set(kernel_classes)
76 write_doc('notebook', 'IPython notebook options', nbclasses,
74 write_doc('notebook', 'IPython notebook options', NotebookApp().classes,
77 75 preamble="To configure the IPython kernel, see :doc:`kernel`."
78 76 )
79 77
80 78 try:
81 79 from IPython.qt.console.qtconsoleapp import IPythonQtConsoleApp
82 80 except ImportError:
83 81 print("WARNING: Could not import qtconsoleapp. Config options for the "
84 82 "Qt Console will not be documented.")
85 83 else:
86 qtclasses = set(IPythonQtConsoleApp().classes) - set(kernel_classes)
87 write_doc('qtconsole', 'IPython Qt console options', qtclasses,
84 write_doc('qtconsole', 'IPython Qt console options', IPythonQtConsoleApp().classes,
88 85 preamble="To configure the IPython kernel, see :doc:`kernel`."
89 86 )
90 87
General Comments 0
You need to be logged in to leave comments. Login now