diff options
-rw-r--r-- | sphinx/apidoc.py | 10 | ||||
-rw-r--r-- | tests/test_apidoc.py | 13 |
2 files changed, 23 insertions, 0 deletions
diff --git a/sphinx/apidoc.py b/sphinx/apidoc.py index 0fca17d81..11d2994ef 100644 --- a/sphinx/apidoc.py +++ b/sphinx/apidoc.py @@ -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): diff --git a/tests/test_apidoc.py b/tests/test_apidoc.py index d44868aeb..7e6c4fd0a 100644 --- a/tests/test_apidoc.py +++ b/tests/test_apidoc.py @@ -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 |