Add `--extensions to sphinx-quickstart` to support enable arbitary extensions from command line (ref: #2904)

This commit is contained in:
Takeshi KOMIYA
2016-11-02 11:11:15 +09:00
parent a759e5eae7
commit ae1f523d52
4 changed files with 34 additions and 8 deletions

View File

@@ -11,6 +11,8 @@ Features added
* #3096: ``'maxlistdepth'`` key to work around LaTeX list limitations
* #3060: autodoc supports documentation for attributes of Enum class. Now autodoc render
just the value of Enum attributes instead of Enum attribute representation.
* Add ``--extensions`` to ``sphinx-quickstart`` to support enable arbitary
extensions from command line (ref: #2904)
Bugs fixed
----------

View File

@@ -118,6 +118,10 @@ Extension options
Enable `sphinx.ext.viewcode` extension.
.. option:: --extensions=EXTENSIONS
Enable arbitary extensions.
Makefile and Batchfile creation options
---------------------------------------

View File

@@ -388,14 +388,11 @@ def generate(d, overwrite=True, silent=False, templatedir=None):
d['project_manpage'] = d['project_fn'].lower()
d['now'] = time.asctime()
d['project_underline'] = column_width(d['project']) * '='
extensions = (',\n' + indent).join(
repr('sphinx.ext.' + name)
for name in EXTENSIONS
if d.get('ext_' + name))
if extensions:
d['extensions'] = '\n' + indent + extensions + ',\n'
else:
d['extensions'] = extensions
d.setdefault('extensions', [])
for name in EXTENSIONS:
if d.get('ext_' + name):
d['extensions'].append('sphinx.ext.' + name)
d['extensions'] = (',\n' + indent).join(repr(name) for name in d['extensions'])
d['copyright'] = time.strftime('%Y') + ', ' + d['author']
d['author_texescaped'] = text_type(d['author']).\
translate(texescape.tex_escape_map)
@@ -581,6 +578,8 @@ def main(argv=sys.argv):
group.add_option('--ext-' + ext, action='store_true',
dest='ext_' + ext, default=False,
help='enable %s extension' % ext)
group.add_option('--extensions', metavar='EXTENSIONS', dest='extensions',
action='append', help='enable extensions')
group = parser.add_option_group('Makefile and Batchfile creation')
group.add_option('--makefile', action='store_true', dest='makefile',
@@ -659,6 +658,14 @@ def main(argv=sys.argv):
if isinstance(value, binary_type):
d[key] = term_decode(value)
# parse extensions list
d.setdefault('extensions', [])
for ext in d['extensions'][:]:
if ',' in ext:
d['extensions'].remove(ext)
for modname in ext.split(','):
d['extensions'].append(modname)
for variable in d.get('variables', []):
try:
name, value = variable.split('=')

View File

@@ -298,3 +298,16 @@ def test_default_filename(tempdir):
assert ns['latex_documents'][0][1] == 'sphinx.tex'
assert ns['man_pages'][0][1] == 'sphinx'
assert ns['texinfo_documents'][0][1] == 'sphinx'
@with_tempdir
def test_extensions(tempdir):
qs.main(['sphinx-quickstart', '-q',
'-p', 'project_name', '-a', 'author',
'--extensions', 'foo,bar,baz', tempdir])
conffile = tempdir / 'conf.py'
assert conffile.isfile()
ns = {}
execfile_(conffile, ns)
assert ns['extensions'] == ['foo', 'bar', 'baz']