From a92a4ff45c98b7e68ac1b5fcc6e994940100313b Mon Sep 17 00:00:00 2001 From: Dunedan Date: Thu, 9 Jan 2025 16:35:31 +0100 Subject: [PATCH] Update the pre-commit hooks --- .pre-commit-config.yaml | 8 ++++---- source/tools/entity/checkrefs.py | 2 +- source/tools/entity/creationgraph.py | 4 ++-- source/tools/fontbuilder2/fontbuilder.py | 11 +++++------ source/tools/i18n/i18n_helper/extractors.py | 15 ++++++--------- source/tools/i18n/update_templates.py | 6 +++--- source/tools/templatesanalyzer/unit_tables.py | 2 +- 7 files changed, 22 insertions(+), 26 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 293064f320..535514ae79 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ --- repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-case-conflict - id: check-executables-have-shebangs @@ -19,7 +19,7 @@ repos: ^binaries/data/mods/public/maps/.*\.xml ) - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.1 + rev: v0.9.0 hooks: - id: ruff args: @@ -41,7 +41,7 @@ repos: files: ^binaries/ exclude: (^binaries/data/mods/(mod|public)/art/.*\.xml|\.dae$) - repo: https://github.com/scop/pre-commit-shfmt - rev: v3.9.0-1 + rev: v3.10.0-2 hooks: - id: shfmt args: @@ -53,7 +53,7 @@ repos: hooks: - id: shellcheck - repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.41.0 + rev: v0.43.0 hooks: - id: markdownlint exclude: | diff --git a/source/tools/entity/checkrefs.py b/source/tools/entity/checkrefs.py index 667d5162b5..81b5d2765f 100755 --- a/source/tools/entity/checkrefs.py +++ b/source/tools/entity/checkrefs.py @@ -195,7 +195,7 @@ class CheckRefs: self.deps.append((fp, Path(f"art/actors/{template[len(actor_prefix) :]}"))) elif template.startswith(resource_prefix): self.deps.append( - (fp, Path(f"simulation/templates/{template[len(resource_prefix):]}.xml")) + (fp, Path(f"simulation/templates/{template[len(resource_prefix) :]}.xml")) ) else: self.deps.append((fp, Path(f"simulation/templates/{template}.xml"))) diff --git a/source/tools/entity/creationgraph.py b/source/tools/entity/creationgraph.py index 6c9bb81a60..7127777948 100755 --- a/source/tools/entity/creationgraph.py +++ b/source/tools/entity/creationgraph.py @@ -1,9 +1,9 @@ #!/usr/bin/env python3 +import sys from os import chdir from pathlib import Path from re import split from subprocess import run -from sys import exit from scriptlib import SimulTemplateEntity, find_files, warn @@ -58,7 +58,7 @@ def main(): dot_f.write(f'"{f}" -> "{training_queue}" [color=blue];\n') dot_f.write("}\n") if run(["dot", "-V"], capture_output=True, check=False).returncode == 0: - exit( + sys.exit( run( ["dot", "-Tpng", "creation.dot", "-o", "creation.png"], text=True, check=False ).returncode diff --git a/source/tools/fontbuilder2/fontbuilder.py b/source/tools/fontbuilder2/fontbuilder.py index 431b93b89f..ddc398fb18 100755 --- a/source/tools/fontbuilder2/fontbuilder.py +++ b/source/tools/fontbuilder2/fontbuilder.py @@ -163,11 +163,11 @@ def generate_font(outname, ttf_names, loadopts, size, renderstyle, dsizes): # Output the .fnt file with all the glyph positions etc with open(f"{outname}.fnt", "w", encoding="utf-8") as fnt: fnt.write("101\n") - fnt.write("%d %d\n" % (w, h)) + fnt.write(f"{w} {h}\n") fnt.write("%s\n" % ("rgba" if "colour" in renderstyle else "a")) - fnt.write("%d\n" % len(glyphs)) - fnt.write("%d\n" % linespacing) - fnt.write("%d\n" % charheight) + fnt.write(f"{len(glyphs)}\n") + fnt.write(f"{linespacing}\n") + fnt.write(f"{charheight}\n") for g in glyphs: x0 = g.x0 y0 = g.y0 @@ -181,8 +181,7 @@ def generate_font(outname, ttf_names, loadopts, size, renderstyle, dsizes): y0 += charheight / 3 fnt.write( - "%d %d %d %d %d %d %d %d\n" - % (ord(g.char), g.pos.x, h - g.pos.y, g.w, g.h, -x0, y0, g.xadvance) + f"{ord(g.char)} {g.pos.x} {h - g.pos.y} {g.w} {g.h} {-x0} {g.xadvance}\n" ) return diff --git a/source/tools/i18n/i18n_helper/extractors.py b/source/tools/i18n/i18n_helper/extractors.py index 5748ba2aa3..626c569f6c 100644 --- a/source/tools/i18n/i18n_helper/extractors.py +++ b/source/tools/i18n/i18n_helper/extractors.py @@ -123,11 +123,6 @@ class Extractor: class JavascriptExtractor(Extractor): """Extract messages from JavaScript source code.""" - empty_msgid_warning = ( - '%s: warning: Empty msgid. It is reserved by GNU gettext: gettext("") ' - "returns the header entry with meta information, not the empty string." - ) - def extract_javascript_from_file(self, file_object): funcname = message_lineno = None messages = [] @@ -282,11 +277,13 @@ class JavascriptExtractor(Extractor): first_msg_index = spec[0] - 1 if not messages[first_msg_index]: # An empty string msgid isn't valid, emit a warning - where = "%s:%i" % ( - hasattr(file_object, "name") and file_object.name or "(unknown)", - lineno, + fname = (hasattr(file_object, "name") and file_object.name) or "(unknown)" + print( + f"{fname}:{lineno}: warning: Empty msgid. It is reserved by GNU gettext: " + 'gettext("") returns the header entry with meta information, ' + "not the empty string.", + file=sys.stderr, ) - print(self.empty_msgid_warning % where, file=sys.stderr) continue messages = tuple(msgs) diff --git a/source/tools/i18n/update_templates.py b/source/tools/i18n/update_templates.py index aafd9623eb..d8c60f5d76 100755 --- a/source/tools/i18n/update_templates.py +++ b/source/tools/i18n/update_templates.py @@ -52,8 +52,8 @@ def warn_about_untouched_mods(): if untouched_mods: print("Warning: No messages were extracted from the following mods:") - for mod in untouched_mods: - print(f"• {mod}: {untouched_mods[mod]}") + for mod_folder, error in untouched_mods.items(): + print(f"• {mod_folder}: {error}") print( "" f"For this script to extract messages from a mod folder, this mod folder must contain " @@ -83,7 +83,7 @@ def generate_pot(template_settings, root_path): options = rule.get("options", {}) extractor_class = getattr( - import_module("i18n_helper.extractors"), f'{rule["extractor"].title()}Extractor' + import_module("i18n_helper.extractors"), f"{rule['extractor'].title()}Extractor" ) extractor = extractor_class(input_root_path, rule["filemasks"], options) format_flag = None diff --git a/source/tools/templatesanalyzer/unit_tables.py b/source/tools/templatesanalyzer/unit_tables.py index 25957acacd..b3abad2fd8 100755 --- a/source/tools/templatesanalyzer/unit_tables.py +++ b/source/tools/templatesanalyzer/unit_tables.py @@ -395,7 +395,7 @@ def write_coloured_diff(file, diff, is_changed): if diff == 0: rgb_str = "200,200,200" - elif is_advantageous and diff > 0 or (not is_advantageous) and diff < 0: + elif (is_advantageous and diff > 0) or (not is_advantageous and diff < 0): rgb_str = "180,0,0" else: rgb_str = "0,150,0"