From f4d1b3e2fb2cc581e4ef53b64f07ecb61ef9abec Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Sun, 26 Jul 2026 14:51:55 +0200 Subject: [PATCH 1/5] MAINT: upgrade lock files --- .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 851c203e..325464be 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -84,7 +84,7 @@ repos: )$ - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.21 + rev: v0.16.0 hooks: - id: ruff-check args: [--fix] @@ -110,7 +110,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/tombi-toml/tombi-pre-commit - rev: v1.2.0 + rev: v1.2.4 hooks: - id: tombi-format - id: tombi-lint @@ -139,7 +139,7 @@ repos: )$ - repo: https://github.com/astral-sh/ty-pre-commit - rev: v0.0.59 + rev: v0.0.63 hooks: - id: ty args: [--group=types, --no-default-groups] From 06e7ed8811be0c1788c537b8c27053b1b62f5c91 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Sun, 26 Jul 2026 14:51:56 +0200 Subject: [PATCH 2/5] MAINT: update Ruff comments --- .cspell.json | 1 + docs/conf.py | 2 +- src/compwa_policy/cli/__init__.py | 2 +- src/compwa_policy/cli/_checks.py | 6 +++--- src/compwa_policy/cli/env.py | 2 +- src/compwa_policy/cli/github.py | 2 +- src/compwa_policy/cli/nb.py | 2 +- src/compwa_policy/cli/python.py | 2 +- src/compwa_policy/env/pixi/_remove.py | 2 +- src/compwa_policy/env/pixi/_update.py | 12 ++++++------ src/compwa_policy/env/uv.py | 2 +- src/compwa_policy/errors.py | 2 +- src/compwa_policy/format/cspell.py | 2 +- src/compwa_policy/format/precommit.py | 2 +- src/compwa_policy/github/dependabot.py | 2 +- src/compwa_policy/github/workflows.py | 8 ++++---- src/compwa_policy/python/mypy.py | 2 +- src/compwa_policy/python/pyright.py | 2 +- src/compwa_policy/python/ruff.py | 2 +- src/compwa_policy/python/ty.py | 2 +- src/compwa_policy/repo/poe.py | 2 +- src/compwa_policy/self_check.py | 2 +- src/compwa_policy/utilities/__init__.py | 4 ++-- src/compwa_policy/utilities/cfg.py | 2 +- src/compwa_policy/utilities/match.py | 4 ++-- src/compwa_policy/utilities/precommit/getters.py | 8 ++++---- src/compwa_policy/utilities/precommit/setters.py | 2 +- src/compwa_policy/utilities/precommit/struct.py | 2 +- src/compwa_policy/utilities/pyproject/__init__.py | 2 +- src/compwa_policy/utilities/pyproject/setters.py | 2 +- src/compwa_policy/utilities/python.py | 2 +- src/compwa_policy/utilities/readme.py | 2 +- src/compwa_policy/utilities/session.py | 4 ++-- src/compwa_policy/utilities/vscode.py | 2 +- src/compwa_policy/utilities/yaml.py | 2 +- tests/conftest.py | 8 ++++---- 36 files changed, 55 insertions(+), 54 deletions(-) diff --git a/.cspell.json b/.cspell.json index ee0d7a4e..6afc01ff 100644 --- a/.cspell.json +++ b/.cspell.json @@ -61,6 +61,7 @@ "doclive", "docnb", "docnblive", + "dunder", "envrc", "fromdict", "indentless", diff --git a/docs/conf.py b/docs/conf.py index 023f4151..0b8ceaba 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -50,7 +50,7 @@ codeautolink_concat_default = True copybutton_prompt_is_regexp = True copybutton_prompt_text = r">>> |\.\.\. " # doctest -copyright = "2023, Common Partial Wave Analysis" # noqa: A001 +copyright = "2023, Common Partial Wave Analysis" # ruff: ignore[builtin-variable-shadowing] default_role = "py:obj" extensions = [ "_ext.policy_settings", diff --git a/src/compwa_policy/cli/__init__.py b/src/compwa_policy/cli/__init__.py index c97e1fe4..f2b012df 100644 --- a/src/compwa_policy/cli/__init__.py +++ b/src/compwa_policy/cli/__init__.py @@ -82,7 +82,7 @@ def _add(command: Command, name: str, parent: Tree) -> None: @app.callback(invoke_without_command=True) -def run_everything( # noqa: PLR0917 +def run_everything( # ruff: ignore[too-many-positional-arguments] ctx: typer.Context, python: Python = None, dev_python_version: DevPythonVersion = None, diff --git a/src/compwa_policy/cli/_checks.py b/src/compwa_policy/cli/_checks.py index c2bc40fc..0c87d921 100644 --- a/src/compwa_policy/cli/_checks.py +++ b/src/compwa_policy/cli/_checks.py @@ -65,7 +65,7 @@ def check_dev_python_version(args: Arguments) -> int: if CONFIG_PATH.pyproject.exists(): supported_versions = Pyproject.load().get_supported_python_versions() if supported_versions and args.dev_python_version not in supported_versions: - print( # noqa: T201 + print( # ruff: ignore[print] f"The specified development Python version {args.dev_python_version} is" " not listed in the supported Python versions of pyproject.toml:" f" {', '.join(sorted(supported_versions))}" @@ -133,10 +133,10 @@ def _run(args: Arguments, groups: frozenset[Group]) -> int: run_checks(session, args, ctx, groups=groups) changes = session.flush() except PolicyError as exception: - print("\n".join(exception.args)) # noqa: T201 + print("\n".join(exception.args)) # ruff: ignore[print] return 1 if changes: - print("\n--------------------\n".join(changes)) # noqa: T201 + print("\n--------------------\n".join(changes)) # ruff: ignore[print] return 1 return 0 diff --git a/src/compwa_policy/cli/env.py b/src/compwa_policy/cli/env.py index 5acb79b4..969ffe68 100644 --- a/src/compwa_policy/cli/env.py +++ b/src/compwa_policy/cli/env.py @@ -15,7 +15,7 @@ ) -def env( # noqa: PLR0917 +def env( # ruff: ignore[too-many-positional-arguments] python: Python = None, dev_python_version: DevPythonVersion = None, package_manager: PackageManager = None, diff --git a/src/compwa_policy/cli/github.py b/src/compwa_policy/cli/github.py index 3cd4a8a1..a6b8e380 100644 --- a/src/compwa_policy/cli/github.py +++ b/src/compwa_policy/cli/github.py @@ -29,7 +29,7 @@ ) -def github( # noqa: PLR0917 +def github( # ruff: ignore[too-many-positional-arguments] python: Python = None, dev_python_version: DevPythonVersion = None, allow_labels: AllowLabels = None, diff --git a/src/compwa_policy/cli/nb.py b/src/compwa_policy/cli/nb.py index f8bcdec9..8156715c 100644 --- a/src/compwa_policy/cli/nb.py +++ b/src/compwa_policy/cli/nb.py @@ -15,7 +15,7 @@ ) -def nb( # noqa: PLR0917 +def nb( # ruff: ignore[too-many-positional-arguments] package_manager: PackageManager = None, dev_python_version: DevPythonVersion = None, no_binder: NoBinder = None, diff --git a/src/compwa_policy/cli/python.py b/src/compwa_policy/cli/python.py index fa1b47f9..a1e8f547 100644 --- a/src/compwa_policy/cli/python.py +++ b/src/compwa_policy/cli/python.py @@ -17,7 +17,7 @@ ) -def python( # noqa: PLR0917 +def python( # ruff: ignore[too-many-positional-arguments] python: Python = None, dev_python_version: DevPythonVersion = None, excluded_python_versions: ExcludedPythonVersions = None, diff --git a/src/compwa_policy/env/pixi/_remove.py b/src/compwa_policy/env/pixi/_remove.py index d108e250..0f3a51ce 100644 --- a/src/compwa_policy/env/pixi/_remove.py +++ b/src/compwa_policy/env/pixi/_remove.py @@ -25,5 +25,5 @@ def remove_pixi_configuration(session: Session, /) -> None: if pyproject is None: return if pyproject.has_table("tool.pixi"): - del pyproject._document["tool"]["pixi"] # noqa: SLF001 + del pyproject._document["tool"]["pixi"] # ruff: ignore[private-member-access] pyproject.changelog.append("Removed Pixi configuration table") diff --git a/src/compwa_policy/env/pixi/_update.py b/src/compwa_policy/env/pixi/_update.py index e0d29969..a54e5980 100644 --- a/src/compwa_policy/env/pixi/_update.py +++ b/src/compwa_policy/env/pixi/_update.py @@ -113,10 +113,10 @@ def _rename_workspace_table(config: ModifiablePyproject) -> None: project = __get_table(config, "project") workspace = __get_table(config, "workspace", create=True) workspace.update(project) - if config._source == CONFIG_PATH.pyproject: # noqa: SLF001 - del config._document["tool"]["pixi"]["project"] # noqa: SLF001 + if config._source == CONFIG_PATH.pyproject: # ruff: ignore[private-member-access] + del config._document["tool"]["pixi"]["project"] # ruff: ignore[private-member-access] else: - del config._document["project"] # noqa: SLF001 # ty:ignore[invalid-argument-type] + del config._document["project"] # ruff: ignore[private-member-access] # ty:ignore[invalid-argument-type] msg = 'Renamed "project" table to "workspace" in Pixi configuration' config.changelog.append(msg) @@ -136,7 +136,7 @@ def _define_minimal_project( channels=["conda-forge"], platforms=["linux-64"], ) - if config._source == CONFIG_PATH.pixi_toml: # noqa: SLF001 + if config._source == CONFIG_PATH.pixi_toml: # ruff: ignore[private-member-access] pyproject = session.pyproject if pyproject is not None: minimal_settings["name"] = pyproject.get_package_name() @@ -375,12 +375,12 @@ def ___outsource_cmd(task: Table, other_task_name: str) -> bool: def __get_table( config: ModifiablePyproject, key: str, create: bool = False ) -> MutableMapping[str, Any]: - if config._source == CONFIG_PATH.pyproject: # noqa: SLF001 + if config._source == CONFIG_PATH.pyproject: # ruff: ignore[private-member-access] key = f"tool.pixi.{key}" return config.get_table(key, create=create) def __has_table(config: Pyproject, key: str) -> bool: - if config._source == CONFIG_PATH.pyproject: # noqa: SLF001 + if config._source == CONFIG_PATH.pyproject: # ruff: ignore[private-member-access] key = f"tool.pixi.{key}" return config.has_table(key) diff --git a/src/compwa_policy/env/uv.py b/src/compwa_policy/env/uv.py index 61000505..73906f1b 100644 --- a/src/compwa_policy/env/uv.py +++ b/src/compwa_policy/env/uv.py @@ -92,7 +92,7 @@ def _remove_pip_constraint_files() -> Changelog: def _remove_uv_configuration(pyproject: ModifiablePyproject | None) -> None: if pyproject is None: return - readonly_pyproject = pyproject._document # noqa: SLF001 + readonly_pyproject = pyproject._document # ruff: ignore[private-member-access] if "tool" not in readonly_pyproject or "uv" not in readonly_pyproject["tool"]: return tool_table = pyproject.get_table("tool") diff --git a/src/compwa_policy/errors.py b/src/compwa_policy/errors.py index 073cd727..76a77d6e 100644 --- a/src/compwa_policy/errors.py +++ b/src/compwa_policy/errors.py @@ -1,3 +1,3 @@ -# noqa: D100 +# ruff: ignore[undocumented-public-module] class PolicyError(RuntimeError): """Policy violation that is caught by the executor and printed without a traceback.""" diff --git a/src/compwa_policy/format/cspell.py b/src/compwa_policy/format/cspell.py index 4d38de39..d6bab4f6 100644 --- a/src/compwa_policy/format/cspell.py +++ b/src/compwa_policy/format/cspell.py @@ -215,7 +215,7 @@ def __express_list_of_sections(sections: Sequence[str]) -> str: else: sentence += "s " sentence += ", ".join(sections[:-1]) - if len(sections) > 2: # noqa: PLR2004 + if len(sections) > 2: # ruff: ignore[magic-value-comparison] sentence += "," sentence += " and " + sections[-1] return sentence diff --git a/src/compwa_policy/format/precommit.py b/src/compwa_policy/format/precommit.py index a3147250..2564b641 100644 --- a/src/compwa_policy/format/precommit.py +++ b/src/compwa_policy/format/precommit.py @@ -52,7 +52,7 @@ def _sort_hooks(precommit: ModifiablePrecommit) -> None: precommit.changelog.append(msg) -def __repo_sort_key(repo: Repo) -> tuple[int, str]: # noqa: PLR0911 +def __repo_sort_key(repo: Repo) -> tuple[int, str]: # ruff: ignore[too-many-return-statements] repo_url = repo["repo"] if repo_url == "meta": return 0, repo_url diff --git a/src/compwa_policy/github/dependabot.py b/src/compwa_policy/github/dependabot.py index b7a7b500..873a90e8 100644 --- a/src/compwa_policy/github/dependabot.py +++ b/src/compwa_policy/github/dependabot.py @@ -25,7 +25,7 @@ directories=(CONFIG_PATH.github_workflow_dir.parent,), patterns=("(.*/)?Manifest\\.toml",), ) -def check(session: Session, args: Arguments, _: CheckContext) -> None: # noqa: C901 +def check(session: Session, args: Arguments, _: CheckContext) -> None: # ruff: ignore[complex-structure] frequency = args.upgrade_frequency def dump_dependabot_config() -> Changelog: diff --git a/src/compwa_policy/github/workflows.py b/src/compwa_policy/github/workflows.py index 4c786e7b..24f5c41a 100644 --- a/src/compwa_policy/github/workflows.py +++ b/src/compwa_policy/github/workflows.py @@ -72,14 +72,14 @@ def check(session: Session, args: Arguments, ctx: CheckContext) -> None: _recommend_vscode_extension(session) -def _update_cd_workflow( # noqa: C901 +def _update_cd_workflow( # ruff: ignore[complex-structure] session: Session, /, no_milestones: bool, no_pypi: bool, no_version_branches: bool, ) -> None: - def update() -> Changelog: # noqa: C901 + def update() -> Changelog: # ruff: ignore[complex-structure] yaml = create_prettier_round_trip_yaml() workflow_path = CONFIG_PATH.github_workflow_dir / "cd.yml" expected_data = yaml.load(COMPWA_POLICY_DIR / workflow_path) @@ -126,7 +126,7 @@ def _update_pr_linting() -> Changelog: return [] -def _update_ci_workflow( # noqa: PLR0917 +def _update_ci_workflow( # ruff: ignore[too-many-positional-arguments] session: Session, /, allow_deprecated: bool, @@ -174,7 +174,7 @@ def update() -> Changelog: session.changelog += remove_workflow("clean-cache.yml") -def _get_ci_workflow( # noqa: PLR0917 +def _get_ci_workflow( # ruff: ignore[too-many-positional-arguments] path: Path, precommit: Precommit, doc_apt_packages: list[str], diff --git a/src/compwa_policy/python/mypy.py b/src/compwa_policy/python/mypy.py index 5b88a213..edf5f079 100644 --- a/src/compwa_policy/python/mypy.py +++ b/src/compwa_policy/python/mypy.py @@ -75,7 +75,7 @@ def _remove_mypy(session: Session, /) -> None: if pyproject is None: return if pyproject.has_table("tool.mypy"): - del pyproject._document["tool"]["mypy"] # noqa: SLF001 + del pyproject._document["tool"]["mypy"] # ruff: ignore[private-member-access] pyproject.changelog.append("Removed mypy configuration table") pyproject.remove_dependency("mypy") precommit.remove_hook("mypy") diff --git a/src/compwa_policy/python/pyright.py b/src/compwa_policy/python/pyright.py index 2dc8fb96..15bc656d 100644 --- a/src/compwa_policy/python/pyright.py +++ b/src/compwa_policy/python/pyright.py @@ -143,7 +143,7 @@ def _remove_pyright(session: Session, /) -> None: msg = f"Removed old pyright configuration file {pyright_config}" pyproject.changelog.append(msg) if pyproject.has_table("tool.pyright"): - del pyproject._document["tool"]["pyright"] # noqa: SLF001 + del pyproject._document["tool"]["pyright"] # ruff: ignore[private-member-access] msg = "Removed pyright configuration from pyproject.toml" pyproject.changelog.append(msg) pyproject.remove_dependency("pyright") diff --git a/src/compwa_policy/python/ruff.py b/src/compwa_policy/python/ruff.py index 51452d49..4252b684 100644 --- a/src/compwa_policy/python/ruff.py +++ b/src/compwa_policy/python/ruff.py @@ -141,7 +141,7 @@ def __remove_nbqa_option(pyproject: ModifiablePyproject, option: str) -> None: def __remove_tool_table(pyproject: ModifiablePyproject, tool_table: str) -> None: - tools = pyproject._document.get("tool") # noqa: SLF001 + tools = pyproject._document.get("tool") # ruff: ignore[private-member-access] if isinstance(tools, dict) and tool_table in tools: tools.pop(tool_table) msg = f"Removed [tool.{tool_table}] table" diff --git a/src/compwa_policy/python/ty.py b/src/compwa_policy/python/ty.py index 51ebd656..875c13a9 100644 --- a/src/compwa_policy/python/ty.py +++ b/src/compwa_policy/python/ty.py @@ -132,7 +132,7 @@ def _remove_ty(session: Session, /) -> None: config_path.unlink() pyproject.changelog.append(f"Removed {config_path}") if pyproject.has_table("tool.ty"): - del pyproject._document["tool"]["ty"] # noqa: SLF001 + del pyproject._document["tool"]["ty"] # ruff: ignore[private-member-access] pyproject.changelog.append("Removed ty configuration table") pyproject.remove_dependency("ty") precommit.remove_hook("ty") diff --git a/src/compwa_policy/repo/poe.py b/src/compwa_policy/repo/poe.py index d73700e0..28df5ad1 100644 --- a/src/compwa_policy/repo/poe.py +++ b/src/compwa_policy/repo/poe.py @@ -65,7 +65,7 @@ def check(session: Session, args: Arguments, ctx: CheckContext) -> None: if config is None: return if config.has_table("tool.tox"): - del config._document["tool"]["tox"] # noqa: SLF001 + del config._document["tool"]["tox"] # ruff: ignore[private-member-access] msg = f"Removed deprecated tool.tox section from {CONFIG_PATH.pyproject}" config.changelog.append(msg) if config.has_table("tool.poe"): diff --git a/src/compwa_policy/self_check.py b/src/compwa_policy/self_check.py index aab523b3..f0816f59 100644 --- a/src/compwa_policy/self_check.py +++ b/src/compwa_policy/self_check.py @@ -43,7 +43,7 @@ def main(precommit: Precommit | None = None) -> int: if any(hooks_updated): _write_precommit_config(config) if errors: - print("\n--------------------\n".join(error.strip() for error in errors)) # noqa: T201 + print("\n--------------------\n".join(error.strip() for error in errors)) # ruff: ignore[print] return 1 _update_policy_schema() return 0 diff --git a/src/compwa_policy/utilities/__init__.py b/src/compwa_policy/utilities/__init__.py index 609e683b..9894464c 100644 --- a/src/compwa_policy/utilities/__init__.py +++ b/src/compwa_policy/utilities/__init__.py @@ -59,7 +59,7 @@ def append_safe(session: Session, /, expected_line: str, path: Path) -> bool: return True -def contains_line(input: Path | io.TextIOBase | str, expected_line: str) -> bool: # noqa: A002 +def contains_line(input: Path | io.TextIOBase | str, expected_line: str) -> bool: # ruff: ignore[builtin-argument-shadowing] if isinstance(input, io.TextIOBase): lines = input.readlines() else: @@ -82,7 +82,7 @@ def hash_file(path: Path | str) -> str: def read( - input: Path | io.TextIOBase | str, # noqa: A002 + input: Path | io.TextIOBase | str, # ruff: ignore[builtin-argument-shadowing] *, session: Session | None = None, ) -> str: diff --git a/src/compwa_policy/utilities/cfg.py b/src/compwa_policy/utilities/cfg.py index 04c5e5c3..f716e843 100644 --- a/src/compwa_policy/utilities/cfg.py +++ b/src/compwa_policy/utilities/cfg.py @@ -16,7 +16,7 @@ def format_config( - input: Path | io.TextIOBase | str, # noqa: A002 + input: Path | io.TextIOBase | str, # ruff: ignore[builtin-argument-shadowing] output: Path | io.TextIOBase | str, additional_rules: Iterable[Callable[[str], str]] | None = None, ) -> None: diff --git a/src/compwa_policy/utilities/match.py b/src/compwa_policy/utilities/match.py index fb49414e..bcc3668c 100644 --- a/src/compwa_policy/utilities/match.py +++ b/src/compwa_policy/utilities/match.py @@ -2,7 +2,7 @@ from __future__ import annotations -import subprocess # noqa: S404 +import subprocess # ruff: ignore[suspicious-subprocess-import] from functools import cache from typing import TYPE_CHECKING @@ -41,7 +41,7 @@ def _git_ls_files_cmd(*glob: str, untracked: bool = False) -> str: cmd = ["git", "ls-files", *glob] if untracked: cmd.extend(["--cached", "--exclude-standard", "--others"]) - return subprocess.check_output(cmd).decode("utf-8") # noqa: S603 + return subprocess.check_output(cmd).decode("utf-8") # ruff: ignore[subprocess-without-shell-equals-true] def matches_files(pattern: str, files: list[str]) -> bool: diff --git a/src/compwa_policy/utilities/precommit/getters.py b/src/compwa_policy/utilities/precommit/getters.py index 36ea1de3..e712aa74 100644 --- a/src/compwa_policy/utilities/precommit/getters.py +++ b/src/compwa_policy/utilities/precommit/getters.py @@ -1,9 +1,9 @@ -# noqa: D100 +# ruff: ignore[undocumented-public-module] from __future__ import annotations import operator import re -import subprocess # noqa: S404 +import subprocess # ruff: ignore[suspicious-subprocess-import] from typing import TYPE_CHECKING from packaging.version import InvalidVersion, Version @@ -67,8 +67,8 @@ def get_latest_rev(repo_url: str, fallback: str = "PLEASE-UPDATE") -> str: def _git_ls_remote_tags(repo_url: str) -> str: try: - return subprocess.check_output( # noqa: S603 - ["git", "ls-remote", "--tags", "--refs", repo_url], # noqa: S607 + return subprocess.check_output( # ruff: ignore[subprocess-without-shell-equals-true] + ["git", "ls-remote", "--tags", "--refs", repo_url], # ruff: ignore[start-process-with-partial-path] stderr=subprocess.DEVNULL, text=True, timeout=10, diff --git a/src/compwa_policy/utilities/precommit/setters.py b/src/compwa_policy/utilities/precommit/setters.py index e698762d..19dcd603 100644 --- a/src/compwa_policy/utilities/precommit/setters.py +++ b/src/compwa_policy/utilities/precommit/setters.py @@ -1,4 +1,4 @@ -# noqa: D100 +# ruff: ignore[undocumented-public-module] from __future__ import annotations from typing import TYPE_CHECKING, cast diff --git a/src/compwa_policy/utilities/precommit/struct.py b/src/compwa_policy/utilities/precommit/struct.py index cf04bcc7..f7ba137b 100644 --- a/src/compwa_policy/utilities/precommit/struct.py +++ b/src/compwa_policy/utilities/precommit/struct.py @@ -1,4 +1,4 @@ -# noqa: D100 +# ruff: ignore[undocumented-public-module] from __future__ import annotations import sys diff --git a/src/compwa_policy/utilities/pyproject/__init__.py b/src/compwa_policy/utilities/pyproject/__init__.py index cdc692d4..9fe107bb 100644 --- a/src/compwa_policy/utilities/pyproject/__init__.py +++ b/src/compwa_policy/utilities/pyproject/__init__.py @@ -323,7 +323,7 @@ def has_pyproject_package_name(session: Session, /) -> bool: def has_dependency(pyproject: Pyproject, package: str | tuple[str, ...]) -> bool: - toml_document: PyprojectTOML = pyproject._document # noqa: SLF001 + toml_document: PyprojectTOML = pyproject._document # ruff: ignore[private-member-access] dependencies = set(toml_document.get("project", {}).get("dependencies", [])) for group in toml_document.get("dependency-groups", {}).values(): dependencies |= {x for x in group if isinstance(x, str)} diff --git a/src/compwa_policy/utilities/pyproject/setters.py b/src/compwa_policy/utilities/pyproject/setters.py index 89829931..ab8376eb 100644 --- a/src/compwa_policy/utilities/pyproject/setters.py +++ b/src/compwa_policy/utilities/pyproject/setters.py @@ -130,7 +130,7 @@ def get_sub_table( return cast("MutableMapping[str, Any]", table) -def remove_dependency( # noqa: C901, PLR0912 +def remove_dependency( # ruff: ignore[complex-structure, too-many-branches] pyproject: PyprojectTOML, package: str, ignored_sections: Iterable[str] | None = None, diff --git a/src/compwa_policy/utilities/python.py b/src/compwa_policy/utilities/python.py index 6f5167f4..bacd19e4 100644 --- a/src/compwa_policy/utilities/python.py +++ b/src/compwa_policy/utilities/python.py @@ -1,4 +1,4 @@ -# noqa: D100 +# ruff: ignore[undocumented-public-module] from __future__ import annotations from pathlib import Path diff --git a/src/compwa_policy/utilities/readme.py b/src/compwa_policy/utilities/readme.py index 0b896ce1..b7c4e16d 100644 --- a/src/compwa_policy/utilities/readme.py +++ b/src/compwa_policy/utilities/readme.py @@ -56,7 +56,7 @@ def add_badge(self, badge: str) -> None: error_message += f"{self._source} contains no title, so cannot add badge" raise PolicyError(error_message) insert_position = 0 - for insert_position, line in enumerate(self._lines): # noqa: B007 + for insert_position, line in enumerate(self._lines): # ruff: ignore[unused-loop-control-variable] if line.startswith("#"): break self._lines.insert(insert_position + 1, f"\n{badge}") diff --git a/src/compwa_policy/utilities/session.py b/src/compwa_policy/utilities/session.py index 8b388071..801205d0 100644 --- a/src/compwa_policy/utilities/session.py +++ b/src/compwa_policy/utilities/session.py @@ -81,7 +81,7 @@ def get(self, resource: type[R], /) -> R: loaded = resource.load() self._loaded[key] = loaded if self._is_in_context and key not in self._entered: - loaded.__enter__() # noqa: PLC2801 + loaded.__enter__() # ruff: ignore[unnecessary-dunder-call] self._entered.add(key) return cast("R", loaded) @@ -94,7 +94,7 @@ def get_path(self, path: Path | str, /) -> ModifiablePath: loaded = ModifiablePath.load_path(normalized) self._loaded[key] = loaded if self._is_in_context and key not in self._entered: - loaded.__enter__() # noqa: PLC2801 + loaded.__enter__() # ruff: ignore[unnecessary-dunder-call] self._entered.add(key) return cast("ModifiablePath", loaded) diff --git a/src/compwa_policy/utilities/vscode.py b/src/compwa_policy/utilities/vscode.py index 0f0c319a..d27f5525 100644 --- a/src/compwa_policy/utilities/vscode.py +++ b/src/compwa_policy/utilities/vscode.py @@ -226,7 +226,7 @@ def _determine_new_value(old: V, new: V, sort: bool = False) -> V: if isinstance(old, dict) and isinstance(new, dict): return _update_dict_recursively(old, new, sort) # ty:ignore[invalid-return-type] if isinstance(old, list) and isinstance(new, list): - return sorted({*old, *new}) # ty:ignore[invalid-return-type] + return sorted({*old, *new}) # ty:ignore[invalid-argument-type] return new diff --git a/src/compwa_policy/utilities/yaml.py b/src/compwa_policy/utilities/yaml.py index 0f609a93..623aab63 100644 --- a/src/compwa_policy/utilities/yaml.py +++ b/src/compwa_policy/utilities/yaml.py @@ -15,7 +15,7 @@ class _IncreasedYamlIndent(yaml.Dumper): - def increase_indent(self, flow: bool = False, indentless: bool = False) -> None: # noqa: ARG002 + def increase_indent(self, flow: bool = False, indentless: bool = False) -> None: # ruff: ignore[unused-method-argument] return super().increase_indent(flow, indentless=False) def write_line_break(self, data: str | None = None) -> None: diff --git a/tests/conftest.py b/tests/conftest.py index 8458b511..6a7d7a3a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,5 @@ import os -import subprocess # noqa: S404 +import subprocess # ruff: ignore[suspicious-subprocess-import] from collections.abc import Callable from pathlib import Path from typing import Any @@ -50,7 +50,7 @@ def test_dir() -> Path: @pytest.fixture def git_init() -> GitCommand: def run(directory: Path) -> None: - subprocess.run(["git", "init", "-q"], cwd=directory, check=True) # noqa: S607 + subprocess.run(["git", "init", "-q"], cwd=directory, check=True) # ruff: ignore[start-process-with-partial-path] return run @@ -58,7 +58,7 @@ def run(directory: Path) -> None: @pytest.fixture def git_add() -> GitCommand: def run(directory: Path) -> None: - subprocess.run(["git", "add", "-A"], cwd=directory, check=True) # noqa: S607 + subprocess.run(["git", "add", "-A"], cwd=directory, check=True) # ruff: ignore[start-process-with-partial-path] return run @@ -71,7 +71,7 @@ def run(directory: Path) -> None: git_init(directory) git_add(directory) subprocess.run( - ["git", "commit", "-qm", "init", "--allow-empty"], # noqa: S607 + ["git", "commit", "-qm", "init", "--allow-empty"], # ruff: ignore[start-process-with-partial-path] cwd=directory, check=True, ) From 69a783a966d41f04c5e98f368866d593cd3afbcc Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Sun, 26 Jul 2026 14:51:57 +0200 Subject: [PATCH 3/5] BEHAVIOR: adapt to Ruff v0.16 --- pyproject.toml | 110 ++++++++++++++++--------------- src/compwa_policy/python/ruff.py | 94 +++++++++++++------------- tests/python/test_ruff.py | 4 ++ 3 files changed, 107 insertions(+), 101 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8ba6c66e..5dcb2310 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -327,36 +327,36 @@ line-ending = "lf" [tool.ruff.lint] ignore = [ - "ANN401", - "C408", - "COM812", - "CPY001", - "D101", - "D102", - "D103", - "D105", - "D107", - "D203", - "D213", - "D407", - "D416", "DOC", - "E501", "FBT", - "FURB101", - "FURB103", - "FURB140", - "G004", - "ISC001", - "PLR0913", - "PLW1514", - "PLW2901", - "PT001", "PTH", - "RUF067", - "S301", - "SIM108", - "UP036", + "any-type", + "if-else-block-instead-of-if-exp", + "incorrect-blank-line-before-class", + "line-too-long", + "logging-f-string", + "missing-copyright-notice", + "missing-dashed-underline-after-section", + "missing-section-name-colon", + "missing-trailing-comma", + "multi-line-summary-second-line", + "non-empty-init-module", + "outdated-version-block", + "pytest-fixture-incorrect-parentheses-style", + "read-whole-file", + "redefined-loop-name", + "reimplemented-starmap", + "single-line-implicit-string-concatenation", + "suspicious-pickle-usage", + "too-many-arguments", + "undocumented-magic-method", + "undocumented-public-class", + "undocumented-public-function", + "undocumented-public-init", + "undocumented-public-method", + "unnecessary-collection-call", + "unspecified-encoding", + "write-whole-file", ] select = ["ALL"] task-tags = ["cspell"] @@ -371,41 +371,43 @@ split-on-trailing-comma = false "benchmarks/*" = [ "ANN", "D", - "INP001", - "PLC2701", - "PLR2004", - "PLR6301", - "RUF069", - "S101", - "S404", - "S603", - "S607", - "SLF001", "T20", + "assert", + "boolean-type-hint-positional-argument", + "float-equality-comparison", + "implicit-namespace-package", + "import-private-name", + "magic-value-comparison", + "no-self-use", + "private-member-access", + "start-process-with-partial-path", + "subprocess-without-shell-equals-true", + "suspicious-subprocess-import", ] "docs/*" = [ - "E402", - "INP001", - "S101", - "S113", - "T201", + "assert", + "implicit-namespace-package", + "module-import-not-at-top-of-file", + "print", + "request-without-timeout", ] -"docs/conf.py" = ["D100"] -"setup.py" = ["D100"] -"src/compwa_policy/config.py" = ["D100"] +"docs/conf.py" = ["undocumented-public-module"] +"setup.py" = ["undocumented-public-module"] +"src/compwa_policy/config.py" = ["undocumented-public-module"] "tests/*" = [ "ANN", - "C901", "D", - "INP001", - "PLC2701", - "PLR0915", - "PLR2004", - "PLR6301", - "RUF069", - "S101", - "SLF001", "T20", + "assert", + "boolean-type-hint-positional-argument", + "complex-structure", + "float-equality-comparison", + "implicit-namespace-package", + "import-private-name", + "magic-value-comparison", + "no-self-use", + "private-member-access", + "too-many-statements", ] [tool.ruff.lint.pydocstyle] diff --git a/src/compwa_policy/python/ruff.py b/src/compwa_policy/python/ruff.py index 4252b684..a3e92c08 100644 --- a/src/compwa_policy/python/ruff.py +++ b/src/compwa_policy/python/ruff.py @@ -306,33 +306,33 @@ def __update_ruff_format_settings(pyproject: ModifiablePyproject) -> None: def __update_ruff_lint_settings(pyproject: ModifiablePyproject) -> None: settings = pyproject.get_table("tool.ruff.lint", create=True) ignored_rules = { - "ANN401", # allow typing.Any - "COM812", # missing trailing comma - "CPY001", # don't add copyright - "D101", # class docstring - "D102", # method docstring - "D103", # function docstring - "D105", # magic method docstring - "D107", # init docstring - "D203", # conflicts with D211 - "D213", # multi-line docstring should start at the second line - "D407", # missing dashed underline after section - "D416", # section name does not have to end with a colon + "any-type", + "missing-trailing-comma", + "missing-copyright-notice", + "undocumented-public-class", + "undocumented-public-method", + "undocumented-public-function", + "undocumented-magic-method", + "undocumented-public-init", + "incorrect-blank-line-before-class", # conflicts with D211 + "multi-line-summary-second-line", + "missing-dashed-underline-after-section", + "missing-section-name-colon", "DOC", # do not check undocumented exceptions - "E501", # line-width already handled by black - "FURB101", # do not enforce Path.read_text() - "FURB103", # do not enforce Path.write_text() - "FURB140", # do not enforce itertools.starmap - "G004", # allow f-string in logging - "ISC001", # conflicts with ruff formatter - "PLW1514", # allow missing encoding in open() - "PT001", # allow pytest.fixture without parentheses + "line-too-long", # line-width already handled by Ruff formatter + "read-whole-file", + "write-whole-file", + "reimplemented-starmap", + "logging-f-string", + "single-line-implicit-string-concatenation", # conflicts with formatter + "unspecified-encoding", + "pytest-fixture-incorrect-parentheses-style", "PTH", # do not enforce Path - "RUF067", # `__init__` module should only contain docstrings and re-exports - "SIM108", # allow if-else blocks + "non-empty-init-module", + "if-else-block-instead-of-if-exp", } if "3.6" in pyproject.get_supported_python_versions(): - ignored_rules.add("UP036") + ignored_rules.add("outdated-version-block") ignored_rules = ___merge_rules(settings.get("ignore", []), ignored_rules) minimal_settings = { "select": to_toml_array(["ALL"]), @@ -368,25 +368,25 @@ def __update_per_file_ignores( key=key, expected_ignores={ "ANN", # global-statement - "B018", # useless-expression + "useless-expression", "C90", # complex-structure "D", # pydocstyle - "E303", # too many blank lines, specific for jupyterlab-lsp - "E703", # useless-semicolon - "N806", # non-lowercase-variable-in-function - "N816", # mixed-case-variable-in-global-scope + "too-many-blank-lines", # specific for jupyterlab-lsp + "useless-semicolon", + "non-lowercase-variable-in-function", + "mixed-case-variable-in-global-scope", "PLR09", # complicated logic - "PLR2004", # magic-value-comparison - "PLW0602", # global-variable-not-assigned - "PLW0603", # global-statement - "S101", # `assert` detected + "magic-value-comparison", + "global-variable-not-assigned", + "global-statement", + "assert", "T20", # print found "TC00", # type-checking block *___get_existing_nbqa_ignores(pyproject), }, banned_ignores={ - "F821", # identify variables that are not defined - "ISC003", # explicit-string-concatenation + "undefined-name", + "explicit-string-concatenation", "TCH00", # https://astral.sh/blog/ruff-v0.8.0#new-error-codes-for-flake8-type-checking-rules }, ) @@ -397,9 +397,9 @@ def __update_per_file_ignores( pyproject, key=key, expected_ignores={ - "INP001", # implicit namespace package - "S101", # `assert` detected - "S113", # requests call without timeout + "implicit-namespace-package", + "assert", + "request-without-timeout", }, ) conf_path = f"{docs_dir}/conf.py" @@ -409,11 +409,11 @@ def __update_per_file_ignores( pyproject, key=key, expected_ignores={ - "D100", # no module docstring + "undocumented-public-module", }, ) if os.path.exists("setup.py"): - minimal_settings["setup.py"] = to_toml_array(["D100"]) + minimal_settings["setup.py"] = to_toml_array(["undocumented-public-module"]) for tests_dir in ["benchmarks", "tests"]: if not os.path.exists(tests_dir): continue @@ -426,14 +426,14 @@ def __update_per_file_ignores( expected_ignores={ "ANN", # don't check missing types "D", # no need for pydocstyle - "FBT001", # don't force booleans as keyword arguments - "INP001", # allow implicit-namespace-package - "RUF069", # float-equality-comparison - "PLC2701", # private module imports - "PLR2004", # magic-value-comparison - "PLR6301", # allow non-static method - "S101", # allow assert - "SLF001", # allow access to private members + "boolean-type-hint-positional-argument", + "implicit-namespace-package", + "float-equality-comparison", + "import-private-name", + "magic-value-comparison", + "no-self-use", + "assert", + "private-member-access", "T20", # allow print and pprint }, ) diff --git a/tests/python/test_ruff.py b/tests/python/test_ruff.py index bb602f3a..2c7591b0 100644 --- a/tests/python/test_ruff.py +++ b/tests/python/test_ruff.py @@ -79,6 +79,10 @@ def migrates_config_with_notebooks(ruff_repo: Path, run_check): assert "[tool.black]" not in pyproject # black settings removed assert "[tool.ruff.lint]" in pyproject # linting config migrated assert 'select = ["ALL"]' in pyproject + assert '"any-type"' in pyproject + assert '"ANN401"' not in pyproject + assert '"undocumented-public-module"' in pyproject + assert '"D100"' not in pyproject assert '"*.ipynb"' in pyproject # per-file-ignores for notebooks assert 'ignorelist = ["display"]' in pyproject assert "builtins-ignorelist" not in pyproject From 3c176169ea6c29df49135ded624c6b5937cb49c5 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Sun, 26 Jul 2026 15:06:49 +0200 Subject: [PATCH 4/5] MAINT: minor formatting improvements --- docs/conf.py | 2 +- pyproject.toml | 5 ++- src/compwa_policy/python/ruff.py | 58 ++++++++++++++++---------------- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 0b8ceaba..30751e70 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -50,7 +50,7 @@ codeautolink_concat_default = True copybutton_prompt_is_regexp = True copybutton_prompt_text = r">>> |\.\.\. " # doctest -copyright = "2023, Common Partial Wave Analysis" # ruff: ignore[builtin-variable-shadowing] +copyright = "2023, Common Partial Wave Analysis" default_role = "py:obj" extensions = [ "_ext.policy_settings", diff --git a/pyproject.toml b/pyproject.toml index 5dcb2310..b6f3b171 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -391,7 +391,10 @@ split-on-trailing-comma = false "print", "request-without-timeout", ] -"docs/conf.py" = ["undocumented-public-module"] +"docs/conf.py" = [ + "builtin-variable-shadowing", + "undocumented-public-module", +] "setup.py" = ["undocumented-public-module"] "src/compwa_policy/config.py" = ["undocumented-public-module"] "tests/*" = [ diff --git a/src/compwa_policy/python/ruff.py b/src/compwa_policy/python/ruff.py index a3e92c08..dd423c24 100644 --- a/src/compwa_policy/python/ruff.py +++ b/src/compwa_policy/python/ruff.py @@ -307,29 +307,29 @@ def __update_ruff_lint_settings(pyproject: ModifiablePyproject) -> None: settings = pyproject.get_table("tool.ruff.lint", create=True) ignored_rules = { "any-type", - "missing-trailing-comma", - "missing-copyright-notice", - "undocumented-public-class", - "undocumented-public-method", - "undocumented-public-function", - "undocumented-magic-method", - "undocumented-public-init", + "DOC", # do not check undocumented exceptions + "if-else-block-instead-of-if-exp", "incorrect-blank-line-before-class", # conflicts with D211 - "multi-line-summary-second-line", + "line-too-long", # line-width already handled by Ruff formatter + "logging-f-string", + "missing-copyright-notice", "missing-dashed-underline-after-section", "missing-section-name-colon", - "DOC", # do not check undocumented exceptions - "line-too-long", # line-width already handled by Ruff formatter + "missing-trailing-comma", + "multi-line-summary-second-line", + "non-empty-init-module", + "PTH", # do not enforce Path + "pytest-fixture-incorrect-parentheses-style", "read-whole-file", - "write-whole-file", "reimplemented-starmap", - "logging-f-string", "single-line-implicit-string-concatenation", # conflicts with formatter + "undocumented-magic-method", + "undocumented-public-class", + "undocumented-public-function", + "undocumented-public-init", + "undocumented-public-method", "unspecified-encoding", - "pytest-fixture-incorrect-parentheses-style", - "PTH", # do not enforce Path - "non-empty-init-module", - "if-else-block-instead-of-if-exp", + "write-whole-file", } if "3.6" in pyproject.get_supported_python_versions(): ignored_rules.add("outdated-version-block") @@ -368,26 +368,26 @@ def __update_per_file_ignores( key=key, expected_ignores={ "ANN", # global-statement - "useless-expression", + "assert", "C90", # complex-structure "D", # pydocstyle - "too-many-blank-lines", # specific for jupyterlab-lsp - "useless-semicolon", - "non-lowercase-variable-in-function", + "global-statement", + "global-variable-not-assigned", + "magic-value-comparison", "mixed-case-variable-in-global-scope", + "non-lowercase-variable-in-function", "PLR09", # complicated logic - "magic-value-comparison", - "global-variable-not-assigned", - "global-statement", - "assert", "T20", # print found "TC00", # type-checking block + "too-many-blank-lines", # specific for jupyterlab-lsp + "useless-expression", + "useless-semicolon", *___get_existing_nbqa_ignores(pyproject), }, banned_ignores={ - "undefined-name", "explicit-string-concatenation", "TCH00", # https://astral.sh/blog/ruff-v0.8.0#new-error-codes-for-flake8-type-checking-rules + "undefined-name", }, ) docs_dir = "docs" @@ -397,8 +397,8 @@ def __update_per_file_ignores( pyproject, key=key, expected_ignores={ - "implicit-namespace-package", "assert", + "implicit-namespace-package", "request-without-timeout", }, ) @@ -425,14 +425,14 @@ def __update_per_file_ignores( key=key, expected_ignores={ "ANN", # don't check missing types - "D", # no need for pydocstyle + "assert", "boolean-type-hint-positional-argument", - "implicit-namespace-package", + "D", # no need for pydocstyle "float-equality-comparison", + "implicit-namespace-package", "import-private-name", "magic-value-comparison", "no-self-use", - "assert", "private-member-access", "T20", # allow print and pprint }, From 60e34d99fbfe567aedaf01c1b8edf92adbd33a61 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Sun, 26 Jul 2026 15:08:44 +0200 Subject: [PATCH 5/5] BEHAVIOR: disable `builtin-variable-shadowing` in `conf.py` by default --- src/compwa_policy/python/ruff.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compwa_policy/python/ruff.py b/src/compwa_policy/python/ruff.py index dd423c24..442f855f 100644 --- a/src/compwa_policy/python/ruff.py +++ b/src/compwa_policy/python/ruff.py @@ -409,6 +409,7 @@ def __update_per_file_ignores( pyproject, key=key, expected_ignores={ + "builtin-variable-shadowing", "undocumented-public-module", }, )