From c0232c6b5fb85de11fcf06b75c30c9c7ad369978 Mon Sep 17 00:00:00 2001 From: Dunedan Date: Sat, 21 Sep 2024 20:54:24 +0200 Subject: [PATCH] Specify the Python target version in ruff.toml This ensures the same Python target version used for `ruff format` is used for `ruff check` as well. It also allows ruff, even if it's not run through pre-commit, to use the correct target Python version. --- .pre-commit-config.yaml | 2 -- ruff.toml | 2 ++ source/tools/entity/checkrefs.py | 9 ++++----- source/tools/entity/entvalidate.py | 5 ++--- source/tools/i18n/check_diff.py | 5 ++--- source/tools/i18n/i18n_helper/globber.py | 3 +-- source/tools/i18n/tests/test_check_diff.py | 2 +- source/tools/rlclient/python/samples/simple_example.py | 4 ++-- source/tools/rlclient/python/tests/test_actions.py | 4 ++-- source/tools/rlclient/python/zero_ad/api.py | 2 +- source/tools/rlclient/python/zero_ad/environment.py | 2 +- 11 files changed, 18 insertions(+), 22 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 40bf599453..f3c053aacb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,8 +30,6 @@ repos: - id: ruff-format args: - --check - - --target-version - - py311 exclude: ^source/tools/webservices/ - repo: local hooks: diff --git a/ruff.toml b/ruff.toml index 610e22be18..17e243bec0 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,5 +1,7 @@ line-length = 99 +target-version = "py311" + [format] line-ending = "lf" diff --git a/source/tools/entity/checkrefs.py b/source/tools/entity/checkrefs.py index dd8af265a0..90c6382b3c 100755 --- a/source/tools/entity/checkrefs.py +++ b/source/tools/entity/checkrefs.py @@ -8,7 +8,6 @@ from json import load, loads from logging import INFO, WARNING, Filter, Formatter, StreamHandler, getLogger from pathlib import Path from struct import calcsize, unpack -from typing import Dict, List, Set, Tuple from xml.etree import ElementTree as ET from scriptlib import SimulTemplateEntity, find_files @@ -27,9 +26,9 @@ class SingleLevelFilter(Filter): class CheckRefs: def __init__(self): - self.files: List[Path] = [] - self.roots: List[Path] = [] - self.deps: List[Tuple[Path, Path]] = [] + self.files: list[Path] = [] + self.roots: list[Path] = [] + self.deps: list[tuple[Path, Path]] = [] self.vfs_root = Path(__file__).resolve().parents[3] / "binaries" / "data" / "mods" self.supportedTextureFormats = ("dds", "png") self.supportedMeshesFormats = ("pmd", "dae") @@ -794,7 +793,7 @@ class CheckRefs: uniq_files = {r.as_posix() for r in self.files} lower_case_files = {f.lower(): f for f in uniq_files} - missing_files: Dict[str, Set[str]] = defaultdict(set) + missing_files: dict[str, set[str]] = defaultdict(set) for parent, dep in self.deps: dep_str = dep.as_posix() diff --git a/source/tools/entity/entvalidate.py b/source/tools/entity/entvalidate.py index 51bbd547e2..574ee75dc6 100755 --- a/source/tools/entity/entvalidate.py +++ b/source/tools/entity/entvalidate.py @@ -7,7 +7,6 @@ import shutil import sys from pathlib import Path from subprocess import CalledProcessError, run -from typing import Sequence from xml.etree import ElementTree as ET from scriptlib import SimulTemplateEntity, find_files @@ -50,7 +49,7 @@ errorch.setFormatter(logging.Formatter("%(levelname)s - %(message)s")) logger.addHandler(errorch) -def main(argv: Sequence[str] | None = None) -> int: +def main() -> int: parser = argparse.ArgumentParser(description="Validate templates") parser.add_argument("-m", "--mod-name", required=True, help="The name of the mod to validate.") parser.add_argument( @@ -73,7 +72,7 @@ def main(argv: Sequence[str] | None = None) -> int: ) parser.add_argument("-v", "--verbose", help="Be verbose about the output.", default=False) - args = parser.parse_args(argv) + args = parser.parse_args() if not args.relaxng_schema.exists(): logging.error(RELAXNG_SCHEMA_ERROR_MSG.format(args.relaxng_schema)) diff --git a/source/tools/i18n/check_diff.py b/source/tools/i18n/check_diff.py index bd23f73346..db85ba3d3d 100755 --- a/source/tools/i18n/check_diff.py +++ b/source/tools/i18n/check_diff.py @@ -22,7 +22,6 @@ import io import os import subprocess from itertools import islice -from typing import List from i18n_helper import PROJECT_ROOT_DIRECTORY @@ -38,7 +37,7 @@ def get_diff(): return io.StringIO(diff_process.stdout.decode("utf-8")) -def check_diff(diff: io.StringIO) -> List[str]: +def check_diff(diff: io.StringIO) -> list[str]: """Check a diff of .po files for meaningful changes. Run through a diff of .po files and check that some of the changes @@ -87,7 +86,7 @@ def check_diff(diff: io.StringIO) -> List[str]: return list(files.difference(keep)) -def revert_files(files: List[str], verbose=False): +def revert_files(files: list[str], verbose=False): def batched(iterable, n): """Split an iterable in equally sized chunks. diff --git a/source/tools/i18n/i18n_helper/globber.py b/source/tools/i18n/i18n_helper/globber.py index 7055fa5efb..d19f896f59 100644 --- a/source/tools/i18n/i18n_helper/globber.py +++ b/source/tools/i18n/i18n_helper/globber.py @@ -1,12 +1,11 @@ """Utils to list .po.""" import os -from typing import List, Optional from i18n_helper.catalog import Catalog -def get_catalogs(input_file_path, filters: Optional[List[str]] = None) -> List[Catalog]: +def get_catalogs(input_file_path, filters: list[str] | None = None) -> list[Catalog]: """Return a list of "real" catalogs (.po) in the given folder.""" existing_translation_catalogs = [] l10n_folder_path = os.path.dirname(input_file_path) diff --git a/source/tools/i18n/tests/test_check_diff.py b/source/tools/i18n/tests/test_check_diff.py index 79375f9374..924feb27f3 100644 --- a/source/tools/i18n/tests/test_check_diff.py +++ b/source/tools/i18n/tests/test_check_diff.py @@ -97,7 +97,7 @@ PATCHES_EXPECT_REVERT = [ ] -@pytest.fixture(params=zip(PATCHES, PATCHES_EXPECT_REVERT)) +@pytest.fixture(params=zip(PATCHES, PATCHES_EXPECT_REVERT, strict=False)) def patch(request): return [io.StringIO(request.param[0]), request.param[1]] diff --git a/source/tools/rlclient/python/samples/simple_example.py b/source/tools/rlclient/python/samples/simple_example.py index 26ae80117d..e348fe7430 100644 --- a/source/tools/rlclient/python/samples/simple_example.py +++ b/source/tools/rlclient/python/samples/simple_example.py @@ -7,11 +7,11 @@ import zero_ad def dist(p1, p2): - return math.sqrt(sum(math.pow(x2 - x1, 2) for (x1, x2) in zip(p1, p2))) + return math.sqrt(sum(math.pow(x2 - x1, 2) for (x1, x2) in zip(p1, p2, strict=False))) def center(units): - sum_position = map(sum, zip(*(u.position() for u in units))) + sum_position = map(sum, zip(*(u.position() for u in units), strict=False)) return [x / len(units) for x in sum_position] diff --git a/source/tools/rlclient/python/tests/test_actions.py b/source/tools/rlclient/python/tests/test_actions.py index f9c6742d01..0faa354a52 100644 --- a/source/tools/rlclient/python/tests/test_actions.py +++ b/source/tools/rlclient/python/tests/test_actions.py @@ -11,11 +11,11 @@ with open(path.join(scriptdir, "..", "samples", "arcadia.json"), encoding="utf-8 def dist(p1, p2): - return math.sqrt(sum(math.pow(x2 - x1, 2) for (x1, x2) in zip(p1, p2))) + return math.sqrt(sum(math.pow(x2 - x1, 2) for (x1, x2) in zip(p1, p2, strict=False))) def center(units): - sum_position = map(sum, zip(*(u.position() for u in units))) + sum_position = map(sum, zip(*(u.position() for u in units), strict=False)) return [x / len(units) for x in sum_position] diff --git a/source/tools/rlclient/python/zero_ad/api.py b/source/tools/rlclient/python/zero_ad/api.py index f2705a5c61..97e78a2b6b 100644 --- a/source/tools/rlclient/python/zero_ad/api.py +++ b/source/tools/rlclient/python/zero_ad/api.py @@ -26,7 +26,7 @@ class RLAPI: def get_templates(self, names): post_data = "\n".join(names) response = self.post("templates", post_data) - return zip(names, response.decode().split("\n")) + return zip(names, response.decode().split("\n"), strict=False) def evaluate(self, code): response = self.post("evaluate", code) diff --git a/source/tools/rlclient/python/zero_ad/environment.py b/source/tools/rlclient/python/zero_ad/environment.py index e349654e7f..70e0959310 100644 --- a/source/tools/rlclient/python/zero_ad/environment.py +++ b/source/tools/rlclient/python/zero_ad/environment.py @@ -17,7 +17,7 @@ class ZeroAD: actions = [] player_ids = cycle([self.player_id]) if player is None else cycle(player) - cmds = zip(player_ids, actions) + cmds = zip(player_ids, actions, strict=False) cmds = ((player, action) for (player, action) in cmds if action is not None) state_json = self.api.step(cmds) self.current_state = GameState(json.loads(state_json), self)