]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-138286: Run ``ruff`` on ``Tools/i18n`` (GH-138287) (#138524)
authorStan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Fri, 5 Sep 2025 07:55:04 +0000 (08:55 +0100)
committerGitHub <noreply@github.com>
Fri, 5 Sep 2025 07:55:04 +0000 (10:55 +0300)
* [3.13] gh-138286: Run ``ruff`` on ``Tools/i18n`` (GH-138287)
(cherry picked from commit 78acd8e95e78bc410b8207cd60e1323ece01b3d5)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
* Commit

* Commit

---------

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
.pre-commit-config.yaml
Tools/i18n/.ruff.toml [new file with mode: 0644]
Tools/i18n/makelocalealias.py
Tools/i18n/msgfmt.py
Tools/i18n/pygettext.py

index c146201fc355efd255c3df7c880e952a397c30ed..e35b0880a4370edad0ff954885828fd2ca9c9f0a 100644 (file)
@@ -10,6 +10,10 @@ repos:
         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]
diff --git a/Tools/i18n/.ruff.toml b/Tools/i18n/.ruff.toml
new file mode 100644 (file)
index 0000000..a8f4f2f
--- /dev/null
@@ -0,0 +1,10 @@
+extend = "../../.ruff.toml"  # Inherit the project-wide settings
+
+target-version = "py313"
+
+[lint]
+select = [
+    "F",     # pyflakes
+    "I",     # isort
+    "UP",    # pyupgrade
+]
index 02af1caff7d499813f8846c50422617d5e783ea1..085da1c63b701c30f1cb8fbf2082951c7ea23ad5 100755 (executable)
@@ -8,6 +8,7 @@
 """
 import locale
 import sys
+
 _locale = locale
 
 # Location of the X11 alias file.
@@ -89,16 +90,15 @@ def parse_glibc_supported(filename):
 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):
@@ -121,7 +121,7 @@ def check(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
@@ -131,10 +131,10 @@ if __name__ == '__main__':
     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()
index ecebf5d6a51ee87f4dddcc573fd84cf670b058d3..27b67f2843143591ab939351e3f8059c3e372cc0 100755 (executable)
@@ -25,16 +25,17 @@ Options:
         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 = {}
 
 
@@ -112,11 +113,12 @@ def make(filename, outfile):
     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,
@@ -168,7 +170,7 @@ def make(filename, outfile):
         # 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:]
@@ -179,7 +181,7 @@ def make(filename, outfile):
             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]
@@ -187,7 +189,7 @@ def make(filename, outfile):
                     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:]
@@ -203,8 +205,7 @@ def make(filename, outfile):
         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
@@ -217,7 +218,7 @@ def make(filename, outfile):
     try:
         with open(outfile,"wb") as f:
             f.write(output)
-    except IOError as msg:
+    except OSError as msg:
         print(msg, file=sys.stderr)
 
 
index 8f59982640cbbabd74bd561d79f773a93420ffd2..058a41783779113ff5e9cf39471fdf8ec250d896 100755 (executable)
@@ -214,7 +214,7 @@ def make_escapes(pass_nonascii):
     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'\\'
@@ -620,7 +620,7 @@ def main():
         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)