Deprecate config value: source_parsers

This commit is contained in:
Takeshi KOMIYA 2017-10-30 13:46:12 +09:00
parent f886f08cb2
commit dc45877d3c
6 changed files with 59 additions and 6 deletions

View File

@ -10,6 +10,9 @@ Incompatible changes
Deprecated Deprecated
---------- ----------
* :confval:`source_parsers` is deprecated. Please use ``add_source_parser()``
instead.
Features added Features added
-------------- --------------

View File

@ -123,6 +123,10 @@ General configuration
.. versionadded:: 1.3 .. versionadded:: 1.3
.. deprecated:: 1.8
Now Sphinx provides an API :meth:`Sphinx.add_source_parser` to register
a source parser. Please use it instead.
.. confval:: master_doc .. confval:: master_doc
The document name of the "master" document, that is, the document that The document name of the "master" document, that is, the document that

View File

@ -92,6 +92,7 @@ builtin_extensions = (
'sphinx.roles', 'sphinx.roles',
'sphinx.transforms.post_transforms', 'sphinx.transforms.post_transforms',
'sphinx.transforms.post_transforms.images', 'sphinx.transforms.post_transforms.images',
'sphinx.util.compat',
# collectors should be loaded by specific order # collectors should be loaded by specific order
'sphinx.environment.collectors.dependencies', 'sphinx.environment.collectors.dependencies',
'sphinx.environment.collectors.asset', 'sphinx.environment.collectors.asset',
@ -287,8 +288,6 @@ class Sphinx(object):
def _init_source_parsers(self): def _init_source_parsers(self):
# type: () -> None # type: () -> None
for suffix, parser in iteritems(self.config.source_parsers):
self.add_source_parser(suffix, parser)
for suffix, parser in iteritems(self.registry.get_source_parsers()): for suffix, parser in iteritems(self.registry.get_source_parsers()):
if suffix not in self.config.source_suffix and suffix != '*': if suffix not in self.config.source_suffix and suffix != '*':
self.config.source_suffix.append(suffix) self.config.source_suffix.append(suffix)

View File

@ -22,4 +22,8 @@ class RemovedInSphinx20Warning(PendingDeprecationWarning):
pass pass
class RemovedInSphinx30Warning(PendingDeprecationWarning):
pass
RemovedInNextVersionWarning = RemovedInSphinx18Warning RemovedInNextVersionWarning = RemovedInSphinx18Warning

View File

@ -13,7 +13,7 @@ from __future__ import print_function
import traceback import traceback
from pkg_resources import iter_entry_points from pkg_resources import iter_entry_points
from six import iteritems, itervalues, string_types from six import iteritems, itervalues
from sphinx.errors import ExtensionError, SphinxError, VersionRequirementError from sphinx.errors import ExtensionError, SphinxError, VersionRequirementError
from sphinx.extension import Extension from sphinx.extension import Extension
@ -23,7 +23,6 @@ from sphinx.locale import __
from sphinx.parsers import Parser as SphinxParser from sphinx.parsers import Parser as SphinxParser
from sphinx.roles import XRefRole from sphinx.roles import XRefRole
from sphinx.util import logging from sphinx.util import logging
from sphinx.util import import_object
from sphinx.util.console import bold # type: ignore from sphinx.util.console import bold # type: ignore
from sphinx.util.docutils import directive_helper from sphinx.util.docutils import directive_helper
@ -216,8 +215,6 @@ class SphinxComponentRegistry(object):
if parser_class is None: if parser_class is None:
raise SphinxError(__('Source parser for %s not registered') % filename) raise SphinxError(__('Source parser for %s not registered') % filename)
else: else:
if isinstance(parser_class, string_types):
parser_class = import_object(parser_class, 'source parser') # type: ignore
return parser_class return parser_class
def get_source_parsers(self): def get_source_parsers(self):

46
sphinx/util/compat.py Normal file
View File

@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
"""
sphinx.util.compat
~~~~~~~~~~~~~~~~~~
modules for backward compatibility
:copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import warnings
from six import string_types, iteritems
from sphinx.deprecation import RemovedInSphinx30Warning
from sphinx.util import import_object
if False:
# For type annotation
from typing import Any, Dict # NOQA
from sphinx.application import Sphinx # NOQA
from sphinx.config import Config # NOQA
def deprecate_source_parsers(app, config):
# type: (Sphinx, Config) -> None
if config.source_parsers:
warnings.warn('The config variable "source_parsers" is deprecated. '
'Please use app.add_source_parser() API instead.',
RemovedInSphinx30Warning)
for suffix, parser in iteritems(config.source_parsers):
if isinstance(parser, string_types):
parser = import_object(parser, 'source parser') # type: ignore
app.add_source_parser(suffix, parser)
def setup(app):
# type: (Sphinx) -> Dict[unicode, Any]
app.connect('config-inited', deprecate_source_parsers)
return {
'version': 'builtin',
'parallel_read_safe': True,
'parallel_write_safe': True,
}