mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Rename Config.read_from_py() to Config.read()
This commit is contained in:
parent
5897d45cc6
commit
b165ade6b0
3
CHANGES
3
CHANGES
@ -47,6 +47,7 @@ Deprecated
|
||||
argument has been deprecated
|
||||
* ``Config.check_types()`` is deprecated
|
||||
* ``Config.check_unicode()`` is deprecated
|
||||
* ``sphinx.application.CONFIG_FILENAME`` is deprecated
|
||||
|
||||
For more details, see `deprecation APIs list
|
||||
<http://www.sphinx-doc.org/en/master/extdev/index.html#deprecated-apis>`_
|
||||
@ -75,7 +76,7 @@ Features added
|
||||
* #4834: Ensure set object descriptions are reproducible.
|
||||
* #4828: Allow to override :confval:`numfig_format` partially. Full definition
|
||||
is not needed.
|
||||
* Add ``Config.from_conf_py()`` classmethod to create a new config object from
|
||||
* Add ``Config.read()`` classmethod to create a new config object from
|
||||
configuration file
|
||||
|
||||
Bugs fixed
|
||||
|
@ -119,6 +119,11 @@ The following is a list of deprecated interface.
|
||||
- 4.0
|
||||
- :meth:`~sphinx.application.Sphinx.add_css_file()`
|
||||
|
||||
* - ``sphinx.application.CONFIG_FILENAME``
|
||||
- 1.8
|
||||
- 3.0
|
||||
- ``sphinx.config.CONFIG_FILENAME``
|
||||
|
||||
* - ``Config.check_unicode()``
|
||||
- 1.8
|
||||
- 3.0
|
||||
@ -133,7 +138,7 @@ The following is a list of deprecated interface.
|
||||
``Config.__init__()``
|
||||
- 1.8
|
||||
- 3.0
|
||||
- ``Config.from_conf_py()``
|
||||
- ``Config.read()``
|
||||
|
||||
* - ``sphinx.versioning.prepare()``
|
||||
- 1.8
|
||||
|
@ -26,6 +26,7 @@ from six.moves import cStringIO
|
||||
|
||||
import sphinx
|
||||
from sphinx import package_dir, locale
|
||||
from sphinx.config import CONFIG_FILENAME # NOQA # for compatibility (RemovedInSphinx30)
|
||||
from sphinx.config import Config, check_unicode
|
||||
from sphinx.deprecation import (
|
||||
RemovedInSphinx20Warning, RemovedInSphinx30Warning, RemovedInSphinx40Warning
|
||||
@ -108,7 +109,6 @@ builtin_extensions = (
|
||||
'alabaster',
|
||||
) # type: Tuple[unicode, ...]
|
||||
|
||||
CONFIG_FILENAME = 'conf.py'
|
||||
ENV_PICKLE_FILENAME = 'environment.pickle'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -190,8 +190,7 @@ class Sphinx(object):
|
||||
if self.confdir is None:
|
||||
self.config = Config({}, confoverrides or {})
|
||||
else:
|
||||
self.config = Config.from_conf_py(path.join(self.confdir, CONFIG_FILENAME),
|
||||
confoverrides or {}, self.tags)
|
||||
self.config = Config.read(self.confdir, confoverrides or {}, self.tags)
|
||||
check_unicode(self.config)
|
||||
|
||||
# initialize some limited config variables before initialize i18n and loading
|
||||
|
@ -34,6 +34,7 @@ if False:
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
CONFIG_FILENAME = 'conf.py'
|
||||
copyright_year_re = re.compile(r'^((\d{4}-)?)(\d{4})(?=[ ,])')
|
||||
|
||||
if PY3:
|
||||
@ -148,7 +149,7 @@ class Config(object):
|
||||
if len(args) == 4:
|
||||
# old style arguments: (dirname, filename, overrides, tags)
|
||||
warnings.warn('The argument of Config() class has been changed. '
|
||||
'Use Config.from_conf_py() to read configuration from conf.py.',
|
||||
'Use Config.read() to read configuration from conf.py.',
|
||||
RemovedInSphinx30Warning)
|
||||
dirname, filename, overrides, tags = args
|
||||
if dirname is None:
|
||||
@ -177,9 +178,10 @@ class Config(object):
|
||||
self.extensions = config.get('extensions', []) # type: List[unicode]
|
||||
|
||||
@classmethod
|
||||
def from_conf_py(cls, filename, overrides=None, tags=None):
|
||||
def read(cls, confdir, overrides=None, tags=None):
|
||||
# type: (unicode, Dict, Tags) -> Config
|
||||
"""Create a Config object from configuration file."""
|
||||
filename = path.join(confdir, CONFIG_FILENAME)
|
||||
namespace = eval_config_file(filename, tags)
|
||||
return cls(namespace, overrides or {})
|
||||
|
||||
|
@ -124,14 +124,14 @@ def test_errors_warnings(logger, tempdir):
|
||||
# test the error for syntax errors in the config file
|
||||
(tempdir / 'conf.py').write_text(u'project = \n', encoding='ascii')
|
||||
with pytest.raises(ConfigError) as excinfo:
|
||||
Config.from_conf_py(tempdir / 'conf.py', {}, None)
|
||||
Config.read(tempdir, {}, None)
|
||||
assert 'conf.py' in str(excinfo.value)
|
||||
|
||||
# test the automatic conversion of 2.x only code in configs
|
||||
(tempdir / 'conf.py').write_text(
|
||||
u'# -*- coding: utf-8\n\nproject = u"Jägermeister"\n',
|
||||
encoding='utf-8')
|
||||
cfg = Config.from_conf_py(tempdir / 'conf.py', {}, None)
|
||||
cfg = Config.read(tempdir, {}, None)
|
||||
cfg.init_values()
|
||||
assert cfg.project == u'Jägermeister'
|
||||
assert logger.called is False
|
||||
@ -143,7 +143,7 @@ def test_errors_warnings(logger, tempdir):
|
||||
return
|
||||
(tempdir / 'conf.py').write_text(
|
||||
u'# -*- coding: latin-1\nproject = "fooä"\n', encoding='latin-1')
|
||||
cfg = Config.from_conf_py(tempdir / 'conf.py', {}, None)
|
||||
cfg = Config.read(tempdir, {}, None)
|
||||
|
||||
assert logger.warning.called is False
|
||||
cfg.check_unicode()
|
||||
@ -202,7 +202,7 @@ def test_config_eol(logger, tempdir):
|
||||
configfile = tempdir / 'conf.py'
|
||||
for eol in (b'\n', b'\r\n'):
|
||||
configfile.write_bytes(b'project = "spam"' + eol)
|
||||
cfg = Config.from_conf_py(tempdir / 'conf.py', {}, None)
|
||||
cfg = Config.read(tempdir, {}, None)
|
||||
cfg.init_values()
|
||||
assert cfg.project == u'spam'
|
||||
assert logger.called is False
|
||||
|
Loading…
Reference in New Issue
Block a user