Skip to content

Commit

Permalink
Ensure that [theme] and [options] are tables in theme.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Apr 11, 2024
1 parent 44a42d5 commit 72760ad
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions sphinx/theming.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,21 @@ def _load_theme_toml(config_file_path: str, /) -> _ThemeToml:

def _validate_theme_toml(cfg: _ThemeToml, name: str) -> str:
if 'theme' not in cfg:
raise ThemeError(__('theme %r doesn\'t have the "theme" table') % name)
if inherit := cfg['theme'].get('inherit', ''):
return inherit
msg = __('The %r theme must define the "theme.inherit" setting') % name
raise ThemeError(msg)
msg = __('theme %r doesn\'t have the "theme" table') % name
raise ThemeError(msg)
theme = cfg['theme']
if not isinstance(theme, dict):
msg = __('The %r theme "[theme]" table is not a table') % name
raise ThemeError(msg)
inherit = theme.get('inherit', '')
if not inherit:
msg = __('The %r theme must define the "theme.inherit" setting') % name
raise ThemeError(msg)
if 'options' in cfg:
if not isinstance(cfg['options'], dict):
msg = __('The %r theme "[options]" table is not a table') % name
raise ThemeError(msg)
return inherit


def _convert_theme_toml(cfg: _ThemeToml, /) -> _ConfigFile:
Expand Down

0 comments on commit 72760ad

Please sign in to comment.