Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6802677

Browse files
committed
Generate docs for config options.
1 parent b144aa8 commit 6802677

5 files changed

Lines changed: 96 additions & 3 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ dist
44
_build
55
docs/man/*.gz
66
docs/source/api/generated
7+
docs/source/config/options
78
docs/gh-pages
89
IPython/html/notebook/static/mathjax
910
*.py[co]

docs/Makefile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ clean_api:
4040

4141
clean: clean_api
4242
-rm -rf build/* dist/*
43+
-rm -rf $(SRCDIR)/config/options/generated
4344

4445
pdf: latex
4546
cd build/latex && make all-pdf
@@ -56,15 +57,21 @@ dist: html
5657
cp -al build/html .
5758
@echo "Build finished. Final docs are in html/"
5859

59-
html: api
60-
html_noapi: clean_api
60+
html: api autoconfig
61+
html_noapi: clean_api autoconfig
6162

6263
html html_noapi:
6364
mkdir -p build/html build/doctrees
6465
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) build/html
6566
@echo
6667
@echo "Build finished. The HTML pages are in build/html."
6768

69+
autoconfig: source/config/options/generated
70+
71+
source/config/options/generated:
72+
python autogen_config.py
73+
@echo "Created docs for config options"
74+
6875
api: source/api/generated/gen.txt
6976

7077
source/api/generated/gen.txt:
@@ -98,7 +105,7 @@ qthelp:
98105
@echo "To view the help file:"
99106
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/IPython.qhc"
100107

101-
latex: api
108+
latex: api autoconfig
102109
mkdir -p build/latex build/doctrees
103110
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) build/latex
104111
@echo

docs/autogen_config.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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

docs/source/config/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Configuration and customization
88
:maxdepth: 2
99

1010
overview
11+
options/index
1112
extensions/index
1213
ipython
1314
integrating
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
===============
2+
IPython options
3+
===============
4+
5+
.. toctree::
6+
7+
terminal
8+
kernel
9+
notebook
10+
qtconsole

0 commit comments

Comments
 (0)