Rename viewcode_import to viewcode_follow_imported_members (refs: #4035)

This commit is contained in:
Takeshi KOMIYA 2018-04-02 12:32:07 +09:00
parent 3fdef7ec62
commit fad03ea050
5 changed files with 31 additions and 10 deletions

View File

@ -29,6 +29,8 @@ Incompatible changes
* #4811: The files under :confval:`html_static_path` are excluded from source * #4811: The files under :confval:`html_static_path` are excluded from source
files. files.
* latex: Use ``\sphinxcite`` for citation references instead ``\hyperref`` * latex: Use ``\sphinxcite`` for citation references instead ``\hyperref``
* The config value ``viewcode_import`` is renamed to
:confval:`viewcode_follow_imported_members` (refs: #4035)
Deprecated Deprecated
---------- ----------

View File

@ -17,12 +17,11 @@ from the source to the description will also be inserted.
.. warning:: .. warning::
If :confval:`viewcode_import` is True, If :confval:`viewcode_follow_imported_members` is True, or if the
or if the :event:`viewcode-find-source` event does not find source code :event:`viewcode-find-source` event does not find source code for the given
for the given module, module, ``viewcode`` will import the modules being linked to. If any modules
``viewcode`` will import the modules being linked to. have side effects on import, these will be executed by ``viewcode`` when
If any modules have side effects on import, these will be ``sphinx-build`` is run.
executed by ``viewcode`` when ``sphinx-build`` is run.
If you document scripts (as opposed to library modules), make sure their If you document scripts (as opposed to library modules), make sure their
main routine is protected by a ``if __name__ == '__main__'`` condition. main routine is protected by a ``if __name__ == '__main__'`` condition.
@ -34,7 +33,7 @@ support this extension (see :confval:`viewcode_enable_epub`).
There is an additional config value: There is an additional config value:
.. confval:: viewcode_import .. confval:: viewcode_follow_imported_members
If this is ``True``, viewcode extension will follow alias objects that If this is ``True``, viewcode extension will follow alias objects that
imported from another module such as functions, classes and attributes. imported from another module such as functions, classes and attributes.
@ -43,6 +42,9 @@ There is an additional config value:
.. versionadded:: 1.3 .. versionadded:: 1.3
.. versionchanged:: 1.8
Renamed from ``viewcode_import`` to ``viewcode_follow_imported_members``.
.. confval:: viewcode_enable_epub .. confval:: viewcode_enable_epub
If this is ``True``, viewcode extension is also enabled even if you use If this is ``True``, viewcode extension is also enabled even if you use

View File

@ -126,6 +126,11 @@ The following is a list of deprecated interface.
- 4.0 - 4.0
- :meth:`~sphinx.application.Sphinx.add_css_file()` - :meth:`~sphinx.application.Sphinx.add_css_file()`
* - ``viewcode_import`` (config value)
- 1.8
- 3.0
- :confval:`viewcode_follow_imported_members`
* - ``sphinx.writers.latex.Table.caption_footnotetexts`` * - ``sphinx.writers.latex.Table.caption_footnotetexts``
- 1.8 - 1.8
- 3.0 - 3.0

View File

@ -10,12 +10,14 @@
""" """
import traceback import traceback
import warnings
from docutils import nodes from docutils import nodes
from six import iteritems, text_type from six import iteritems, text_type
import sphinx import sphinx
from sphinx import addnodes from sphinx import addnodes
from sphinx.deprecation import RemovedInSphinx30Warning
from sphinx.locale import _ from sphinx.locale import _
from sphinx.pycode import ModuleAnalyzer from sphinx.pycode import ModuleAnalyzer
from sphinx.util import get_full_modname, logging, status_iterator from sphinx.util import get_full_modname, logging, status_iterator
@ -25,6 +27,7 @@ if False:
# For type annotation # For type annotation
from typing import Any, Dict, Iterable, Iterator, Set, Tuple # NOQA from typing import Any, Dict, Iterable, Iterator, Set, Tuple # NOQA
from sphinx.application import Sphinx # NOQA from sphinx.application import Sphinx # NOQA
from sphinx.config import Config # NOQA
from sphinx.environment import BuildEnvironment # NOQA from sphinx.environment import BuildEnvironment # NOQA
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -100,7 +103,7 @@ def doctree_read(app, doctree):
modname = signode.get('module') modname = signode.get('module')
fullname = signode.get('fullname') fullname = signode.get('fullname')
refname = modname refname = modname
if env.config.viewcode_import: if env.config.viewcode_follow_imported_members:
modname = _get_full_modname(app, modname, fullname) modname = _get_full_modname(app, modname, fullname)
if not modname: if not modname:
continue continue
@ -239,10 +242,19 @@ def collect_pages(app):
yield ('_modules/index', context, 'page.html') yield ('_modules/index', context, 'page.html')
def migrate_viewcode_import(app, config):
# type: (Sphinx, Config) -> None
if config.viewcode_import is not None:
warnings.warn('viewcode_import was renamed to viewcode_follow_imported_members. '
'Please update your configuration.',
RemovedInSphinx30Warning)
def setup(app): def setup(app):
# type: (Sphinx) -> Dict[unicode, Any] # type: (Sphinx) -> Dict[unicode, Any]
app.add_config_value('viewcode_import', True, False) app.add_config_value('viewcode_import', None, False)
app.add_config_value('viewcode_enable_epub', False, False) app.add_config_value('viewcode_enable_epub', False, False)
app.add_config_value('viewcode_follow_imported_members', True, False)
app.connect('doctree-read', doctree_read) app.connect('doctree-read', doctree_read)
app.connect('env-merge-info', env_merge_info) app.connect('env-merge-info', env_merge_info)
app.connect('html-collect-pages', collect_pages) app.connect('html-collect-pages', collect_pages)

View File

@ -6,4 +6,4 @@ import sys
extensions = ['sphinx.ext.viewcode'] extensions = ['sphinx.ext.viewcode']
master_doc = 'index' master_doc = 'index'
exclude_patterns = ['_build'] exclude_patterns = ['_build']
viewcode_import = False viewcode_follow_imported_members = False