From f0c25a0adafe36eb987bae6ea13ed4a57d1c3bf0 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Thu, 14 Sep 2023 11:49:41 +0100 Subject: [PATCH] Raise a useful error if ``theme.conf`` doesn't exist (#11671) --- CHANGES.rst | 3 +++ sphinx/theming.py | 5 ++++- tests/test_theming.py | 9 ++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index ab10498fd0c..10abb27b452 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -16,6 +16,9 @@ Features added Bugs fixed ---------- +* #11668: Raise a useful error when ``theme.conf`` is missing. + Patch by Vinay Sajip. + Testing ------- diff --git a/sphinx/theming.py b/sphinx/theming.py index a8a3f83f361..71aaf3080ea 100644 --- a/sphinx/theming.py +++ b/sphinx/theming.py @@ -69,7 +69,10 @@ def __init__(self, name: str, theme_path: str, factory: HTMLThemeFactory) -> Non extract_zip(theme_path, self.themedir) self.config = configparser.RawConfigParser() - self.config.read(path.join(self.themedir, THEMECONF), encoding='utf-8') + config_file_path = path.join(self.themedir, THEMECONF) + if not os.path.isfile(config_file_path): + raise ThemeError(__('theme configuration file %r not found') % config_file_path) + self.config.read(config_file_path, encoding='utf-8') try: inherit = self.config.get('theme', 'inherit') diff --git a/tests/test_theming.py b/tests/test_theming.py index b4c85112a58..2dfdd8dee0d 100644 --- a/tests/test_theming.py +++ b/tests/test_theming.py @@ -6,7 +6,7 @@ import pytest import sphinx.builders.html -from sphinx.theming import ThemeError +from sphinx.theming import Theme, ThemeError @pytest.mark.sphinx( @@ -62,6 +62,13 @@ def test_theme_api(app, status, warning): assert not os.path.exists(themedir) +def test_nonexistent_theme_conf(tmp_path): + # Check that error occurs with a non-existent theme.conf + # (https://github.com/sphinx-doc/sphinx/issues/11668) + with pytest.raises(ThemeError): + Theme('dummy', str(tmp_path), None) + + @pytest.mark.sphinx(testroot='double-inheriting-theme') def test_double_inheriting_theme(app, status, warning): assert app.builder.theme.name == 'base_theme2'