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