Compare commits

...

2 Commits

Author SHA1 Message Date
b5bb79ae6b
Fix ruff errors caused checking for Python 3.11 2024-09-15 11:30:13 +02:00
3208241a62
Specify the target version in ruff.toml
This allows ruff even if it's not run through pre-commit to use the
correct target Python version.
2024-09-13 21:49:58 +02:00
12 changed files with 20 additions and 26 deletions

View File

@ -26,14 +26,10 @@ repos:
- id: ruff
args:
- --output-format=full
- --target-version
- py311
exclude: ^source/tools/webservices/
- id: ruff-format
args:
- --check
- --target-version
- py311
exclude: ^source/tools/webservices/
- repo: local
hooks:

View File

@ -1,5 +1,7 @@
line-length = 99
target-version = "py311"
[format]
line-ending = "lf"

View File

@ -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()

View File

@ -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))

View File

@ -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.

View File

@ -1,6 +1,6 @@
"""Wrapper around babel Catalog / .po handling."""
from datetime import datetime, timezone
from datetime import UTC, datetime
from babel.messages.catalog import Catalog as BabelCatalog
from babel.messages.pofile import read_po, write_po
@ -10,7 +10,7 @@ class Catalog(BabelCatalog):
"""Wraps a BabelCatalog for convenience."""
def __init__(self, *args, project=None, copyright_holder=None, **other_kwargs):
date = datetime.now(tz=timezone.utc)
date = datetime.now(tz=UTC)
super().__init__(
*args,
header_comment=(

View File

@ -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)

View File

@ -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]]

View File

@ -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]

View File

@ -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]

View File

@ -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)

View File

@ -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)