Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 thebe #354

Merged
merged 4 commits into from
Jun 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions qiskit_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ def _get_theme_absolute_path(folder_name: str) -> str:
return str(path.resolve())


def remove_thebe_if_not_needed(app, pagename, templatename, context, doctree):
"""
Remove files that jupyter-sphinx incorrectly tries to add.

See https://github.com/Qiskit/qiskit_sphinx_theme/issues/291 for more context.
"""
# jupyter-sphinx might be not installed. If so, skip this function.
try:
from jupyter_sphinx.thebelab import ThebeButtonNode
except ImportError:
return

if not doctree or doctree.traverse(ThebeButtonNode):
return

thebe_js_files = ["_static/sphinx-thebe.js", "_static/thebelab-helper.js", "https://unpkg.com/thebelab@latest/lib/index.js"]
context["script_files"] = [js_file for js_file in context["script_files"] if js_file not in thebe_js_files]

thebe_css_files = ['_static/thebelab.css', '_static/sphinx-thebe.css']
context["css_files"] = [css_file for css_file in context["css_files"] if css_file not in thebe_css_files]


# See https://www.sphinx-doc.org/en/master/development/theming.html
def setup(app):
# Used to generate URL references. Expected to be e.g. `ecosystem/finance`.
Expand All @@ -41,6 +63,8 @@ def setup(app):
app.add_html_theme("qiskit_sphinx_theme", _get_theme_absolute_path("pytorch_base"))
app.add_html_theme("_qiskit_furo", _get_theme_absolute_path("furo/base"))

app.connect("html-page-context", remove_thebe_if_not_needed)

if app.config.html_theme == "_qiskit_furo":
# The below must be kept in sync with `furo/__init__.py`.
from furo import (
Expand Down