gh-138286: Run `ruff on Tools/i18n` (#138287)
Some checks are pending
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Ubuntu SSL tests with AWS-LC (push) Blocked by required conditions
Tests / Android (aarch64) (push) Blocked by required conditions
Tests / Android (x86_64) (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
This commit is contained in:
Stan Ulbrych 2025-08-31 21:29:02 +01:00 committed by GitHub
parent 15e37ea6b7
commit 78acd8e95e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 36 additions and 22 deletions

View file

@ -14,6 +14,10 @@ repos:
name: Run Ruff (lint) on Tools/build/ name: Run Ruff (lint) on Tools/build/
args: [--exit-non-zero-on-fix, --config=Tools/build/.ruff.toml] args: [--exit-non-zero-on-fix, --config=Tools/build/.ruff.toml]
files: ^Tools/build/ files: ^Tools/build/
- id: ruff
name: Run Ruff (lint) on Tools/i18n/
args: [--exit-non-zero-on-fix, --config=Tools/i18n/.ruff.toml]
files: ^Tools/i18n/
- id: ruff - id: ruff
name: Run Ruff (lint) on Argument Clinic name: Run Ruff (lint) on Argument Clinic
args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml] args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml]

10
Tools/i18n/.ruff.toml Normal file
View file

@ -0,0 +1,10 @@
extend = "../../.ruff.toml" # Inherit the project-wide settings
target-version = "py313"
[lint]
select = [
"F", # pyflakes
"I", # isort
"UP", # pyupgrade
]

View file

@ -8,6 +8,7 @@
""" """
import locale import locale
import sys import sys
_locale = locale _locale = locale
# Location of the X11 alias file. # Location of the X11 alias file.
@ -100,16 +101,15 @@ def parse_glibc_supported(filename):
def pprint(data): def pprint(data):
items = sorted(data.items()) items = sorted(data.items())
for k, v in items: for k, v in items:
print(' %-40s%a,' % ('%a:' % k, v)) print(f" {k!a:<40}{v!a},")
def print_differences(data, olddata): def print_differences(data, olddata):
items = sorted(olddata.items()) items = sorted(olddata.items())
for k, v in items: for k, v in items:
if k not in data: if k not in data:
print('# removed %a' % k) print(f'# removed {k!a}')
elif olddata[k] != data[k]: elif olddata[k] != data[k]:
print('# updated %a -> %a to %a' % \ print(f'# updated {k!a} -> {olddata[k]!a} to {data[k]!a}')
(k, olddata[k], data[k]))
# Additions are not mentioned # Additions are not mentioned
def optimize(data): def optimize(data):
@ -132,7 +132,7 @@ def check(data):
errors = 0 errors = 0
for k, v in data.items(): for k, v in data.items():
if locale.normalize(k) != v: if locale.normalize(k) != v:
print('ERROR: %a -> %a != %a' % (k, locale.normalize(k), v), print(f'ERROR: {k!a} -> {locale.normalize(k)!a} != {v!a}',
file=sys.stderr) file=sys.stderr)
errors += 1 errors += 1
return errors return errors
@ -142,10 +142,10 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--locale-alias', default=LOCALE_ALIAS, parser.add_argument('--locale-alias', default=LOCALE_ALIAS,
help='location of the X11 alias file ' help='location of the X11 alias file '
'(default: %a)' % LOCALE_ALIAS) f'(default: {LOCALE_ALIAS})')
parser.add_argument('--glibc-supported', default=SUPPORTED, parser.add_argument('--glibc-supported', default=SUPPORTED,
help='location of the glibc SUPPORTED locales file ' help='location of the glibc SUPPORTED locales file '
'(default: %a)' % SUPPORTED) f'(default: {SUPPORTED})')
args = parser.parse_args() args = parser.parse_args()
data = locale.locale_alias.copy() data = locale.locale_alias.copy()

View file

