From b5176da3b2ad56354b0d82fceb43aeede69e6b4f Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sun, 21 Jan 2024 23:53:12 -0800 Subject: [PATCH] docs: enable opt-in use of the furo theme Signed-off-by: David Aguilar --- docs/conf.py | 27 +++++++++++++++++++++++++-- setup.cfg | 1 + 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index b200ae9a..7e0ab7e3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,6 +2,10 @@ import os import sys try: + import furo +except ImportError: + furo = None +try: import sphinx_rtd_theme except ImportError: sphinx_rtd_theme = None @@ -82,7 +86,26 @@ man_pages = [ # Disable this feature for consistency across Sphinx versions. man_make_section_directory = False -# Enable the sphinx_rtd_theme. -if sphinx_rtd_theme is not None: + +# furo overwrites "_static/pygments.css" so we monkey-patch +# "def _overwrite_pygments_css()" to use "static/pygments.css" instead. +def _overwrite_pygments_css(app, exception): + """Replacement for furo._overwrite_pygments_css to handle sphinxtogithub""" + if exception is not None: + return + assert app.builder + with open( + os.path.join(app.builder.outdir, 'static', 'pygments.css'), + 'w', + encoding='utf-8', + ) as f: + f.write(furo.get_pygments_stylesheet()) + + +# Enable custom themes. +if furo is not None and hasattr(furo, '_overwrite_pygments_css'): + furo._overwrite_pygments_css = _overwrite_pygments_css + html_theme = 'furo' +elif sphinx_rtd_theme is not None: extensions += ['sphinx_rtd_theme'] html_theme = 'sphinx_rtd_theme' diff --git a/setup.cfg b/setup.cfg index 4a7cbc6a..37a5dc64 100644 --- a/setup.cfg +++ b/setup.cfg @@ -63,6 +63,7 @@ testing = docs = # upstream + furo sphinx rst.linker >= 1.9 -- 2.11.4.GIT