diff mbox series

[2/3] conf.py: use importlib to check that sphinx_rtd_theme exists

Message ID 20260828-cleanup-conf-py-v1-2-c8925e5fe1ac@bootlin.com
State New
Headers show
Series conf.py cleanups | expand

Commit Message

Antonin Godard Aug. 28, 2026, 9:49 a.m. UTC
We don't need to import sphinx_rtd_theme in this file, only check if it
exists, so use importlib.util.find_spec() which is made for that.

Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
---
 documentation/conf.py | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/documentation/conf.py b/documentation/conf.py
index 671bf537c..bd3a4e5bc 100644
--- a/documentation/conf.py
+++ b/documentation/conf.py
@@ -13,6 +13,7 @@ 
 # documentation root, use os.path.abspath to make it absolute, like shown here.
 
 import datetime
+import importlib.util
 import os
 import re
 import sys
@@ -169,18 +170,17 @@  if os.environ.get('LINKCHECK_NOT_NICE') != "1":
 
 # The theme to use for HTML and HTML Help pages.  See the documentation for
 # a list of builtin themes.
-#
-try:
-    import sphinx_rtd_theme
-    html_theme = 'sphinx_rtd_theme'
-    html_theme_options = {
-        'sticky_navigation': False,
-    }
-except ImportError:
+
+if not importlib.util.find_spec('sphinx_rtd_theme'):
     sys.stderr.write("The Sphinx sphinx_rtd_theme HTML theme was not found.\
     \nPlease make sure to install the sphinx_rtd_theme Python package.\n")
     sys.exit(1)
 
+html_theme = 'sphinx_rtd_theme'
+html_theme_options = {
+    'sticky_navigation': False,
+}
+
 html_logo = 'sphinx-static/YoctoProject_Logo_RGB.jpg'
 html_favicon = 'sphinx-static/favicon.ico'