##// END OF EJS Templates
Merge pull request #6297 from takluyver/is-complete-request...
Merge pull request #6297 from takluyver/is-complete-request is_complete messages

File last commit:

r18030:1b4fb63d
r18369:d236bec1 merge
Show More
autogen_config.py
90 lines | 3.2 KiB | text/x-python | PythonLexer
/ docs / autogen_config.py
Yaroslav Halchenko
ENH: list generated config files in generated, and rm them upon clean
r16197 #!/usr/bin/env python
Thomas Kluyver
Generate docs for config options.
r13459 from IPython.utils.text import indent, wrap_paragraphs
from IPython.terminal.ipapp import TerminalIPythonApp
from IPython.kernel.zmq.kernelapp import IPKernelApp
from IPython.html.notebookapp import NotebookApp
def document_config_options(classes):
lines = []
for cls in classes:
classname = cls.__name__
for k, trait in sorted(cls.class_traits(config=True).items()):
ttype = trait.__class__.__name__
termline = classname + '.' + trait.name
# Choices or type
if 'Enum' in ttype:
# include Enum choices
termline += ' : ' + '|'.join(repr(x) for x in trait.values)
else:
termline += ' : ' + ttype
lines.append(termline)
# Default value
try:
dv = trait.get_default_value()
dvr = repr(dv)
except Exception:
dvr = dv = None # ignore defaults we can't construct
if (dv is not None) and (dvr is not None):
if len(dvr) > 64:
dvr = dvr[:61]+'...'
# Double up backslashes, so they get to the rendered docs
dvr = dvr.replace('\\n', '\\\\n')
lines.append(' Default: ' + dvr)
lines.append('')
help = trait.get_metadata('help')
if help is not None:
Thomas Kluyver
Fix some Sphinx warnings with autogenerated config docs
r13504 help = '\n\n'.join(wrap_paragraphs(help, 76))
Thomas Kluyver
Generate docs for config options.
r13459 lines.append(indent(help, 4))
else:
lines.append(' No description')
lines.append('')
return '\n'.join(lines)
kernel_classes = IPKernelApp().classes
Yaroslav Halchenko
ENH: list generated config files in generated, and rm them upon clean
r16197 def write_doc(name, title, classes, preamble=None):
Thomas Kluyver
Generate docs for config options.
r13459 configdoc = document_config_options(classes)
Yaroslav Halchenko
ENH: list generated config files in generated, and rm them upon clean
r16197 filename = '%s.rst' % name
with open('source/config/options/%s' % filename, 'w') as f:
Thomas Kluyver
Generate docs for config options.
r13459 f.write(title + '\n')
f.write(('=' * len(title)) + '\n')
f.write('\n')
if preamble is not None:
f.write(preamble + '\n\n')
f.write(configdoc)
Yaroslav Halchenko
ENH: list generated config files in generated, and rm them upon clean
r16197 with open('source/config/options/generated', 'a') as f:
f.write(filename + '\n')
Thomas Kluyver
Generate docs for config options.
r13459
if __name__ == '__main__':
Yaroslav Halchenko
ENH: list generated config files in generated, and rm them upon clean
r16197 # create empty file
with open('source/config/options/generated', 'w'):
pass
Thomas Kluyver
Generate docs for config options.
r13459 write_doc('terminal', 'Terminal IPython options', TerminalIPythonApp().classes)
write_doc('kernel', 'IPython kernel options', kernel_classes,
MinRK
remove references to kernel config in parent config files...
r18030 preamble="These options can be used in :file:`ipython_kernel_config.py`",
)
Thomas Kluyver
Generate docs for config options.
r13459 nbclasses = set(NotebookApp().classes) - set(kernel_classes)
write_doc('notebook', 'IPython notebook options', nbclasses,
MinRK
remove references to kernel config in parent config files...
r18030 preamble="To configure the IPython kernel, see :doc:`kernel`."
)
Thomas Kluyver
Allow docs to build without PyQt installed....
r13758
try:
from IPython.qt.console.qtconsoleapp import IPythonQtConsoleApp
except ImportError:
print("WARNING: Could not import qtconsoleapp. Config options for the "
"Qt Console will not be documented.")
else:
qtclasses = set(IPythonQtConsoleApp().classes) - set(kernel_classes)
write_doc('qtconsole', 'IPython Qt console options', qtclasses,
MinRK
remove references to kernel config in parent config files...
r18030 preamble="To configure the IPython kernel, see :doc:`kernel`."
)
Thomas Kluyver
Generate docs for config options.
r13459