Skip to content

Commit f0c25a0

Browse files
authored
Raise a useful error if theme.conf doesn't exist (#11671)
1 parent 655bd15 commit f0c25a0

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Features added
1616
Bugs fixed
1717
----------
1818

19+
* #11668: Raise a useful error when ``theme.conf`` is missing.
20+
Patch by Vinay Sajip.
21+
1922
Testing
2023
-------
2124

sphinx/theming.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ def __init__(self, name: str, theme_path: str, factory: HTMLThemeFactory) -> Non
6969
extract_zip(theme_path, self.themedir)
7070

7171
self.config = configparser.RawConfigParser()
72-
self.config.read(path.join(self.themedir, THEMECONF), encoding='utf-8')
72+
config_file_path = path.join(self.themedir, THEMECONF)
73+
if not os.path.isfile(config_file_path):
74+
raise ThemeError(__('theme configuration file %r not found') % config_file_path)
75+
self.config.read(config_file_path, encoding='utf-8')
7376

7477
try:
7578
inherit = self.config.get('theme', 'inherit')

tests/test_theming.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77

88
import sphinx.builders.html
9-
from sphinx.theming import ThemeError
9+
from sphinx.theming import Theme, ThemeError
1010

1111

1212
@pytest.mark.sphinx(
@@ -62,6 +62,13 @@ def test_theme_api(app, status, warning):
6262
assert not os.path.exists(themedir)
6363

6464

65+
def test_nonexistent_theme_conf(tmp_path):
66+
# Check that error occurs with a non-existent theme.conf
67+
# (https://github.com/sphinx-doc/sphinx/issues/11668)
68+
with pytest.raises(ThemeError):
69+
Theme('dummy', str(tmp_path), None)
70+
71+
6572
@pytest.mark.sphinx(testroot='double-inheriting-theme')
6673
def test_double_inheriting_theme(app, status, warning):
6774
assert app.builder.theme.name == 'base_theme2'

0 commit comments

Comments
 (0)