From 9d7f6f1caf84cd528aa7c60a9631f00b7aefc7e9 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Fri, 11 Oct 2024 20:10:46 +0200 Subject: [PATCH] MAINT: drop Python 3.7 & 3.8 support due to EOL (#418) * DX: run label sync on Python 3.12 * MAINT: modernize Python syntax to Python 3.9 * MAINT: switch to single quotation marks for sorting --- .github/workflows/sync-labels.yml | 2 +- pyproject.toml | 7 ++---- src/compwa_policy/check_dev_files/__init__.py | 11 +++++--- src/compwa_policy/check_dev_files/conda.py | 8 +----- src/compwa_policy/check_dev_files/cspell.py | 3 ++- .../check_dev_files/dependabot.py | 7 +----- .../check_dev_files/precommit.py | 4 ++- src/compwa_policy/check_dev_files/prettier.py | 4 ++- src/compwa_policy/check_dev_files/pytest.py | 4 ++- .../check_dev_files/pyupgrade.py | 2 +- src/compwa_policy/check_dev_files/ruff.py | 6 +++-- .../check_dev_files/update_pip_constraints.py | 8 +----- src/compwa_policy/colab_toc_visible.py | 5 +++- src/compwa_policy/fix_nbformat_version.py | 5 +++- src/compwa_policy/remove_empty_tags.py | 5 +++- src/compwa_policy/set_nb_cells.py | 5 +++- src/compwa_policy/utilities/cfg.py | 5 +++- .../utilities/precommit/struct.py | 10 +++----- .../utilities/pyproject/__init__.py | 19 +++----------- .../utilities/pyproject/_struct.py | 14 ++++------- .../utilities/pyproject/getters.py | 8 +----- .../utilities/pyproject/setters.py | 3 ++- src/compwa_policy/utilities/toml.py | 4 ++- src/compwa_policy/utilities/vscode.py | 5 ++-- .../editorconfig/test_editorconfig.py | 7 +++--- tests/check_dev_files/pyright/test_pyright.py | 25 +++++++++++-------- tests/check_dev_files/test_cspell.py | 7 +++--- tests/check_dev_files/test_pixi.py | 8 +++--- tests/utilities/precommit/test_class.py | 15 +++++------ 29 files changed, 104 insertions(+), 112 deletions(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index ac660d85..ba8685f8 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: "3.7" + python-version: "3.12" - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/pyproject.toml b/pyproject.toml index f2f481dd..ab40df76 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,8 +16,6 @@ classifiers = [ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python", "Typing :: Typed", @@ -30,9 +28,9 @@ dependencies = [ "nbformat", "pathspec", "pip-tools", + "rtoml", # fast, read-only parsing "ruamel.yaml", # better YAML dumping "tomlkit", # preserve original TOML formatting - 'rtoml', # fast, read-only parsing 'typing-extensions; python_version <"3.12.0"', # override ] description = "Pre-commit hooks that ensure that ComPWA repositories have a similar developer set-up" @@ -40,7 +38,7 @@ dynamic = ["version"] license = {text = "BSD 3-Clause License"} maintainers = [{email = "compwa-admin@ep1.rub.de"}] name = "compwa-policy" -requires-python = ">=3.7" +requires-python = ">=3.9" [project.optional-dependencies] dev = [ @@ -50,7 +48,6 @@ dev = [ "labels", "sphinx-autobuild", "tox >=1.9", # for skip_install, use_develop - 'sphinx-autobuild!=2024.4.*; python_version <"3.10.0"', ] doc = [ "Sphinx", diff --git a/src/compwa_policy/check_dev_files/__init__.py b/src/compwa_policy/check_dev_files/__init__.py index 11338f62..2c60bb90 100644 --- a/src/compwa_policy/check_dev_files/__init__.py +++ b/src/compwa_policy/check_dev_files/__init__.py @@ -6,7 +6,7 @@ import sys from argparse import ArgumentParser from textwrap import dedent -from typing import TYPE_CHECKING, Any, Sequence +from typing import TYPE_CHECKING, Any from compwa_policy.check_dev_files import ( black, @@ -42,6 +42,8 @@ from compwa_policy.utilities.precommit import ModifiablePrecommit if TYPE_CHECKING: + from collections.abc import Sequence + from compwa_policy.utilities.pyproject import PythonVersion @@ -57,9 +59,10 @@ def main(argv: Sequence[str] | None = None) -> int: package_managers: set[conda.PackageManagerChoice] = set( _to_list(args.package_managers) # type: ignore[arg-type] ) - with Executor( - raise_exception=False - ) as do, ModifiablePrecommit.load() as precommit_config: + with ( + Executor(raise_exception=False) as do, + ModifiablePrecommit.load() as precommit_config, + ): do(citation.main, precommit_config) do(commitlint.main) do(conda.main, dev_python_version, package_managers) diff --git a/src/compwa_policy/check_dev_files/conda.py b/src/compwa_policy/check_dev_files/conda.py index 44d743b2..6e783ba8 100644 --- a/src/compwa_policy/check_dev_files/conda.py +++ b/src/compwa_policy/check_dev_files/conda.py @@ -2,8 +2,7 @@ from __future__ import annotations -import sys -from typing import NoReturn +from typing import Literal, NoReturn from ruamel.yaml.comments import CommentedMap, CommentedSeq from ruamel.yaml.scalarstring import PlainScalarString @@ -18,11 +17,6 @@ ) from compwa_policy.utilities.yaml import create_prettier_round_trip_yaml -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal - PackageManagerChoice = Literal["conda", "pixi", "uv", "venv"] """Package managers you want to develop the project with.""" diff --git a/src/compwa_policy/check_dev_files/cspell.py b/src/compwa_policy/check_dev_files/cspell.py index 7ac7d294..62175861 100644 --- a/src/compwa_policy/check_dev_files/cspell.py +++ b/src/compwa_policy/check_dev_files/cspell.py @@ -8,7 +8,7 @@ import json import os -from typing import TYPE_CHECKING, Any, Iterable, Sequence +from typing import TYPE_CHECKING, Any from compwa_policy.errors import PrecommitError from compwa_policy.utilities import COMPWA_POLICY_DIR, CONFIG_PATH, rename_file, vscode @@ -18,6 +18,7 @@ from compwa_policy.utilities.readme import add_badge, remove_badge if TYPE_CHECKING: + from collections.abc import Iterable, Sequence from pathlib import Path from compwa_policy.utilities.precommit import ModifiablePrecommit diff --git a/src/compwa_policy/check_dev_files/dependabot.py b/src/compwa_policy/check_dev_files/dependabot.py index 14e37da1..844a4d74 100644 --- a/src/compwa_policy/check_dev_files/dependabot.py +++ b/src/compwa_policy/check_dev_files/dependabot.py @@ -2,16 +2,11 @@ from __future__ import annotations -import sys -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Literal from compwa_policy.errors import PrecommitError from compwa_policy.utilities import COMPWA_POLICY_DIR, CONFIG_PATH -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal if TYPE_CHECKING: from pathlib import Path diff --git a/src/compwa_policy/check_dev_files/precommit.py b/src/compwa_policy/check_dev_files/precommit.py index a20a0bd4..a7bb445e 100644 --- a/src/compwa_policy/check_dev_files/precommit.py +++ b/src/compwa_policy/check_dev_files/precommit.py @@ -4,7 +4,7 @@ import re from pathlib import Path -from typing import TYPE_CHECKING, Any, MutableMapping, cast +from typing import TYPE_CHECKING, Any, cast from ruamel.yaml.comments import CommentedMap, CommentedSeq @@ -21,6 +21,8 @@ from compwa_policy.utilities.yaml import create_prettier_round_trip_yaml if TYPE_CHECKING: + from collections.abc import MutableMapping + from compwa_policy.utilities.precommit import ( ModifiablePrecommit, Precommit, diff --git a/src/compwa_policy/check_dev_files/prettier.py b/src/compwa_policy/check_dev_files/prettier.py index 72a96b70..11652931 100644 --- a/src/compwa_policy/check_dev_files/prettier.py +++ b/src/compwa_policy/check_dev_files/prettier.py @@ -3,7 +3,7 @@ from __future__ import annotations import os -from typing import TYPE_CHECKING, Iterable +from typing import TYPE_CHECKING from compwa_policy.errors import PrecommitError from compwa_policy.utilities import COMPWA_POLICY_DIR, CONFIG_PATH, vscode @@ -11,6 +11,8 @@ from compwa_policy.utilities.readme import add_badge, remove_badge if TYPE_CHECKING: + from collections.abc import Iterable + from compwa_policy.utilities.precommit import ModifiablePrecommit # cspell:ignore esbenp rettier diff --git a/src/compwa_policy/check_dev_files/pytest.py b/src/compwa_policy/check_dev_files/pytest.py index 18255498..06f50e1d 100644 --- a/src/compwa_policy/check_dev_files/pytest.py +++ b/src/compwa_policy/check_dev_files/pytest.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Iterable +from typing import TYPE_CHECKING import rtoml from ini2toml.api import Translator @@ -14,6 +14,8 @@ from compwa_policy.utilities.toml import to_toml_array if TYPE_CHECKING: + from collections.abc import Iterable + from tomlkit.items import Array diff --git a/src/compwa_policy/check_dev_files/pyupgrade.py b/src/compwa_policy/check_dev_files/pyupgrade.py index 012e299e..2cafb5c5 100644 --- a/src/compwa_policy/check_dev_files/pyupgrade.py +++ b/src/compwa_policy/check_dev_files/pyupgrade.py @@ -46,7 +46,7 @@ def __get_pyupgrade_version_argument() -> CommentedSeq: """Get the --py3x-plus argument for pyupgrade. >>> __get_pyupgrade_version_argument() - ['--py37-plus'] + ['--py39-plus'] """ supported_python_versions = Pyproject.load().get_supported_python_versions() lowest_version = supported_python_versions[0] diff --git a/src/compwa_policy/check_dev_files/ruff.py b/src/compwa_policy/check_dev_files/ruff.py index 84d2d4c6..5a6480ef 100644 --- a/src/compwa_policy/check_dev_files/ruff.py +++ b/src/compwa_policy/check_dev_files/ruff.py @@ -4,7 +4,7 @@ import os from collections import abc -from typing import TYPE_CHECKING, Any, Iterable, Mapping +from typing import TYPE_CHECKING, Any from ruamel.yaml import YAML @@ -22,6 +22,8 @@ from compwa_policy.utilities.toml import to_toml_array if TYPE_CHECKING: + from collections.abc import Iterable, Mapping + from tomlkit.items import Array from compwa_policy.utilities.precommit import ModifiablePrecommit @@ -254,7 +256,7 @@ def ___get_target_version(pyproject: Pyproject) -> str: >>> pyproject = Pyproject.load() >>> ___get_target_version(pyproject) - 'py37' + 'py39' """ supported_python_versions = pyproject.get_supported_python_versions() versions = {f'py{v.replace(".", "")}' for v in supported_python_versions} diff --git a/src/compwa_policy/check_dev_files/update_pip_constraints.py b/src/compwa_policy/check_dev_files/update_pip_constraints.py index 493ce69a..c56ed628 100644 --- a/src/compwa_policy/check_dev_files/update_pip_constraints.py +++ b/src/compwa_policy/check_dev_files/update_pip_constraints.py @@ -7,8 +7,7 @@ from __future__ import annotations -import sys -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Literal from compwa_policy.check_dev_files.github_workflows import ( remove_workflow, @@ -23,11 +22,6 @@ if TYPE_CHECKING: from compwa_policy.utilities.precommit import Precommit -if sys.version_info < (3, 8): - from typing_extensions import Literal -else: - from typing import Literal - Frequency = Literal[ "no", diff --git a/src/compwa_policy/colab_toc_visible.py b/src/compwa_policy/colab_toc_visible.py index 9c373f47..3a63a73a 100644 --- a/src/compwa_policy/colab_toc_visible.py +++ b/src/compwa_policy/colab_toc_visible.py @@ -8,7 +8,7 @@ import argparse import sys -from typing import Sequence +from typing import TYPE_CHECKING import nbformat @@ -16,6 +16,9 @@ from compwa_policy.utilities.executor import Executor from compwa_policy.utilities.notebook import load_notebook +if TYPE_CHECKING: + from collections.abc import Sequence + def main(argv: Sequence[str] | None = None) -> int: parser = argparse.ArgumentParser(__doc__) diff --git a/src/compwa_policy/fix_nbformat_version.py b/src/compwa_policy/fix_nbformat_version.py index de8f35a1..46003b60 100644 --- a/src/compwa_policy/fix_nbformat_version.py +++ b/src/compwa_policy/fix_nbformat_version.py @@ -9,7 +9,7 @@ import argparse import sys from textwrap import dedent -from typing import Sequence +from typing import TYPE_CHECKING import nbformat @@ -17,6 +17,9 @@ from compwa_policy.utilities.executor import Executor from compwa_policy.utilities.notebook import load_notebook +if TYPE_CHECKING: + from collections.abc import Sequence + BINARY_CELL_OUTPUT = [ "image/jpeg", "image/png", diff --git a/src/compwa_policy/remove_empty_tags.py b/src/compwa_policy/remove_empty_tags.py index 0167cc7a..11db5b76 100644 --- a/src/compwa_policy/remove_empty_tags.py +++ b/src/compwa_policy/remove_empty_tags.py @@ -4,7 +4,7 @@ import argparse import sys -from typing import Sequence +from typing import TYPE_CHECKING import nbformat @@ -12,6 +12,9 @@ from compwa_policy.utilities.executor import Executor from compwa_policy.utilities.notebook import load_notebook +if TYPE_CHECKING: + from collections.abc import Sequence + def main(argv: Sequence[str] | None = None) -> int: parser = argparse.ArgumentParser(__doc__) diff --git a/src/compwa_policy/set_nb_cells.py b/src/compwa_policy/set_nb_cells.py index 9c4d4d43..b8a085dd 100644 --- a/src/compwa_policy/set_nb_cells.py +++ b/src/compwa_policy/set_nb_cells.py @@ -24,13 +24,16 @@ import sys from functools import lru_cache from textwrap import dedent -from typing import Sequence +from typing import TYPE_CHECKING import nbformat from compwa_policy.utilities.notebook import load_notebook from compwa_policy.utilities.pyproject import Pyproject +if TYPE_CHECKING: + from collections.abc import Sequence + __CONFIG_CELL_CONTENT = """ import os diff --git a/src/compwa_policy/utilities/cfg.py b/src/compwa_policy/utilities/cfg.py index c092952d..22b99a56 100644 --- a/src/compwa_policy/utilities/cfg.py +++ b/src/compwa_policy/utilities/cfg.py @@ -6,11 +6,14 @@ import re from configparser import ConfigParser from pathlib import Path -from typing import Callable, Iterable +from typing import TYPE_CHECKING, Callable from compwa_policy.errors import PrecommitError from compwa_policy.utilities import read, write +if TYPE_CHECKING: + from collections.abc import Iterable + def format_config( input: Path | io.TextIOBase | str, # noqa: A002 diff --git a/src/compwa_policy/utilities/precommit/struct.py b/src/compwa_policy/utilities/precommit/struct.py index 5f316829..86dc3c44 100644 --- a/src/compwa_policy/utilities/precommit/struct.py +++ b/src/compwa_policy/utilities/precommit/struct.py @@ -2,13 +2,9 @@ from __future__ import annotations import sys -from functools import lru_cache -from typing import ForwardRef +from functools import cache +from typing import ForwardRef, Literal, TypedDict -if sys.version_info < (3, 8): - from typing_extensions import Literal, TypedDict -else: - from typing import Literal, TypedDict if sys.version_info < (3, 11): from typing_extensions import NotRequired else: @@ -76,7 +72,7 @@ def validate(config: PrecommitConfig) -> None: raise ValueError(msg) -@lru_cache(maxsize=None) +@cache def _get_required_keys(struct: type) -> set[str]: annotations: dict[str, ForwardRef] = struct.__annotations__ return { diff --git a/src/compwa_policy/utilities/pyproject/__init__.py b/src/compwa_policy/utilities/pyproject/__init__.py index 15335f96..775c1205 100644 --- a/src/compwa_policy/utilities/pyproject/__init__.py +++ b/src/compwa_policy/utilities/pyproject/__init__.py @@ -8,17 +8,7 @@ from contextlib import AbstractContextManager from pathlib import Path from textwrap import indent -from typing import ( - IO, - TYPE_CHECKING, - Any, - Iterable, - Mapping, - MutableMapping, - Sequence, - TypeVar, - overload, -) +from typing import IO, TYPE_CHECKING, Any, Literal, TypeVar, final, overload import rtoml import tomlkit @@ -41,10 +31,6 @@ remove_dependency, ) -if sys.version_info < (3, 8): - from typing_extensions import Literal, final -else: - from typing import Literal, final if sys.version_info < (3, 11): from typing_extensions import Self else: @@ -54,6 +40,7 @@ else: from typing import override if TYPE_CHECKING: + from collections.abc import Iterable, Mapping, MutableMapping, Sequence from types import TracebackType from compwa_policy.utilities.pyproject._struct import PyprojectTOML @@ -114,7 +101,7 @@ def get_supported_python_versions(self) -> list[PythonVersion]: """Extract sorted, supported Python versions from package classifiers. >>> Pyproject.load().get_supported_python_versions() - ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] + ['3.9', '3.10', '3.11', '3.12'] """ return get_supported_python_versions(self._document) diff --git a/src/compwa_policy/utilities/pyproject/_struct.py b/src/compwa_policy/utilities/pyproject/_struct.py index 488c13c0..7adc7984 100644 --- a/src/compwa_policy/utilities/pyproject/_struct.py +++ b/src/compwa_policy/utilities/pyproject/_struct.py @@ -5,12 +5,8 @@ """ import sys -from typing import Dict, List +from typing import TypedDict -if sys.version_info < (3, 8): - from typing_extensions import TypedDict -else: - from typing import TypedDict if sys.version_info < (3, 11): from typing_extensions import NotRequired else: @@ -21,7 +17,7 @@ { "build-system": NotRequired["BuildSystem"], "project": "Project", - "tool": NotRequired[Dict[str, Dict[str, str]]], + "tool": NotRequired[dict[str, dict[str, str]]], }, ) """Structure of a `pyproject.toml` file. @@ -34,7 +30,7 @@ BuildSystem = TypedDict( "BuildSystem", { - "requires": List[str], + "requires": list[str], "build-backend": str, }, ) @@ -45,8 +41,8 @@ { "name": str, "version": NotRequired[str], - "dependencies": NotRequired[List[str]], - "optional-dependencies": NotRequired[Dict[str, List[str]]], + "dependencies": NotRequired[list[str]], + "optional-dependencies": NotRequired[dict[str, list[str]]], "urls": NotRequired["ProjectURLs"], }, ) diff --git a/src/compwa_policy/utilities/pyproject/getters.py b/src/compwa_policy/utilities/pyproject/getters.py index bc9037ba..f00560e6 100644 --- a/src/compwa_policy/utilities/pyproject/getters.py +++ b/src/compwa_policy/utilities/pyproject/getters.py @@ -2,9 +2,8 @@ from __future__ import annotations -import sys from textwrap import dedent -from typing import TYPE_CHECKING, Any, overload +from typing import TYPE_CHECKING, Any, Literal, overload from compwa_policy.errors import PrecommitError @@ -13,11 +12,6 @@ from compwa_policy.utilities.pyproject._struct import ProjectURLs, PyprojectTOML -if sys.version_info < (3, 8): - from typing_extensions import Literal -else: - from typing import Literal - PythonVersion = Literal["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] diff --git a/src/compwa_policy/utilities/pyproject/setters.py b/src/compwa_policy/utilities/pyproject/setters.py index 9762ae06..fe51633d 100644 --- a/src/compwa_policy/utilities/pyproject/setters.py +++ b/src/compwa_policy/utilities/pyproject/setters.py @@ -3,7 +3,8 @@ from __future__ import annotations from collections import abc -from typing import TYPE_CHECKING, Any, Iterable, Mapping, MutableMapping, Sequence, cast +from collections.abc import Iterable, Mapping, MutableMapping, Sequence +from typing import TYPE_CHECKING, Any, cast import tomlkit diff --git a/src/compwa_policy/utilities/toml.py b/src/compwa_policy/utilities/toml.py index 0fdbc6dd..9f7df372 100644 --- a/src/compwa_policy/utilities/toml.py +++ b/src/compwa_policy/utilities/toml.py @@ -2,12 +2,14 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Iterable +from typing import TYPE_CHECKING, Any import tomlkit from tomlkit.items import String, StringType, Trivia if TYPE_CHECKING: + from collections.abc import Iterable + from tomlkit.items import Array diff --git a/src/compwa_policy/utilities/vscode.py b/src/compwa_policy/utilities/vscode.py index 6377e1aa..de227e9e 100644 --- a/src/compwa_policy/utilities/vscode.py +++ b/src/compwa_policy/utilities/vscode.py @@ -4,7 +4,8 @@ import json from collections import abc -from typing import TYPE_CHECKING, Any, Dict, Iterable, TypeVar, Union +from collections.abc import Iterable +from typing import TYPE_CHECKING, Any, TypeVar, Union from compwa_policy.errors import PrecommitError from compwa_policy.utilities import CONFIG_PATH @@ -18,7 +19,7 @@ V = TypeVar("V") -RemovedKeys = Union[Iterable[str], Dict[str, "RemovedKeys"]] +RemovedKeys = Union[Iterable[str], dict[str, "RemovedKeys"]] """Type for keys to be removed from a (nested) dictionary.""" diff --git a/tests/check_dev_files/editorconfig/test_editorconfig.py b/tests/check_dev_files/editorconfig/test_editorconfig.py index 90e8cbb7..b3530ba0 100644 --- a/tests/check_dev_files/editorconfig/test_editorconfig.py +++ b/tests/check_dev_files/editorconfig/test_editorconfig.py @@ -14,9 +14,10 @@ def test_update_precommit_config(): src = file.read() stream = io.StringIO(src) - with pytest.raises( - PrecommitError, match=r"Updated editorconfig-checker hook" - ), ModifiablePrecommit.load(stream) as precommit: + with ( + pytest.raises(PrecommitError, match=r"Updated editorconfig-checker hook"), + ModifiablePrecommit.load(stream) as precommit, + ): _update_precommit_config(precommit) result = precommit.dumps() diff --git a/tests/check_dev_files/pyright/test_pyright.py b/tests/check_dev_files/pyright/test_pyright.py index 4665727f..c14d558b 100644 --- a/tests/check_dev_files/pyright/test_pyright.py +++ b/tests/check_dev_files/pyright/test_pyright.py @@ -23,10 +23,13 @@ def this_dir() -> Path: def test_merge_config_into_pyproject(this_dir: Path): input_stream = io.StringIO() old_config_path = this_dir / "pyrightconfig.json" - with pytest.raises( - PrecommitError, - match=re.escape(f"Imported pyright configuration from {old_config_path}"), - ), ModifiablePyproject.load(input_stream) as pyproject: + with ( + pytest.raises( + PrecommitError, + match=re.escape(f"Imported pyright configuration from {old_config_path}"), + ), + ModifiablePyproject.load(input_stream) as pyproject, + ): _merge_config_into_pyproject(pyproject, old_config_path, remove=False) result = input_stream.getvalue() @@ -45,9 +48,10 @@ def test_update_precommit(this_dir: Path): pyproject = Pyproject.load(this_dir / "pyproject-bad.toml") with open(this_dir / ".pre-commit-config-bad.yaml") as stream: input_stream = io.StringIO(stream.read()) - with pytest.raises(PrecommitError), ModifiablePrecommit.load( - input_stream - ) as precommit: + with ( + pytest.raises(PrecommitError), + ModifiablePrecommit.load(input_stream) as precommit, + ): _update_precommit(precommit, pyproject) result = input_stream.getvalue() @@ -59,9 +63,10 @@ def test_update_precommit(this_dir: Path): def test_update_settings(this_dir: Path): with open(this_dir / "pyproject-bad.toml") as stream: input_stream = io.StringIO(stream.read()) - with pytest.raises( - PrecommitError, match=r"Updated pyright configuration" - ), ModifiablePyproject.load(input_stream) as pyproject: + with ( + pytest.raises(PrecommitError, match=r"Updated pyright configuration"), + ModifiablePyproject.load(input_stream) as pyproject, + ): _update_settings(pyproject) result = input_stream.getvalue() diff --git a/tests/check_dev_files/test_cspell.py b/tests/check_dev_files/test_cspell.py index 172234b8..ffc8eac6 100644 --- a/tests/check_dev_files/test_cspell.py +++ b/tests/check_dev_files/test_cspell.py @@ -9,9 +9,10 @@ def test_update_cspell_repo_url(bad_yaml: io.StringIO, good_yaml: io.StringIO): - with pytest.raises( - PrecommitError, match=r"Updated cSpell pre-commit repo URL" - ), ModifiablePrecommit.load(bad_yaml) as bad: + with ( + pytest.raises(PrecommitError, match=r"Updated cSpell pre-commit repo URL"), + ModifiablePrecommit.load(bad_yaml) as bad, + ): _update_cspell_repo_url(bad) good = Precommit.load(good_yaml) diff --git a/tests/check_dev_files/test_pixi.py b/tests/check_dev_files/test_pixi.py index 7f91e785..e7c5d54e 100644 --- a/tests/check_dev_files/test_pixi.py +++ b/tests/check_dev_files/test_pixi.py @@ -25,10 +25,10 @@ def test_update_docnb_and_doclive(table_key: str): [{table_key}.docnb-test] cmd = "should not change" """) - with pytest.raises( - PrecommitError, - match="Updated `cmd` of Pixi tasks docnb", - ), ModifiablePyproject.load(content) as pyproject: + with ( + pytest.raises(PrecommitError, match="Updated `cmd` of Pixi tasks docnb"), + ModifiablePyproject.load(content) as pyproject, + ): __update_docnb_and_doclive(pyproject, table_key) new_content = pyproject.dumps() expected = dedent(f""" diff --git a/tests/utilities/precommit/test_class.py b/tests/utilities/precommit/test_class.py index f7e440d5..db2a44b6 100644 --- a/tests/utilities/precommit/test_class.py +++ b/tests/utilities/precommit/test_class.py @@ -30,19 +30,20 @@ def test_no_context_manager(self, example_config: str): def test_context_manager_path(self, example_config: str): input_stream = io.StringIO(example_config) - with pytest.raises( - PrecommitError, - match=r"Fake modification$", - ), ModifiablePrecommit.load(input_stream) as precommit: + with ( + pytest.raises(PrecommitError, match=r"Fake modification$"), + ModifiablePrecommit.load(input_stream) as precommit, + ): precommit.changelog.append("Fake modification") yaml = precommit.dumps() assert yaml == example_config def test_context_manager_string_stream(self, example_config: str): stream = io.StringIO(example_config) - with pytest.raises( - PrecommitError, match=r"Fake modification$" - ), ModifiablePrecommit.load(stream) as precommit: + with ( + pytest.raises(PrecommitError, match=r"Fake modification$"), + ModifiablePrecommit.load(stream) as precommit, + ): precommit.changelog.append("Fake modification") stream.seek(0) yaml = stream.read()