From efc4660d613f3d7a1df9f4fb8b12705b3b0781a3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Aug 2026 16:39:37 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.15.20 → v0.16.1](https://github.com/astral-sh/ruff-pre-commit/compare/v0.15.20...v0.16.1) - [github.com/rbubley/mirrors-prettier: 39e2973981e6d2f9b6c543b0086a2d2393abdc89 → 0ee178619d696787ca73d210cc191d720868c631](https://github.com/rbubley/mirrors-prettier/compare/39e2973981e6d2f9b6c543b0086a2d2393abdc89...0ee178619d696787ca73d210cc191d720868c631) - [github.com/codespell-project/codespell: v2.4.2 → v2.4.3](https://github.com/codespell-project/codespell/compare/v2.4.2...v2.4.3) --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5ca75abd..394822a9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,20 +27,20 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.20 + rev: v0.16.1 hooks: - id: ruff args: ["--fix", "--show-fixes"] - id: ruff-format - repo: https://github.com/rbubley/mirrors-prettier - rev: 39e2973981e6d2f9b6c543b0086a2d2393abdc89 # frozen: v3.9.4 + rev: 0ee178619d696787ca73d210cc191d720868c631 # frozen: v3.9.6 hooks: - id: prettier types_or: [scss, javascript] - repo: https://github.com/codespell-project/codespell - rev: v2.4.2 + rev: v2.4.3 hooks: - id: codespell exclude: > From fe9827e487d6994b91042466fe309fe970be7ae2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Aug 2026 16:41:22 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/conf.py | 12 ++++++------ docs/scripts/update_kitchen_sink.py | 6 +++--- src/sphinx_book_theme/__init__.py | 18 +++++++++--------- src/sphinx_book_theme/_compat.py | 3 ++- src/sphinx_book_theme/_compile_translations.py | 4 ++-- src/sphinx_book_theme/_transforms.py | 10 ++++++---- .../header_buttons/__init__.py | 6 ++---- src/sphinx_book_theme/header_buttons/launch.py | 9 ++++----- src/sphinx_book_theme/header_buttons/source.py | 4 ++-- src/sphinx_book_theme/nodes.py | 3 ++- tests/test_build.py | 9 ++++----- 11 files changed, 42 insertions(+), 42 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index a81acf43..6805ab0c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,8 +1,8 @@ # -- Project information ----------------------------------------------------- import os -from urllib.request import urlopen -from pathlib import Path from datetime import datetime +from pathlib import Path +from urllib.request import urlopen project = "Sphinx Book Theme" copyright = str(datetime.now().year) @@ -198,7 +198,7 @@ # -- Download latest theme elements page from PyData ----------------------------- -path_pydata_content = "https://raw.githubusercontent.com/pydata/pydata-sphinx-theme/main/docs/user_guide/theme-elements.md" # noqa +path_pydata_content = "https://raw.githubusercontent.com/pydata/pydata-sphinx-theme/main/docs/user_guide/theme-elements.md" path_content_file = Path(__file__).parent / "content/pydata-content-blocks.md" if not path_content_file.exists(): with urlopen(path_pydata_content) as resp: @@ -208,8 +208,8 @@ content[ix_title] = "# PyData Theme Elements" content.insert( ix_title + 1, - "\nThis is a collection of content blocks with special support from this theme's parent theme, [the PyData Sphinx Theme](https://pydata-sphinx-theme.readthedocs.io/en/latest/user_guide/theme-elements.html)\n", # noqa - ) # noqa + "\nThis is a collection of content blocks with special support from this theme's parent theme, [the PyData Sphinx Theme](https://pydata-sphinx-theme.readthedocs.io/en/latest/user_guide/theme-elements.html)\n", + ) content = "\n".join(content) # Replace a relative link in the pydata docs w/ the respective one here content = content.replace("../examples/pydata.ipynb", "notebooks.md") @@ -230,7 +230,7 @@ def setup(app): app.add_css_file("https://assets.readthedocs.org/static/css/badge_only.css") # Create the dummy data file so we can link it - # ref: https://github.com/readthedocs/readthedocs.org/blob/bc3e147770e5740314a8e8c33fec5d111c850498/readthedocs/core/static-src/core/js/doc-embed/footer.js # noqa: E501 + # ref: https://github.com/readthedocs/readthedocs.org/blob/bc3e147770e5740314a8e8c33fec5d111c850498/readthedocs/core/static-src/core/js/doc-embed/footer.js app.add_js_file("rtd-data.js") app.add_js_file( "https://assets.readthedocs.org/static/javascript/readthedocs-doc-embed.js", diff --git a/docs/scripts/update_kitchen_sink.py b/docs/scripts/update_kitchen_sink.py index 0116b47c..d913bd41 100644 --- a/docs/scripts/update_kitchen_sink.py +++ b/docs/scripts/update_kitchen_sink.py @@ -1,5 +1,5 @@ -from urllib.request import urlopen from pathlib import Path +from urllib.request import urlopen EXTRA_MESSAGE = """\ @@ -14,7 +14,7 @@ :color: primary Go to Sphinx Themes -""" # noqa +""" kitchen_sink_files = [ "admonitions.rst", @@ -32,7 +32,7 @@ path_sink = Path(__file__).parent.parent / "reference" / "kitchen-sink" for ifile in kitchen_sink_files: print(f"Reading {ifile}...") - url = f"https://github.com/sphinx-themes/sphinx-themes.org/raw/master/sample-docs/kitchen-sink/{ifile}" # noqa + url = f"https://github.com/sphinx-themes/sphinx-themes.org/raw/master/sample-docs/kitchen-sink/{ifile}" text = urlopen(url).read().decode() # The sphinx-themes docs expect Furo to be installed, so we overwrite w/ this path text = text.replace("src/furo", "src/sphinx_book_theme") diff --git a/src/sphinx_book_theme/__init__.py b/src/sphinx_book_theme/__init__.py index 4c583c97..66b70e89 100644 --- a/src/sphinx_book_theme/__init__.py +++ b/src/sphinx_book_theme/__init__.py @@ -2,27 +2,27 @@ import hashlib import os +from functools import cache, lru_cache from pathlib import Path -from functools import lru_cache from docutils import nodes as docutil_nodes +from pydata_sphinx_theme.utils import get_theme_options_dict from sphinx.application import Sphinx from sphinx.locale import get_translation from sphinx.util import logging -from pydata_sphinx_theme.utils import get_theme_options_dict +from ._compat import findall +from ._transforms import HandleFootnoteTransform from .directives import Margin -from .nodes import SideNoteNode from .header_buttons import ( - prep_header_buttons, add_header_buttons, - update_sourcename, + prep_header_buttons, update_context_with_repository_info, + update_sourcename, ) from .header_buttons.launch import add_launch_buttons from .header_buttons.source import add_source_buttons -from ._compat import findall -from ._transforms import HandleFootnoteTransform +from .nodes import SideNoteNode __version__ = "1.5.0.dev" """sphinx-book-theme version""" @@ -74,7 +74,7 @@ def add_metadata_to_page(app, pagename, templatename, context, doctree): context["theme_search_bar_text"] = translation("Search") + "..." -@lru_cache(maxsize=None) +@cache def _gen_hash(path: str) -> str: return hashlib.sha1(path.read_bytes()).hexdigest() @@ -173,7 +173,7 @@ def check_deprecation_keys(app): for key in deprecated_config_list: if key in get_theme_options_dict(app): SPHINX_LOGGER.warning( - f"'{key}' was deprecated from version 0.3.4 onwards. See the CHANGELOG for more information: https://github.com/executablebooks/sphinx-book-theme/blob/master/CHANGELOG.md" # noqa: E501 + f"'{key}' was deprecated from version 0.3.4 onwards. See the CHANGELOG for more information: https://github.com/executablebooks/sphinx-book-theme/blob/master/CHANGELOG.md" f"[{DEFAULT_LOG_TYPE}]", type=DEFAULT_LOG_TYPE, ) diff --git a/src/sphinx_book_theme/_compat.py b/src/sphinx_book_theme/_compat.py index 4e2940cc..549f6298 100644 --- a/src/sphinx_book_theme/_compat.py +++ b/src/sphinx_book_theme/_compat.py @@ -1,6 +1,7 @@ -from docutils.nodes import Element from collections.abc import Iterator +from docutils.nodes import Element + def findall(node: Element, *args, **kwargs) -> Iterator[Element]: # findall replaces traverse in docutils v0.18 diff --git a/src/sphinx_book_theme/_compile_translations.py b/src/sphinx_book_theme/_compile_translations.py index 5f188f6b..95f70115 100644 --- a/src/sphinx_book_theme/_compile_translations.py +++ b/src/sphinx_book_theme/_compile_translations.py @@ -2,8 +2,8 @@ import json import os -from pathlib import Path import subprocess +from pathlib import Path # In case the smodin.io code is different from the Sphinx code RENAME_LANGUAGE_CODES = { @@ -34,7 +34,7 @@ def convert_json(folder=None): if language in RENAME_LANGUAGE_CODES: language = RENAME_LANGUAGE_CODES[language] out_path = ( - out_folder / "locales" / language / "LC_MESSAGES" / "booktheme.po" # noqa: E501 + out_folder / "locales" / language / "LC_MESSAGES" / "booktheme.po" ) if not out_path.parent.exists(): out_path.parent.mkdir(parents=True) diff --git a/src/sphinx_book_theme/_transforms.py b/src/sphinx_book_theme/_transforms.py index 93843402..577a6a7c 100644 --- a/src/sphinx_book_theme/_transforms.py +++ b/src/sphinx_book_theme/_transforms.py @@ -1,10 +1,12 @@ -from sphinx.transforms.post_transforms import SphinxPostTransform from typing import Any + from docutils import nodes as docutil_nodes -from sphinx import addnodes as sphinx_nodes from pydata_sphinx_theme.utils import get_theme_options_dict -from .nodes import SideNoteNode +from sphinx import addnodes as sphinx_nodes +from sphinx.transforms.post_transforms import SphinxPostTransform + from ._compat import findall +from .nodes import SideNoteNode class HandleFootnoteTransform(SphinxPostTransform): @@ -16,7 +18,7 @@ class HandleFootnoteTransform(SphinxPostTransform): def run(self, **kwargs: Any) -> None: theme_options = get_theme_options_dict(self.app) if theme_options.get("use_sidenotes", False) is False: - return None + return # Cycle through footnote references, and move their content next to the # reference. This lets us display the reference in the margin, # or just below on narrow screens. diff --git a/src/sphinx_book_theme/header_buttons/__init__.py b/src/sphinx_book_theme/header_buttons/__init__.py index 286492af..906afbd0 100644 --- a/src/sphinx_book_theme/header_buttons/__init__.py +++ b/src/sphinx_book_theme/header_buttons/__init__.py @@ -1,12 +1,10 @@ """Generate metadata for header buttons.""" +from pydata_sphinx_theme.utils import config_provided_by_user, get_theme_options_dict from sphinx.errors import SphinxError from sphinx.locale import get_translation -from pydata_sphinx_theme.utils import config_provided_by_user, get_theme_options_dict - from sphinx.util import logging - LOGGER = logging.getLogger(__name__) MESSAGE_CATALOG_NAME = "booktheme" translation = get_translation(MESSAGE_CATALOG_NAME) @@ -167,7 +165,7 @@ def update_context_with_repository_info(app): # If no provider is given, try to infer one from the repo url if provider == "": - for iprov in default_provider_urls.keys(): + for iprov in default_provider_urls: if iprov in provider_url.lower(): provider = iprov break diff --git a/src/sphinx_book_theme/header_buttons/launch.py b/src/sphinx_book_theme/header_buttons/launch.py index 5ef0f0f1..b439ac38 100644 --- a/src/sphinx_book_theme/header_buttons/launch.py +++ b/src/sphinx_book_theme/header_buttons/launch.py @@ -1,18 +1,17 @@ """Launch buttons for Binder / Thebe / Colab / etc.""" from pathlib import Path -from typing import Any, Optional -from urllib.parse import urlencode, quote +from shutil import copy2 +from typing import Any +from urllib.parse import quote, urlencode from docutils.nodes import document from sphinx.application import Sphinx from sphinx.locale import get_translation from sphinx.util import logging -from shutil import copy2 from . import get_repo_parts, get_repo_url - SPHINX_LOGGER = logging.getLogger(__name__) MESSAGE_CATALOG_NAME = "booktheme" @@ -24,7 +23,7 @@ def add_launch_buttons( pagename: str, templatename: str, context: dict[str, Any], - doctree: Optional[document], + doctree: document | None, ): """Builds a binder link and inserts it in HTML context for use in templating. diff --git a/src/sphinx_book_theme/header_buttons/source.py b/src/sphinx_book_theme/header_buttons/source.py index a78ac73f..3e8f47c6 100644 --- a/src/sphinx_book_theme/header_buttons/source.py +++ b/src/sphinx_book_theme/header_buttons/source.py @@ -88,9 +88,9 @@ def add_source_buttons(app, pagename, templatename, context, doctree): repo_url, provider = get_repo_url(context) if provider in ("github", "gitlab"): if provider == "github": - url = f"{repo_url}/issues/new?title=Issue%20on%20page%20%2F{context['pagename']}.html&body=Your%20issue%20content%20here." # noqa: E501 + url = f"{repo_url}/issues/new?title=Issue%20on%20page%20%2F{context['pagename']}.html&body=Your%20issue%20content%20here." elif provider == "gitlab": - url = f"{repo_url}/-/issues/new?issue[title]=Issue%20on%20page%20%2F{context['pagename']}.html&issue[description]=Your%20issue%20content%20here." # noqa: E501 + url = f"{repo_url}/-/issues/new?issue[title]=Issue%20on%20page%20%2F{context['pagename']}.html&issue[description]=Your%20issue%20content%20here." repo_buttons.append( { "type": "link", diff --git a/src/sphinx_book_theme/nodes.py b/src/sphinx_book_theme/nodes.py index 7735652c..f68d7bc3 100644 --- a/src/sphinx_book_theme/nodes.py +++ b/src/sphinx_book_theme/nodes.py @@ -1,6 +1,7 @@ +from typing import Any, cast + from docutils import nodes from sphinx.application import Sphinx -from typing import Any, cast class SideNoteNode(nodes.Element): diff --git a/tests/test_build.py b/tests/test_build.py index 360a01f0..988b8e99 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -1,15 +1,14 @@ import os +from importlib.metadata import version from pathlib import Path from shutil import copytree, rmtree -from importlib.metadata import version -from packaging.version import parse -from bs4 import BeautifulSoup import pytest import sphinx +from bs4 import BeautifulSoup +from packaging.version import parse from sphinx.testing.util import SphinxTestApp - sphinx_version = parse(version("sphinx")) path_tests = Path(__file__).parent @@ -351,7 +350,7 @@ def test_repo_custombranch(sphinx_build_factory, file_regression): "html_theme_options": { "repository_branch": "foo", "use_edit_page_button": True, - "repository_url": "https://github.com/executablebooks/sphinx-book-theme", # noqa: E501 + "repository_url": "https://github.com/executablebooks/sphinx-book-theme", "launch_buttons": {"binderhub_url": "https://mybinder.org"}, "navigation_with_keys": True, }