name: Run Ruff (lint) on Lib/test/
args: [--exit-non-zero-on-fix]
files: ^Lib/test/
+ - 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
name: Run Ruff (lint) on Argument Clinic
args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml]
--- /dev/null
+extend = "../../.ruff.toml" # Inherit the project-wide settings
+
+target-version = "py313"
+
+[lint]
+select = [
+ "F", # pyflakes
+ "I", # isort
+ "UP", # pyupgrade
+]
"""
import locale
import sys
+
_locale = locale
# Location of the X11 alias file.
def pprint(data):
items = sorted(data.items())
for k, v in items:
- print(' %-40s%a,' % ('%a:' % k, v))
+ print(f" {k!a:<40}{v!a},")
def print_differences(data, olddata):
items = sorted(olddata.items())
for k, v in items:
if k not in data:
- print('# removed %a' % k)
+ print(f'# removed {k!a}')
elif olddata[k] != data[k]:
- print('# updated %a -> %a to %a' % \
- (k, olddata[k], data[k]))
+ print(f'# updated {k!a} -> {olddata[k]!a} to {data[k]!a}')
# Additions are not mentioned
def optimize(data):
errors = 0
for k, v in data.items():
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)
errors += 1
return errors
parser = argparse.ArgumentParser()
parser.add_argument('--locale-alias', default=LOCALE_ALIAS,
help='location of the X11 alias file '
- '(default: %a)' % LOCALE_ALIAS)
+ f'(default: {LOCALE_ALIAS})')
parser.add_argument('--glibc-supported', default=SUPPORTED,
help='location of the glibc SUPPORTED locales file '
- '(default: %a)' % SUPPORTED)
+ f'(default: {SUPPORTED})')
args = parser.parse_args()
data = locale.locale_alias.copy()
Display version information and exit.
"""
-import os
-import sys
+import array
import ast
import getopt
+import os
import struct
-import array
+import sys
from email.parser import HeaderParser
__version__ = "1.2"
+
MESSAGES = {}
try:
with open(infile, 'rb') as f:
lines = f.readlines()
- except IOError as msg:
+ except OSError as msg:
print(msg, file=sys.stderr)
sys.exit(1)
section = msgctxt = None
+ msgid = msgstr = b''
fuzzy = 0
# Start off assuming Latin-1, so everything decodes without failure,
# This is a message with plural forms
elif l.startswith('msgid_plural'):
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)
sys.exit(1)
l = l[12:]
section = STR
if l.startswith('msgstr['):
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)
sys.exit(1)
l = l.split(']', 1)[1]
msgstr += b'\0' # Separator of the various plural forms
else:
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)
sys.exit(1)
l = l[6:]
elif section == STR:
msgstr += l.encode(encoding)
else:
- print('Syntax error on %s:%d' % (infile, lno), \
- 'before:', file=sys.stderr)
+ print(f'Syntax error on {infile}:{lno} before:', file=sys.stderr)
print(l, file=sys.stderr)
sys.exit(1)
# Add last entry
try:
with open(outfile,"wb") as f:
f.write(output)
- except IOError as msg:
+ except OSError as msg:
print(msg, file=sys.stderr)
else:
mod = 256
escape = escape_nonascii
- escapes = [r"\%03o" % i for i in range(mod)]
+ escapes = [fr"\{i:03o}" for i in range(mod)]
for i in range(32, 127):
escapes[i] = chr(i)
escapes[ord('\\')] = r'\\'
try:
with open(options.excludefilename) as fp:
options.toexclude = fp.readlines()
- except IOError:
+ except OSError:
print(_(
"Can't read --exclude-file: %s") % options.excludefilename, file=sys.stderr)
sys.exit(1)