mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
autosummary: generate stub pages recursively
This commit is contained in:
parent
c48e1b919e
commit
9043aeb723
@ -221,5 +221,5 @@ The following variables available in the templates:
|
|||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
You can use the :dir:`autosummary` directive in the stub pages. However,
|
You can use the :dir:`autosummary` directive in the stub pages.
|
||||||
stub pages are not generated automatically recursively.
|
Stub pages are generated also based on these directives.
|
||||||
|
@ -94,6 +94,9 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
|
|||||||
# remove possible duplicates
|
# remove possible duplicates
|
||||||
items = dict([(item, True) for item in items]).keys()
|
items = dict([(item, True) for item in items]).keys()
|
||||||
|
|
||||||
|
# keep track of new files
|
||||||
|
new_files = []
|
||||||
|
|
||||||
# write
|
# write
|
||||||
for name, path, template_name in sorted(items):
|
for name, path, template_name in sorted(items):
|
||||||
if path is None:
|
if path is None:
|
||||||
@ -116,6 +119,8 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
|
|||||||
if os.path.isfile(fn):
|
if os.path.isfile(fn):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
new_files.append(fn)
|
||||||
|
|
||||||
f = open(fn, 'w')
|
f = open(fn, 'w')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -139,21 +144,21 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
|
|||||||
if x in include_public or not x.startswith('_')]
|
if x in include_public or not x.startswith('_')]
|
||||||
return public, items
|
return public, items
|
||||||
|
|
||||||
info = {}
|
ns = {}
|
||||||
|
|
||||||
if doc.objtype == 'module':
|
if doc.objtype == 'module':
|
||||||
info['members'] = dir(obj)
|
ns['members'] = dir(obj)
|
||||||
info['functions'], info['all_functions'] = \
|
ns['functions'], ns['all_functions'] = \
|
||||||
get_members(obj, 'function')
|
get_members(obj, 'function')
|
||||||
info['classes'], info['all_classes'] = \
|
ns['classes'], ns['all_classes'] = \
|
||||||
get_members(obj, 'class')
|
get_members(obj, 'class')
|
||||||
info['exceptions'], info['all_exceptions'] = \
|
ns['exceptions'], ns['all_exceptions'] = \
|
||||||
get_members(obj, 'exception')
|
get_members(obj, 'exception')
|
||||||
elif doc.objtype == 'class':
|
elif doc.objtype == 'class':
|
||||||
info['members'] = dir(obj)
|
ns['members'] = dir(obj)
|
||||||
info['methods'], info['all_methods'] = \
|
ns['methods'], ns['all_methods'] = \
|
||||||
get_members(obj, 'method', ['__init__'])
|
get_members(obj, 'method', ['__init__'])
|
||||||
info['attributes'], info['all_attributes'] = \
|
ns['attributes'], ns['all_attributes'] = \
|
||||||
get_members(obj, 'attribute')
|
get_members(obj, 'attribute')
|
||||||
|
|
||||||
parts = name.split('.')
|
parts = name.split('.')
|
||||||
@ -161,23 +166,30 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
|
|||||||
mod_name = '.'.join(parts[:-2])
|
mod_name = '.'.join(parts[:-2])
|
||||||
cls_name = parts[-2]
|
cls_name = parts[-2]
|
||||||
obj_name = '.'.join(parts[-2:])
|
obj_name = '.'.join(parts[-2:])
|
||||||
info['class'] = cls_name
|
ns['class'] = cls_name
|
||||||
else:
|
else:
|
||||||
mod_name, obj_name = '.'.join(parts[:-1]), parts[-1]
|
mod_name, obj_name = '.'.join(parts[:-1]), parts[-1]
|
||||||
|
|
||||||
info['fullname'] = name
|
ns['fullname'] = name
|
||||||
info['module'] = mod_name
|
ns['module'] = mod_name
|
||||||
info['objname'] = obj_name
|
ns['objname'] = obj_name
|
||||||
info['name'] = parts[-1]
|
ns['name'] = parts[-1]
|
||||||
|
|
||||||
info['objtype'] = doc.objtype
|
ns['objtype'] = doc.objtype
|
||||||
info['underline'] = len(name) * '='
|
ns['underline'] = len(name) * '='
|
||||||
|
|
||||||
rendered = template.render(**info)
|
rendered = template.render(**ns)
|
||||||
f.write(rendered)
|
f.write(rendered)
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
# descend recursively to new files
|
||||||
|
if new_files:
|
||||||
|
generate_autosummary_docs(new_files, output_dir=output_dir,
|
||||||
|
suffix=suffix, warn=warn, info=info,
|
||||||
|
base_path=base_path, builder=builder,
|
||||||
|
template_dir=template_dir)
|
||||||
|
|
||||||
|
|
||||||
# -- Finding documented entries in files ---------------------------------------
|
# -- Finding documented entries in files ---------------------------------------
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user