Update the pre-commit hooks

This commit is contained in:
Dunedan
2025-01-09 16:35:31 +01:00
parent 5aa96cd282
commit a92a4ff45c
7 changed files with 22 additions and 26 deletions
+4 -4
View File
@@ -1,7 +1,7 @@
--- ---
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0 rev: v5.0.0
hooks: hooks:
- id: check-case-conflict - id: check-case-conflict
- id: check-executables-have-shebangs - id: check-executables-have-shebangs
@@ -19,7 +19,7 @@ repos:
^binaries/data/mods/public/maps/.*\.xml ^binaries/data/mods/public/maps/.*\.xml
) )
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.1 rev: v0.9.0
hooks: hooks:
- id: ruff - id: ruff
args: args:
@@ -41,7 +41,7 @@ repos:
files: ^binaries/ files: ^binaries/
exclude: (^binaries/data/mods/(mod|public)/art/.*\.xml|\.dae$) exclude: (^binaries/data/mods/(mod|public)/art/.*\.xml|\.dae$)
- repo: https://github.com/scop/pre-commit-shfmt - repo: https://github.com/scop/pre-commit-shfmt
rev: v3.9.0-1 rev: v3.10.0-2
hooks: hooks:
- id: shfmt - id: shfmt
args: args:
@@ -53,7 +53,7 @@ repos:
hooks: hooks:
- id: shellcheck - id: shellcheck
- repo: https://github.com/igorshubovych/markdownlint-cli - repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.41.0 rev: v0.43.0
hooks: hooks:
- id: markdownlint - id: markdownlint
exclude: | exclude: |
+2 -2
View File
@@ -1,9 +1,9 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import sys
from os import chdir from os import chdir
from pathlib import Path from pathlib import Path
from re import split from re import split
from subprocess import run from subprocess import run
from sys import exit
from scriptlib import SimulTemplateEntity, find_files, warn 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(f'"{f}" -> "{training_queue}" [color=blue];\n')
dot_f.write("}\n") dot_f.write("}\n")
if run(["dot", "-V"], capture_output=True, check=False).returncode == 0: if run(["dot", "-V"], capture_output=True, check=False).returncode == 0:
exit( sys.exit(
run( run(
["dot", "-Tpng", "creation.dot", "-o", "creation.png"], text=True, check=False ["dot", "-Tpng", "creation.dot", "-o", "creation.png"], text=True, check=False
).returncode ).returncode
+5 -6
View File
@@ -163,11 +163,11 @@ def generate_font(outname, ttf_names, loadopts, size, renderstyle, dsizes):
# Output the .fnt file with all the glyph positions etc # Output the .fnt file with all the glyph positions etc
with open(f"{outname}.fnt", "w", encoding="utf-8") as fnt: with open(f"{outname}.fnt", "w", encoding="utf-8") as fnt:
fnt.write("101\n") 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("%s\n" % ("rgba" if "colour" in renderstyle else "a"))
fnt.write("%d\n" % len(glyphs)) fnt.write(f"{len(glyphs)}\n")
fnt.write("%d\n" % linespacing) fnt.write(f"{linespacing}\n")
fnt.write("%d\n" % charheight) fnt.write(f"{charheight}\n")
for g in glyphs: for g in glyphs:
x0 = g.x0 x0 = g.x0
y0 = g.y0 y0 = g.y0
@@ -181,8 +181,7 @@ def generate_font(outname, ttf_names, loadopts, size, renderstyle, dsizes):
y0 += charheight / 3 y0 += charheight / 3
fnt.write( fnt.write(
"%d %d %d %d %d %d %d %d\n" f"{ord(g.char)} {g.pos.x} {h - g.pos.y} {g.w} {g.h} {-x0} {g.xadvance}\n"
% (ord(g.char), g.pos.x, h - g.pos.y, g.w, g.h, -x0, y0, g.xadvance)
) )
return return
+6 -9
View File
@@ -123,11 +123,6 @@ class Extractor:
class JavascriptExtractor(Extractor): class JavascriptExtractor(Extractor):
"""Extract messages from JavaScript source code.""" """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): def extract_javascript_from_file(self, file_object):
funcname = message_lineno = None funcname = message_lineno = None
messages = [] messages = []
@@ -282,11 +277,13 @@ class JavascriptExtractor(Extractor):
first_msg_index = spec[0] - 1 first_msg_index = spec[0] - 1
if not messages[first_msg_index]: if not messages[first_msg_index]:
# An empty string msgid isn't valid, emit a warning # An empty string msgid isn't valid, emit a warning
where = "%s:%i" % ( fname = (hasattr(file_object, "name") and file_object.name) or "(unknown)"
hasattr(file_object, "name") and file_object.name or "(unknown)", print(
lineno, 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 continue
messages = tuple(msgs) messages = tuple(msgs)
+3 -3
View File
@@ -52,8 +52,8 @@ def warn_about_untouched_mods():
if untouched_mods: if untouched_mods:
print("Warning: No messages were extracted from the following mods:") print("Warning: No messages were extracted from the following mods:")
for mod in untouched_mods: for mod_folder, error in untouched_mods.items():
print(f"{mod}: {untouched_mods[mod]}") print(f"{mod_folder}: {error}")
print( print(
"" ""
f"For this script to extract messages from a mod folder, this mod folder must contain " 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", {}) options = rule.get("options", {})
extractor_class = getattr( 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) extractor = extractor_class(input_root_path, rule["filemasks"], options)
format_flag = None format_flag = None
@@ -395,7 +395,7 @@ def write_coloured_diff(file, diff, is_changed):
if diff == 0: if diff == 0:
rgb_str = "200,200,200" 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" rgb_str = "180,0,0"
else: else:
rgb_str = "0,150,0" rgb_str = "0,150,0"