From 8822eeff673f14e627925a51070d5eeaf3360dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20K=C5=82oczko?= <31284574+kloczek@users.noreply.github.com> Date: Mon, 23 Dec 2024 17:59:56 +0000 Subject: [PATCH] really drop python<=3.8 support (#844) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * really drop python<=3.8 support Filter all code over `pyupgrade --py39-plus`. Signed-off-by: Tomasz Kłoczko * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Tomasz Kłoczko Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Angus Hollands Co-authored-by: Chris Holdgraf --- src/sphinx_book_theme/__init__.py | 6 ++---- src/sphinx_book_theme/_compat.py | 2 +- src/sphinx_book_theme/header_buttons/__init__.py | 6 ++---- src/sphinx_book_theme/header_buttons/launch.py | 12 +++++------- tests/test_build.py | 2 +- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/sphinx_book_theme/__init__.py b/src/sphinx_book_theme/__init__.py index f38b8a80..146a36b6 100644 --- a/src/sphinx_book_theme/__init__.py +++ b/src/sphinx_book_theme/__init__.py @@ -140,10 +140,8 @@ def update_mode_thebe_config(app): # but has not activated the sphinx_thebe extension. if not hasattr(app.env.config, "thebe_config"): SPHINX_LOGGER.warning( - ( - "Thebe is activated but not added to extensions list. " - "Add `sphinx_thebe` to your site's extensions list." - ) + "Thebe is activated but not added to extensions list. " + "Add `sphinx_thebe` to your site's extensions list." ) return # Will be empty if it doesn't exist diff --git a/src/sphinx_book_theme/_compat.py b/src/sphinx_book_theme/_compat.py index 99e70b8d..4e2940cc 100644 --- a/src/sphinx_book_theme/_compat.py +++ b/src/sphinx_book_theme/_compat.py @@ -1,5 +1,5 @@ from docutils.nodes import Element -from typing import Iterator +from collections.abc import Iterator def findall(node: Element, *args, **kwargs) -> Iterator[Element]: diff --git a/src/sphinx_book_theme/header_buttons/__init__.py b/src/sphinx_book_theme/header_buttons/__init__.py index 6e61c8da..3da1736a 100644 --- a/src/sphinx_book_theme/header_buttons/__init__.py +++ b/src/sphinx_book_theme/header_buttons/__init__.py @@ -174,10 +174,8 @@ def update_context_with_repository_info(app): # If provider is still empty, raise an error because we don't recognize it if provider == "": raise SphinxError( - ( - f"Provider not recognized in repository url {repo_url}. " - "If you're using a custom provider URL, specify `repository_provider`" - ) + f"Provider not recognized in repository url {repo_url}. " + "If you're using a custom provider URL, specify `repository_provider`" ) # Update the context because this is what the get_edit_url function uses. diff --git a/src/sphinx_book_theme/header_buttons/launch.py b/src/sphinx_book_theme/header_buttons/launch.py index c00f9293..20f93b4c 100644 --- a/src/sphinx_book_theme/header_buttons/launch.py +++ b/src/sphinx_book_theme/header_buttons/launch.py @@ -1,7 +1,7 @@ """Launch buttons for Binder / Thebe / Colab / etc.""" from pathlib import Path -from typing import Any, Dict, Optional +from typing import Any, Optional from urllib.parse import urlencode, quote from docutils.nodes import document @@ -23,7 +23,7 @@ def add_launch_buttons( app: Sphinx, pagename: str, templatename: str, - context: Dict[str, Any], + context: dict[str, Any], doctree: Optional[document], ): """Builds a binder link and inserts it in HTML context for use in templating. @@ -89,11 +89,9 @@ def add_launch_buttons( notebook_interface = launch_buttons.get("notebook_interface", "classic") if notebook_interface not in notebook_interface_prefixes: raise ValueError( - ( - "Notebook UI for Binder/JupyterHub links must be one" - f"of {tuple(notebook_interface_prefixes.keys())}," - f"not {notebook_interface}" - ) + "Notebook UI for Binder/JupyterHub links must be one" + f"of {tuple(notebook_interface_prefixes.keys())}," + f"not {notebook_interface}" ) ui_pre = notebook_interface_prefixes[notebook_interface] diff --git a/tests/test_build.py b/tests/test_build.py index 77621e5f..9d7b8847 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -86,7 +86,7 @@ def test_build_book(sphinx_build_factory, file_regression): for filename, kernel in kernels_expected.items(): ntbk_html = sphinx_build.html_tree("section1", filename) thebe_config = ntbk_html.find("script", attrs={"type": "text/x-thebe-config"}) - kernel_name = 'name: "{}",'.format(kernel) + kernel_name = f'name: "{kernel}",' if kernel_name not in thebe_config.prettify(): raise AssertionError(f"{kernel_name} not in {kernels_expected}")