From bd031141ca7b71245b5d886b0388ab43fbefadde Mon Sep 17 00:00:00 2001 From: Nabil Freij Date: Sat, 10 Aug 2024 12:26:58 -0700 Subject: [PATCH] make cards an extension (#268) --- .readthedocs.yaml | 3 +-- docs/conf.py | 1 + src/sunpy_sphinx_theme/__init__.py | 6 ------ src/sunpy_sphinx_theme/cards.py | 13 ++++++++++++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 5d80fb2b..ea79f059 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -1,6 +1,6 @@ version: 2 build: - os: ubuntu-22.04 + os: ubuntu-lts-latest tools: python: "mambaforge-latest" jobs: @@ -24,6 +24,5 @@ python: install: - method: pip extra_requirements: - - all - docs path: . diff --git a/docs/conf.py b/docs/conf.py index 97b60009..754e81f6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -35,6 +35,7 @@ "sphinx.ext.napoleon", "sphinx.ext.todo", "sphinx.ext.viewcode", + "sunpy_sphinx_theme.cards", ] exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] source_suffix = ".rst" diff --git a/src/sunpy_sphinx_theme/__init__.py b/src/sunpy_sphinx_theme/__init__.py index d60a9eb9..aa5234f9 100644 --- a/src/sunpy_sphinx_theme/__init__.py +++ b/src/sunpy_sphinx_theme/__init__.py @@ -10,8 +10,6 @@ from pydata_sphinx_theme import utils from sphinx.application import Sphinx -from .cards import Card, _Card, depart_card_node, visit_card_node - __all__ = ["get_html_theme_path", "ON_RTD", "PNG_ICON", "SVG_ICON"] @@ -141,12 +139,8 @@ def setup(app: Sphinx): theme_dir = get_html_theme_path() app.add_html_theme("sunpy", theme_dir) app.add_css_file("sunpy_style.css", priority=600) - app.add_css_file("sunpy_cards.css", priority=600) - app.add_directive("custom-card", Card) - app.add_node(_Card, html=(visit_card_node, depart_card_node)) app.connect("builder-inited", update_config) app.connect("html-page-context", update_html_context) - # Conditionally include goat counter js # We can't do this in update_config as that causes the scripts to be duplicated. # Also in here none of the theme defaults have be applied by `update_config` diff --git a/src/sunpy_sphinx_theme/cards.py b/src/sunpy_sphinx_theme/cards.py index ffc73f6a..d19bd942 100644 --- a/src/sunpy_sphinx_theme/cards.py +++ b/src/sunpy_sphinx_theme/cards.py @@ -1,9 +1,10 @@ """ -This provides the card extension from the website into the theme. +This provides a card extension for the website. """ from docutils import nodes from docutils.parsers.rst import Directive, directives +from sphinx.application import Sphinx __all__ = ["Card", "_Card", "visit_card_node", "depart_card_node"] @@ -97,3 +98,13 @@ def run(self): ) self.state.nested_parse(self.content, 0, out) return [out] + + +def setup(app: Sphinx): + app.add_css_file("sunpy_cards.css", priority=600) + app.add_directive("custom-card", Card) + app.add_node(_Card, html=(visit_card_node, depart_card_node)) + return { + "parallel_read_safe": True, + "parallel_write_safe": True, + }