Skip to content

Commit

Permalink
Fix Pytorch theme not activating jQuery (#497)
Browse files Browse the repository at this point in the history
Closes #496.

#419 accidentally
broke Pytorch because it apparently doesn't work to call
`app.setup_extension` inside the `config-inited` event. So, we were no
longer activating jQuery by default.
  • Loading branch information
Eric-Arellano authored Jul 17, 2023
1 parent 7b0b5f5 commit 6c52758
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/qiskit_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,12 @@ def remove_thebe_if_not_needed(
]


def activate_themes(app: sphinx.application.Sphinx, config: sphinx.config.Config) -> None:
if config.html_theme in ["qiskit", "_qiskit-ecosystem"]:
# We set a low priority so that our Qiskit CSS file overrides Furo.
app.add_css_file("styles/furo.css", 100)
app.add_js_file("scripts/qiskit-sphinx-theme.js")
else:
# Sphinx 6 stopped including jQuery by default. Our Pytorch theme depend on jQuery,
# so activate it for our users automatically.
app.setup_extension("sphinxcontrib.jquery")
def activate_furo(app: sphinx.application.Sphinx, config: sphinx.config.Config) -> None:
if config.html_theme == "qiskit_sphinx_theme":
return
# We set a low priority so that our Qiskit CSS file overrides Furo.
app.add_css_file("styles/furo.css", 100)
app.add_js_file("scripts/qiskit-sphinx-theme.js")


def remove_furo_js(
Expand All @@ -95,6 +92,11 @@ def setup(app: sphinx.application.Sphinx) -> dict[str, bool]:
# Used to generate URL references. Expected to be e.g. `ecosystem/finance`.
app.add_config_value("docs_url_prefix", default=None, rebuild="html", types=[str])

# Sphinx 6 stopped including jQuery by default. Our Pytorch theme depend on jQuery,
# so activate it for our users automatically. Unfortunately, we can't make this activation
# conditional based on which theme is chosen.
app.setup_extension("sphinxcontrib.jquery")

# We always activate these plugins, but they are only used when users:
# * use the directives in their RST,
# * set `translations_list` in conf.py, or
Expand All @@ -107,7 +109,7 @@ def setup(app: sphinx.application.Sphinx) -> dict[str, bool]:
app.add_html_theme("qiskit", _get_theme_absolute_path("theme/qiskit-sphinx-theme"))
app.add_html_theme("_qiskit-ecosystem", _get_theme_absolute_path("ecosystem"))

app.connect("config-inited", activate_themes)
app.connect("config-inited", activate_furo)
app.connect("html-page-context", remove_furo_js, priority=600)
app.connect("html-page-context", remove_thebe_if_not_needed)

Expand Down

0 comments on commit 6c52758

Please sign in to comment.