@ -24,14 +24,14 @@ Options:
Display version information and exit. Display version information and exit.
""" """
import os
import sys
import ast
import getopt
import struct
import array import array
from email.parser import HeaderParser import ast
import codecs import codecs
import getopt
import os
import struct
import sys
from email.parser import HeaderParser
__version__ = "1.2" __version__ = "1.2"
@ -113,7 +113,7 @@ def make(filename, outfile):
try: try:
with open(infile, 'rb') as f: with open(infile, 'rb') as f:
lines = f.readlines() lines = f.readlines()
except IOError as msg: except OSError as msg:
print(msg, file=sys.stderr) print(msg, file=sys.stderr)
sys.exit(1) sys.exit(1)
@ -126,6 +126,7 @@ def make(filename, outfile):
sys.exit(1) sys.exit(1)
section = msgctxt = None section = msgctxt = None
msgid = msgstr = b''
fuzzy = 0 fuzzy = 0
# Start off assuming Latin-1, so everything decodes without failure, # Start off assuming Latin-1, so everything decodes without failure,
@ -177,7 +178,7 @@ def make(filename, outfile):
# This is a message with plural forms # This is a message with plural forms
elif l.startswith('msgid_plural'): elif l.startswith('msgid_plural'):
if section != ID: if section != ID:
print('msgid_plural not preceded by msgid on %s:%d' % (infile, lno), print(f'msgid_plural not preceded by msgid on {infile}:{lno}',
file=sys.stderr) file=sys.stderr)
sys.exit(1) sys.exit(1)
l = l[12:] l = l[12:]
@ -188,7 +189,7 @@ def make(filename, outfile):
section = STR section = STR
if l.startswith('msgstr['): if l.startswith('msgstr['):
if not is_plural: if not is_plural:
print('plural without msgid_plural on %s:%d' % (infile, lno), print(f'plural without msgid_plural on {infile}:{lno}',
file=sys.stderr) file=sys.stderr)
sys.exit(1) sys.exit(1)
l = l.split(']', 1)[1] l = l.split(']', 1)[1]
@ -196,7 +197,7 @@ def make(filename, outfile):
msgstr += b'\0' # Separator of the various plural forms msgstr += b'\0' # Separator of the various plural forms
else: else:
if is_plural: if is_plural:
print('indexed msgstr required for plural on %s:%d' % (infile, lno), print(f'indexed msgstr required for plural on {infile}:{lno}',
file=sys.stderr) file=sys.stderr)
sys.exit(1) sys.exit(1)
l = l[6:] l = l[6:]
@ -212,8 +213,7 @@ def make(filename, outfile):
elif section == STR: elif section == STR:
msgstr += l.encode(encoding) msgstr += l.encode(encoding)
else: else:
print('Syntax error on %s:%d' % (infile, lno), \ print(f'Syntax error on {infile}:{lno} before:', file=sys.stderr)
'before:', file=sys.stderr)
print(l, file=sys.stderr) print(l, file=sys.stderr)
sys.exit(1) sys.exit(1)
# Add last entry # Add last entry
@ -226,7 +226,7 @@ def make(filename, outfile):
try: try:
with open(outfile,"wb") as f: with open(outfile,"wb") as f:
f.write(output) f.write(output)
except IOError as msg: except OSError as msg:
print(msg, file=sys.stderr) print(msg, file=sys.stderr)

View file

@ -193,7 +193,7 @@ def make_escapes(pass_nonascii):
escape = escape_ascii escape = escape_ascii
else: else:
escape = escape_nonascii escape = escape_nonascii
escapes = [r"\%03o" % i for i in range(256)] escapes = [fr"\{i:03o}" for i in range(256)]
for i in range(32, 127): for i in range(32, 127):
escapes[i] = chr(i) escapes[i] = chr(i)
escapes[ord('\\')] = r'\\' escapes[ord('\\')] = r'\\'
@ -796,7 +796,7 @@ def main():
try: try:
with open(options.excludefilename) as fp: with open(options.excludefilename) as fp:
options.toexclude = fp.readlines() options.toexclude = fp.readlines()
except IOError: except OSError:
print(f"Can't read --exclude-file: {options.excludefilename}", print(f"Can't read --exclude-file: {options.excludefilename}",
file=sys.stderr) file=sys.stderr)
sys.exit(1) sys.exit(1)