mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Now Config.read() takes a filename instead (dirname, filename)
This commit is contained in:
parent
0df4a121bd
commit
181fb1093d
@ -185,7 +185,7 @@ class Sphinx(object):
|
||||
|
||||
# read config
|
||||
self.tags = Tags(tags)
|
||||
self.config = Config.read(self.confdir, CONFIG_FILENAME,
|
||||
self.config = Config.read(path.join(self.confdir, CONFIG_FILENAME),
|
||||
confoverrides or {}, self.tags)
|
||||
self.config.check_unicode()
|
||||
# defer checking types until i18n has been initialized
|
||||
|
@ -159,7 +159,7 @@ class Config(object):
|
||||
if dirname is None:
|
||||
config = {} # type: Dict[unicode, Any]
|
||||
else:
|
||||
config = eval_config_file(dirname, filename, tags)
|
||||
config = eval_config_file(path.join(dirname, filename), tags)
|
||||
else:
|
||||
# new style arguments: (config={}, overrides={})
|
||||
if len(args) == 0:
|
||||
@ -182,10 +182,10 @@ class Config(object):
|
||||
self.extensions = config.get('extensions', []) # type: List[unicode]
|
||||
|
||||
@classmethod
|
||||
def read(cls, confdir, filename, overrides=None, tags=None):
|
||||
# type: (unicode, unicode, Dict, Tags) -> Config
|
||||
def read(cls, filename, overrides=None, tags=None):
|
||||
# type: (unicode, Dict, Tags) -> Config
|
||||
"""Create a Config object from configuration file."""
|
||||
namespace = eval_config_file(confdir, filename, tags)
|
||||
namespace = eval_config_file(filename, tags)
|
||||
return cls(namespace, overrides or {})
|
||||
|
||||
def check_types(self):
|
||||
@ -316,15 +316,14 @@ class Config(object):
|
||||
return (value for value in self if value.rebuild in rebuild)
|
||||
|
||||
|
||||
def eval_config_file(confdir, filename, tags):
|
||||
# type: (unicode, unicode, Tags) -> Dict[unicode, Any]
|
||||
def eval_config_file(filename, tags):
|
||||
# type: (unicode, Tags) -> Dict[unicode, Any]
|
||||
"""Evaluate a config file."""
|
||||
config_path = path.join(confdir, filename)
|
||||
namespace = {} # type: Dict[unicode, Any]
|
||||
namespace['__file__'] = config_path
|
||||
namespace['__file__'] = filename
|
||||
namespace['tags'] = tags
|
||||
|
||||
with cd(confdir):
|
||||
with cd(path.dirname(filename)):
|
||||
# during executing config file, current dir is changed to ``confdir``.
|
||||
try:
|
||||
execfile_(filename, namespace)
|
||||
|
@ -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.read(tempdir, 'conf.py', {}, None)
|
||||
Config.read(tempdir / 'conf.py', {}, 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.read(tempdir, 'conf.py', {}, None)
|
||||
cfg = Config.read(tempdir / 'conf.py', {}, 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.read(tempdir, 'conf.py', {}, None)
|
||||
cfg = Config.read(tempdir / 'conf.py', {}, 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.read(tempdir, 'conf.py', {}, None)
|
||||
cfg = Config.read(tempdir / 'conf.py', {}, None)
|
||||
cfg.init_values()
|
||||
assert cfg.project == u'spam'
|
||||
assert logger.called is False
|
||||
|
Loading…
Reference in New Issue
Block a user