|
| 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