summaryrefslogtreecommitdiff
path: root/sphinx/ext/apidoc.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-05-02 19:31:28 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2019-05-04 17:19:31 +0900
commitb482e38ca2e81b241b3c16f72d5df9296a267389 (patch)
treece0861f3bf06bccc8c070b8838b0f7c8f29794d3 /sphinx/ext/apidoc.py
parent035d5507f0cef2fd636bf90a08ff32a69f8a1cf6 (diff)
downloadsphinx-git-b482e38ca2e81b241b3c16f72d5df9296a267389.tar.gz
apidoc: Use a template for generating module file
Diffstat (limited to 'sphinx/ext/apidoc.py')
-rw-r--r--sphinx/ext/apidoc.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/sphinx/ext/apidoc.py b/sphinx/ext/apidoc.py
index 2d9a771d1..00c5fe8cc 100644
--- a/sphinx/ext/apidoc.py
+++ b/sphinx/ext/apidoc.py
@@ -28,6 +28,7 @@ from sphinx.cmd.quickstart import EXTENSIONS
from sphinx.locale import __
from sphinx.util import rst
from sphinx.util.osutil import FileAvoidWrite, ensuredir
+from sphinx.util.template import ReSTRenderer
if False:
# For type annotation
@@ -47,6 +48,8 @@ else:
INITPY = '__init__.py'
PY_SUFFIXES = {'.py', '.pyx'}
+template_dir = path.join(package_dir, 'templates', 'apidoc')
+
def makename(package, module):
# type: (str, str) -> str
@@ -94,16 +97,18 @@ def format_directive(module, package=None):
return directive
-def create_module_file(package, module, opts):
+def create_module_file(package, basename, opts):
# type: (str, str, Any) -> None
"""Build the text of the file and write the file."""
- if not opts.noheadings:
- text = format_heading(1, '%s module' % module)
- else:
- text = ''
- # text += format_heading(2, ':mod:`%s` Module' % module)
- text += format_directive(module, package)
- write_file(makename(package, module), text, opts)
+ qualname = makename(package, basename)
+ context = {
+ 'show_headings': not opts.noheadings,
+ 'basename': basename,
+ 'qualname': qualname,
+ 'automodule_options': OPTIONS,
+ }
+ text = ReSTRenderer(template_dir).render('module.rst', context)
+ write_file(qualname, text, opts)
def create_package_file(root, master_package, subroot, py_files, opts, subs, is_namespace, excludes=[]): # NOQA