__init__.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. """
  2. Sphinx Read the Docs theme.
  3. From https://github.com/ryan-roemer/sphinx-bootstrap-theme.
  4. """
  5. from os import path
  6. from sys import version_info as python_version
  7. from sphinx import version_info as sphinx_version
  8. from sphinx.locale import _
  9. from sphinx.util.logging import getLogger
  10. __version__ = '1.0.0rc2'
  11. __version_full__ = __version__
  12. logger = getLogger(__name__)
  13. def get_html_theme_path():
  14. """Return list of HTML theme paths."""
  15. cur_dir = path.abspath(path.dirname(path.dirname(__file__)))
  16. return cur_dir
  17. def config_initiated(app, config):
  18. theme_options = config.html_theme_options or {}
  19. if theme_options.get('canonical_url'):
  20. logger.warning(
  21. _('The canonical_url option is deprecated, use the html_baseurl option from Sphinx instead.')
  22. )
  23. # See http://www.sphinx-doc.org/en/stable/theming.html#distribute-your-theme-as-a-python-package
  24. def setup(app):
  25. if python_version[0] < 3:
  26. logger.warning("Python 2 is deprecated with sphinx_rtd_theme, update to Python 3")
  27. app.require_sphinx('1.6')
  28. if sphinx_version <= (2, 0, 0):
  29. logger.warning("Sphinx 1.x is deprecated with sphinx_rtd_theme, update to Sphinx 2.x or greater")
  30. if not app.config.html_experimental_html5_writer:
  31. logger.warning("'html4_writer' is deprecated with sphinx_rtd_theme")
  32. else:
  33. if app.config.html4_writer:
  34. logger.warning("'html4_writer' is deprecated with sphinx_rtd_theme")
  35. # Register the theme that can be referenced without adding a theme path
  36. app.add_html_theme('sphinx_rtd_theme', path.abspath(path.dirname(__file__)))
  37. if sphinx_version >= (1, 8, 0):
  38. # Add Sphinx message catalog for newer versions of Sphinx
  39. # See http://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx.application.Sphinx.add_message_catalog
  40. rtd_locale_path = path.join(path.abspath(path.dirname(__file__)), 'locale')
  41. app.add_message_catalog('sphinx', rtd_locale_path)
  42. app.connect('config-inited', config_initiated)
  43. # sphinx emits the permalink icon for headers, so choose one more in keeping with our theme
  44. if sphinx_version >= (3, 5, 0):
  45. app.config.html_permalinks_icon = "\uf0c1"
  46. else:
  47. app.config.html_add_permalinks = "\uf0c1"
  48. return {'parallel_read_safe': True, 'parallel_write_safe': True}