Show More
@@ -1,54 +1,9 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | |
|
3 | from IPython.utils.text import indent, dedent | |
|
4 | ||
|
5 | 3 | from IPython.terminal.ipapp import TerminalIPythonApp |
|
6 |
from |
|
|
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 | |
|
4 | from ipykernel.kernelapp import IPKernelApp | |
|
49 | 5 | |
|
50 |
def write_doc(name, title, |
|
|
51 | configdoc = document_config_options(classes) | |
|
6 | def write_doc(name, title, app, preamble=None): | |
|
52 | 7 | filename = '%s.rst' % name |
|
53 | 8 | with open('source/config/options/%s' % filename, 'w') as f: |
|
54 | 9 | f.write(title + '\n') |
@@ -56,7 +11,7 b' def write_doc(name, title, classes, preamble=None):' | |||
|
56 | 11 | f.write('\n') |
|
57 | 12 | if preamble is not None: |
|
58 | 13 | f.write(preamble + '\n\n') |
|
59 |
f.write(config |
|
|
14 | f.write(app.document_config_options()) | |
|
60 | 15 | with open('source/config/options/generated', 'a') as f: |
|
61 | 16 | f.write(filename + '\n') |
|
62 | 17 | |
@@ -66,8 +21,9 b" if __name__ == '__main__':" | |||
|
66 | 21 | with open('source/config/options/generated', 'w'): |
|
67 | 22 | pass |
|
68 | 23 | |
|
69 |
write_doc('terminal', 'Terminal IPython options', TerminalIPythonApp() |
|
|
70 |
write_doc('kernel', 'IPython kernel options', |
|
|
71 |
preamble="These options can be used in :file:`ipython_kernel_config.py`" |
|
|
24 | write_doc('terminal', 'Terminal IPython options', TerminalIPythonApp()) | |
|
25 | write_doc('kernel', 'IPython kernel options', IPKernelApp(), | |
|
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