1+ from IPython .utils .text import indent , wrap_paragraphs
2+
3+ from IPython .terminal .ipapp import TerminalIPythonApp
4+ from IPython .kernel .zmq .kernelapp import IPKernelApp
5+ from IPython .html .notebookapp import NotebookApp
6+ from IPython .qt .console .qtconsoleapp import IPythonQtConsoleApp
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: ' + dvr )
37+ lines .append ('' )
38+
39+ help = trait .get_metadata ('help' )
40+ if help is not None :
41+ help = '\n ' .join (wrap_paragraphs (help , 76 ))
42+ lines .append (indent (help , 4 ))
43+ else :
44+ lines .append (' No description' )
45+
46+ lines .append ('' )
47+ return '\n ' .join (lines )
48+
49+ kernel_classes = IPKernelApp ().classes
50+
51+ def write_doc (filename , title , classes , preamble = None ):
52+ configdoc = document_config_options (classes )
53+ with open ('source/config/options/%s.rst' % filename , 'w' ) as f :
54+ f .write (title + '\n ' )
55+ f .write (('=' * len (title )) + '\n ' )
56+ f .write ('\n ' )
57+ if preamble is not None :
58+ f .write (preamble + '\n \n ' )
59+ f .write (configdoc )
60+
61+ if __name__ == '__main__' :
62+ write_doc ('terminal' , 'Terminal IPython options' , TerminalIPythonApp ().classes )
63+ write_doc ('kernel' , 'IPython kernel options' , kernel_classes ,
64+ preamble = "These options can be used in :file:`ipython_notebook_config.py` "
65+ "or in :file:`ipython_qtconsole_config.py`" )
66+ nbclasses = set (NotebookApp ().classes ) - set (kernel_classes )
67+ write_doc ('notebook' , 'IPython notebook options' , nbclasses ,
68+ 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." )
72+
73+ with open ('source/config/options/generated' , 'w' ):
74+ pass
0 commit comments