diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2017-04-20 21:21:04 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2017-04-22 14:59:10 +0900 |
commit | 621a4e6f6182e9ef335e7e4cbc8302ff9caadfc6 (patch) | |
tree | 840cabb6576a9cba7183a96436d21ae82566ef40 /sphinx/theming.py | |
parent | 45887c7d62dde461f2741f1cb9e2cc1ca26a42dd (diff) | |
download | sphinx-git-621a4e6f6182e9ef335e7e4cbc8302ff9caadfc6.tar.gz |
Fix #3628: Rename sphinx_themes entry point to sphinx.html_themes
Diffstat (limited to 'sphinx/theming.py')
-rw-r--r-- | sphinx/theming.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/sphinx/theming.py b/sphinx/theming.py index f0c7667d3..5e023e5a1 100644 --- a/sphinx/theming.py +++ b/sphinx/theming.py @@ -12,6 +12,7 @@ import os import shutil import tempfile +import warnings from os import path from zipfile import ZipFile @@ -20,7 +21,9 @@ from six import string_types, iteritems from six.moves import configparser from sphinx import package_dir +from sphinx.deprecation import RemovedInSphinx20Warning from sphinx.errors import ThemeError +from sphinx.extension import load_extension from sphinx.locale import _ from sphinx.util import logging from sphinx.util.osutil import ensuredir @@ -77,6 +80,8 @@ class Theme(object): try: inherit = self.config.get('theme', 'inherit') + except configparser.NoSectionError: + raise ThemeError(_('theme %r doesn\'t have "theme" setting') % name) except configparser.NoOptionError: raise ThemeError(_('theme %r doesn\'t have "inherit" setting') % name) @@ -161,7 +166,7 @@ class HTMLThemeFactory(object): def __init__(self, app): # type: (Sphinx) -> None - self.confdir = app.confdir + self.app = app self.themes = app.html_themes self.load_builtin_themes() if getattr(app.config, 'html_theme_path', None): @@ -178,7 +183,7 @@ class HTMLThemeFactory(object): # type: (unicode) -> None """Load additional themes placed at specified directories.""" for theme_path in theme_paths: - abs_theme_path = path.abspath(path.join(self.confdir, theme_path)) + abs_theme_path = path.abspath(path.join(self.app.confdir, theme_path)) themes = self.find_themes(abs_theme_path) for name, theme in iteritems(themes): self.themes[name] = theme @@ -215,6 +220,16 @@ class HTMLThemeFactory(object): Sphinx refers to ``sphinx_themes`` entry_points. """ + # look up for new styled entry_points at first + entry_points = pkg_resources.iter_entry_points('sphinx.html_themes', name) + try: + entry_point = next(entry_points) + load_extension(self.app, entry_point.module_name) + return + except StopIteration: + pass + + # look up for old styled entry_points for entry_point in pkg_resources.iter_entry_points('sphinx_themes'): target = entry_point.load() if callable(target): @@ -228,6 +243,9 @@ class HTMLThemeFactory(object): themes = self.find_themes(themedir) for entry, theme in iteritems(themes): if name == entry: + warnings.warn('``sphinx_themes`` entry point is now deprecated. ' + 'Please use ``sphinx.html_themes`` instead.', + RemovedInSphinx20Warning) self.themes[name] = theme def find_themes(self, theme_path): |