Coverage for src/renaissance/utils/ruff_utils.py: 100%
12 statements
« prev ^ index » next coverage.py v7.17.0, created at 2026-11-16 16:04 +0000
« prev ^ index » next coverage.py v7.17.0, created at 2026-11-16 16:04 +0000
1# Copyright (C) 2024-2026 TNO
2#
3# Licensed under the terms specified in the LICENSE file in the root directory
4# of this repository, also available at:
5# https://github.com/TNO/Renaissance.Py/blob/main/LICENSE
7"""Ruff fixes and formatting for the files a recipe changed."""
9import subprocess
10import sys
11from collections.abc import Sequence
12from pathlib import Path
15def run_ruff_import_cleanup(paths: Sequence[Path]) -> None:
16 """Remove unused imports and sort the imports of each file in place.
18 Runs `ruff check --fix --select F401,I001` with the ruff settings that apply to each path. Does nothing when
19 paths is empty.
20 """
21 if not paths:
22 return
23 subprocess.run( # noqa: S603 (fixed arguments plus the caller's paths, no shell)
24 [sys.executable, "-m", "ruff", "check", "--fix", "--select", "F401,I001", *(str(path) for path in paths)],
25 capture_output=True,
26 check=False,
27 )
30def run_ruff_format(paths: Sequence[Path]) -> None:
31 """Format each whole file in place.
33 Runs `ruff format` with the ruff settings that apply to each path. Does nothing when paths is empty.
34 """
35 if not paths:
36 return
37 subprocess.run( # noqa: S603 (fixed arguments plus the caller's paths, no shell)
38 [sys.executable, "-m", "ruff", "format", *(str(path) for path in paths)],
39 capture_output=True,
40 check=False,
41 )