diff options
-rw-r--r-- | sphinx/application.py | 17 | ||||
-rw-r--r-- | sphinx/config.py | 3 | ||||
-rw-r--r-- | tests/test_config.py | 5 |
3 files changed, 13 insertions, 12 deletions
diff --git a/sphinx/application.py b/sphinx/application.py index 588a808f1..07049ffcd 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -152,12 +152,6 @@ class Sphinx: self.srcdir = abspath(srcdir) self.outdir = abspath(outdir) self.doctreedir = abspath(doctreedir) - self.confdir = confdir - if self.confdir: # confdir is optional - self.confdir = abspath(self.confdir) - if not path.isfile(path.join(self.confdir, 'conf.py')): - raise ApplicationError(__("config directory doesn't contain a " - "conf.py file (%s)") % confdir) if not path.isdir(self.srcdir): raise ApplicationError(__('Cannot find source directory (%s)') % @@ -212,9 +206,13 @@ class Sphinx: # read config self.tags = Tags(tags) - if self.confdir is None: + if confdir is None: + # set confdir to srcdir if -C given (!= no confdir); a few pieces + # of code expect a confdir to be set + self.confdir = self.srcdir self.config = Config({}, confoverrides or {}) else: + self.confdir = abspath(confdir) self.config = Config.read(self.confdir, confoverrides or {}, self.tags) # initialize some limited config variables before initialize i18n and loading @@ -230,11 +228,6 @@ class Sphinx: __('This project needs at least Sphinx v%s and therefore cannot ' 'be built with this version.') % self.config.needs_sphinx) - # set confdir to srcdir if -C given (!= no confdir); a few pieces - # of code expect a confdir to be set - if self.confdir is None: - self.confdir = self.srcdir - # load all built-in extension modules for extension in builtin_extensions: self.setup_extension(extension) diff --git a/sphinx/config.py b/sphinx/config.py index 1ba98d007..553aa74d6 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -166,6 +166,9 @@ class Config: def read(cls, confdir: str, overrides: Dict = None, tags: Tags = None) -> "Config": """Create a Config object from configuration file.""" filename = path.join(confdir, CONFIG_FILENAME) + if not path.isfile(filename): + raise ConfigError(__("config directory doesn't contain a conf.py file (%s)") % + confdir) namespace = eval_config_file(filename, tags) return cls(namespace, overrides or {}) diff --git a/tests/test_config.py b/tests/test_config.py index b9b4f612a..717e8658d 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -74,6 +74,11 @@ def test_core_config(app, status, warning): assert cfg['project'] == cfg.project == 'Sphinx Tests' +def test_config_not_found(tempdir): + with pytest.raises(ConfigError): + Config.read(tempdir) + + def test_extension_values(): config = Config() |