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

Skip to content

Commit 81fe7ee

Browse files
committed
WIP: Add refs
1 parent 662bb8c commit 81fe7ee

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

doc/conf.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,33 @@ def _check_dependencies():
359359
}
360360

361361

362+
def append_attr_meth_examples(app, what, name, obj, options, lines):
363+
"""Append SG examples backreferences to method and attr docstrings."""
364+
# NumpyDoc nicely embeds method and attribute docstrings for us, but it
365+
# does not respect the autodoc templates that would otherwise insert
366+
# the .. include:: lines, so we need to do it.
367+
# Eventually this could perhaps live in SG.
368+
if what in ('attribute', 'method'):
369+
size = os.path.getsize(os.path.join(
370+
os.path.dirname(__file__), 'api', '_as_gen',
371+
'%s.examples' % (name,)))
372+
if size > 0:
373+
lines += """
374+
.. rubric:: Examples using ``{0}``:
375+
376+
.. include:: {1}.examples
377+
:start-line: 5
378+
379+
.. raw:: html
380+
381+
<div style="clear:both"></div>
382+
""".format(name.split('.')[-1], name).split('\n')
383+
384+
362385
def setup(app):
363386
if any(st in version for st in ('post', 'alpha', 'beta')):
364387
bld_type = 'dev'
365388
else:
366389
bld_type = 'rel'
367390
app.add_config_value('releaselevel', bld_type, 'env')
391+
app.connect('autodoc-process-docstring', append_attr_meth_examples)

0 commit comments

Comments
 (0)