Skip to content

Commit

Permalink
Move Furo init code to normal top level, not in config-inited
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Arellano committed Jul 7, 2023
1 parent ba25464 commit 85c185e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/qiskit_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ def remove_thebe_if_not_needed(


def activate_themes(app: sphinx.application.Sphinx, config: sphinx.config.Config) -> None:
if config.html_theme == "qiskit":
app.add_js_file("scripts/qiskit-sphinx-theme.js")
furo_py.setup(app)
else:
if config.html_theme == "qiskit_sphinx_theme":
# 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")
return

app.add_js_file("scripts/qiskit-sphinx-theme.js")


# See https://www.sphinx-doc.org/en/master/development/theming.html
Expand All @@ -90,6 +90,9 @@ def setup(app: sphinx.application.Sphinx) -> dict[str, bool]:
previous_releases.setup(app)
translations.setup(app)

# While this runs for Pytorch too, we early exit in the relevant functions with Pytorch.
furo_py.setup(app)

app.add_html_theme("qiskit_sphinx_theme", _get_theme_absolute_path("pytorch"))
app.add_html_theme("qiskit", _get_theme_absolute_path("theme/qiskit-sphinx-theme"))

Expand Down
15 changes: 15 additions & 0 deletions src/qiskit_sphinx_theme/furo_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ def _html_page_context(
context: Dict[str, Any],
doctree: Any,
) -> None:
# QISKIT CHANGE: start.
if app.config.html_theme == "qiskit_sphinx_theme":
return None
# QISKIT CHANGE: end.

if not isinstance(app.builder, StandaloneHTMLBuilder):
raise Exception(
"Furo is being used with a non-HTML builder. "
Expand Down Expand Up @@ -228,6 +233,11 @@ def _html_page_context(


def _builder_inited(app: sphinx.application.Sphinx) -> None:
# QISKIT CHANGE: start.
if app.config.html_theme == "qiskit_sphinx_theme":
return None
# QISKIT CHANGE: end.

if "furo" in app.config.extensions:
raise Exception(
"Did you list 'furo' in the `extensions` in conf.py? "
Expand Down Expand Up @@ -384,6 +394,11 @@ def _overwrite_pygments_css(
app: sphinx.application.Sphinx,
exception: Optional[Exception],
) -> None:
# QISKIT CHANGE: start.
if app.config.html_theme == "qiskit_sphinx_theme":
return None
# QISKIT CHANGE: end.

if exception is not None:
return

Expand Down

0 comments on commit 85c185e

Please sign in to comment.