diff --git a/doc/python_api/conf.py b/doc/python_api/conf.py index 0fe27d0c991..b0ae7abf4b3 100644 --- a/doc/python_api/conf.py +++ b/doc/python_api/conf.py @@ -5,6 +5,17 @@ import time +def has_module(module_name): + found = False + try: + __import__(module_name) + found = True + except ModuleNotFoundError as ex: + if ex.name != module_name: + raise ex + return found + + # These are substituted when this file is copied to the build directory. BLENDER_VERSION_STRING = "${BLENDER_VERSION_STRING}" BLENDER_VERSION_DOTS = "${BLENDER_VERSION_DOTS}" @@ -27,6 +38,16 @@ else: extensions = ["sphinx.ext.intersphinx"] intersphinx_mapping = {"blender_manual": ("https://docs.blender.org/manual/en/dev/", None)} + + +# Provides copy button next to code-blocks (nice to have but not essential). +if has_module("sphinx_copybutton"): + extensions.append("sphinx_copybutton") + + # Exclude line numbers, prompts, and console text. + copybutton_exclude = ".linenos, .gp, .go" + + project = "Blender %s Python API" % BLENDER_VERSION_STRING root_doc = "index" copyright = "Blender Authors" @@ -48,14 +69,8 @@ html_title = "Blender Python API" # The fallback to a built-in theme when `furo` is not found. html_theme = "default" -try: - import furo +if has_module("furo"): html_theme = "furo" - del furo -except ModuleNotFoundError: - pass - -if html_theme == "furo": html_theme_options = { "light_css_variables": { "color-brand-primary": "#265787", diff --git a/doc/python_api/requirements.txt b/doc/python_api/requirements.txt index 70c385b5e74..8bfd02f05f8 100644 --- a/doc/python_api/requirements.txt +++ b/doc/python_api/requirements.txt @@ -11,3 +11,6 @@ requests==2.31.0 # Without this theme, the default theme will be used. furo==2024.1.29 sphinx-basic-ng==1.0.0b2 + +# Show a copy button (convenience only). +sphinx-copybutton==0.5.2