##// END OF EJS Templates
Make each config option individually linkable
Thomas Kluyver -
Show More
@@ -0,0 +1,17 b''
1 """Directives and roles for documenting traitlets config options.
2
3 ::
4
5 .. configtrait:: Application.log_datefmt
6
7 Description goes here.
8
9 Cross reference like this: :configtrait:`Application.log_datefmt`.
10 """
11 from sphinx.locale import l_
12 from sphinx.util.docfields import Field
13
14 def setup(app):
15 app.add_object_type('configtrait', 'configtrait', objname='Config option')
16 metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
17 return metadata
@@ -76,7 +76,7 b' source/interactive/magics-generated.txt: autogen_magics.py'
76 76
77 77 autoconfig: source/config/options/config-generated.txt
78 78
79 source/config/options/config-generated.txt:
79 source/config/options/config-generated.txt: autogen_config.py
80 80 $(PYTHON) autogen_config.py
81 81 @echo "Created docs for config options"
82 82
@@ -4,11 +4,65 b' from os.path import join, dirname, abspath'
4 4
5 5 from IPython.terminal.ipapp import TerminalIPythonApp
6 6 from ipykernel.kernelapp import IPKernelApp
7 from traitlets import Undefined
7 8
8 9 here = abspath(dirname(__file__))
9 10 options = join(here, 'source', 'config', 'options')
10 11 generated = join(options, 'config-generated.txt')
11 12
13 from ipython_genutils.text import indent, dedent
14
15 def interesting_default_value(dv):
16 if (dv is None) or (dv is Undefined):
17 return False
18 if isinstance(dv, (str, list, tuple, dict, set)):
19 return bool(dv)
20 return True
21
22 def class_config_rst_doc(cls):
23 """Generate rST documentation for this class' config options.
24
25 Excludes traits defined on parent classes.
26 """
27 lines = []
28 classname = cls.__name__
29 for k, trait in sorted(cls.class_traits(config=True).items()):
30 ttype = trait.__class__.__name__
31
32 lines += ['.. configtrait:: ' + classname + '.' + trait.name,
33 ''
34 ]
35
36 help = trait.help.rstrip() or 'No description'
37 lines.append(indent(dedent(help), 4) + '\n')
38
39 # Choices or type
40 if 'Enum' in ttype:
41 # include Enum choices
42 lines.append(indent(
43 ':options: ' + ', '.join('``%r``' % x for x in trait.values), 4))
44 else:
45 lines.append(indent(':trait type: ' + ttype, 4))
46
47 # Default value
48 # Ignore boring default values like None, [] or ''
49 if interesting_default_value(trait.default_value):
50 try:
51 dvr = trait.default_value_repr()
52 except Exception:
53 dvr = None # ignore defaults we can't construct
54 if dvr is not None:
55 if len(dvr) > 64:
56 dvr = dvr[:61] + '...'
57 # Double up backslashes, so they get to the rendered docs
58 dvr = dvr.replace('\\n', '\\\\n')
59 lines.append(indent(':default: ``%s``' % dvr, 4))
60
61 # Blank line
62 lines.append('')
63
64 return '\n'.join(lines)
65
12 66
13 67 def write_doc(name, title, app, preamble=None):
14 68 filename = join(options, name+'.rst')
@@ -18,7 +72,11 b' def write_doc(name, title, app, preamble=None):'
18 72 f.write('\n')
19 73 if preamble is not None:
20 74 f.write(preamble + '\n\n')
21 f.write(app.document_config_options())
75 #f.write(app.document_config_options())
76
77 for c in app._classes_inc_parents():
78 f.write(class_config_rst_doc(c))
79 f.write('\n')
22 80
23 81
24 82 if __name__ == '__main__':
@@ -62,6 +62,7 b' extensions = ['
62 62 'sphinx.ext.napoleon', # to preprocess docstrings
63 63 'github', # for easy GitHub links
64 64 'magics',
65 'configtraits',
65 66 ]
66 67
67 68 if ON_RTD:
General Comments 0
You need to be logged in to leave comments. Login now