Merge pull request #3323 from gbaier/apidoc_extensions

apidoc takes extension options
This commit is contained in:
Takeshi KOMIYA 2017-01-12 23:42:56 +09:00 committed by GitHub
commit 81a4248df9
2 changed files with 23 additions and 0 deletions

View File

@ -25,6 +25,7 @@ from fnmatch import fnmatch
from sphinx.util.osutil import FileAvoidWrite, walk
from sphinx import __display_version__
from sphinx.quickstart import EXTENSIONS
if False:
# For type annotation
@ -346,6 +347,11 @@ Note: By default this script will not overwrite already created files.""")
'defaults to --doc-version')
parser.add_option('--version', action='store_true', dest='show_version',
help='Show version information and exit')
group = parser.add_option_group('Extension options')
for ext in EXTENSIONS:
group.add_option('--ext-' + ext, action='store_true',
dest='ext_' + ext, default=False,
help='enable %s extension' % ext)
(opts, args) = parser.parse_args(argv[1:])
@ -404,6 +410,10 @@ Note: By default this script will not overwrite already created files.""")
module_path = rootpath,
append_syspath = opts.append_syspath,
)
enabled_exts = {'ext_' + ext: getattr(opts, 'ext_' + ext)
for ext in EXTENSIONS if getattr(opts, 'ext_' + ext)}
d.update(enabled_exts)
if isinstance(opts.header, binary_type):
d['project'] = d['project'].decode('utf-8')
if isinstance(opts.author, binary_type):

View File

@ -145,3 +145,16 @@ def test_multibyte_parameters(make_app, apidoc):
app.build()
print(app._status.getvalue())
print(app._warning.getvalue())
@pytest.mark.apidoc(
coderoot=(rootdir / 'root'),
options=['--ext-mathjax'],
)
def test_extension_parsed(make_app, apidoc):
outdir = apidoc.outdir
assert (outdir / 'conf.py').isfile()
with open(outdir / 'conf.py') as f:
rst = f.read()
assert "sphinx.ext.mathjax" in rst