Skip to content

Commit dc45877

Browse files
committed
Deprecate config value: source_parsers
1 parent f886f08 commit dc45877

File tree

6 files changed

+59
-6
lines changed

6 files changed

+59
-6
lines changed

CHANGES

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Incompatible changes
1010
Deprecated
1111
----------
1212

13+
* :confval:`source_parsers` is deprecated. Please use ``add_source_parser()``
14+
instead.
15+
1316
Features added
1417
--------------
1518

doc/config.rst

+4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ General configuration
123123

124124
.. versionadded:: 1.3
125125

126+
.. deprecated:: 1.8
127+
Now Sphinx provides an API :meth:`Sphinx.add_source_parser` to register
128+
a source parser. Please use it instead.
129+
126130
.. confval:: master_doc
127131

128132
The document name of the "master" document, that is, the document that

sphinx/application.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
'sphinx.roles',
9393
'sphinx.transforms.post_transforms',
9494
'sphinx.transforms.post_transforms.images',
95+
'sphinx.util.compat',
9596
# collectors should be loaded by specific order
9697
'sphinx.environment.collectors.dependencies',
9798
'sphinx.environment.collectors.asset',
@@ -287,8 +288,6 @@ def _init_i18n(self):
287288

288289
def _init_source_parsers(self):
289290
# type: () -> None
290-
for suffix, parser in iteritems(self.config.source_parsers):
291-
self.add_source_parser(suffix, parser)
292291
for suffix, parser in iteritems(self.registry.get_source_parsers()):
293292
if suffix not in self.config.source_suffix and suffix != '*':
294293
self.config.source_suffix.append(suffix)

sphinx/deprecation.py

+4
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ class RemovedInSphinx20Warning(PendingDeprecationWarning):
2222
pass
2323

2424

25+
class RemovedInSphinx30Warning(PendingDeprecationWarning):
26+
pass
27+
28+
2529
RemovedInNextVersionWarning = RemovedInSphinx18Warning

sphinx/registry.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import traceback
1414

1515
from pkg_resources import iter_entry_points
16-
from six import iteritems, itervalues, string_types
16+
from six import iteritems, itervalues
1717

1818
from sphinx.errors import ExtensionError, SphinxError, VersionRequirementError
1919
from sphinx.extension import Extension
@@ -23,7 +23,6 @@
2323
from sphinx.parsers import Parser as SphinxParser
2424
from sphinx.roles import XRefRole
2525
from sphinx.util import logging
26-
from sphinx.util import import_object
2726
from sphinx.util.console import bold # type: ignore
2827
from sphinx.util.docutils import directive_helper
2928

@@ -216,8 +215,6 @@ def get_source_parser(self, filename):
216215
if parser_class is None:
217216
raise SphinxError(__('Source parser for %s not registered') % filename)
218217
else:
219-
if isinstance(parser_class, string_types):
220-
parser_class = import_object(parser_class, 'source parser') # type: ignore
221218
return parser_class
222219

223220
def get_source_parsers(self):

sphinx/util/compat.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
sphinx.util.compat
4+
~~~~~~~~~~~~~~~~~~
5+
6+
modules for backward compatibility
7+
8+
:copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
9+
:license: BSD, see LICENSE for details.
10+
"""
11+
12+
import warnings
13+
14+
from six import string_types, iteritems
15+
16+
from sphinx.deprecation import RemovedInSphinx30Warning
17+
from sphinx.util import import_object
18+
19+
if False:
20+
# For type annotation
21+
from typing import Any, Dict # NOQA
22+
from sphinx.application import Sphinx # NOQA
23+
from sphinx.config import Config # NOQA
24+
25+
26+
def deprecate_source_parsers(app, config):
27+
# type: (Sphinx, Config) -> None
28+
if config.source_parsers:
29+
warnings.warn('The config variable "source_parsers" is deprecated. '
30+
'Please use app.add_source_parser() API instead.',
31+
RemovedInSphinx30Warning)
32+
for suffix, parser in iteritems(config.source_parsers):
33+
if isinstance(parser, string_types):
34+
parser = import_object(parser, 'source parser') # type: ignore
35+
app.add_source_parser(suffix, parser)
36+
37+
38+
def setup(app):
39+
# type: (Sphinx) -> Dict[unicode, Any]
40+
app.connect('config-inited', deprecate_source_parsers)
41+
42+
return {
43+
'version': 'builtin',
44+
'parallel_read_safe': True,
45+
'parallel_write_safe': True,
46+
}

0 commit comments

Comments
 (0)