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