Skip to content

Commit 4f022f7

Browse files
committed
chore: use more of ruff
1 parent a234f85 commit 4f022f7

19 files changed

+63
-68
lines changed

pyproject.toml

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ target-version = "py39"
104104
[tool.ruff.lint]
105105
ignore = [
106106
"D10", # TODO: we are missing many docstrings
107+
"PTH", # TODO: Not using pathlib
108+
"EM", # TODO: exception literals
109+
"PERF401", # TODO
110+
"COM812", # CONFIG: trailing newlines
111+
"FBT", # TODO: Boolean in function definition
107112
"D203", # CONFIG: incompatible with D211
108113
"D212", # CONFIG: incompatible with D213
109114
"ISC001", # CONFIG: incompatible with formatter
@@ -114,44 +119,14 @@ ignore = [
114119
"RUF012", # TODO: Mutable class attributes should be annotated with `typing.ClassVar`
115120
"E501" # WONTFIX: we accept long strings (rest is formatted by black)
116121
]
117-
select = [
118-
"E",
119-
"F",
120-
"B",
121-
"T10",
122-
"A",
123-
"C4",
124-
"C90",
125-
"YTT",
126-
"DJ",
127-
"UP",
128-
"D",
129-
"PD",
130-
"PGH",
131-
"PL",
132-
"TRY",
133-
"RUF",
134-
"ERA",
135-
"ICN",
136-
"ISC",
137-
"EXE",
138-
"INP",
139-
"PIE",
140-
"G",
141-
"PYI",
142-
"Q",
143-
"SIM",
144-
"TID",
145-
"RSE",
146-
"T20",
147-
"RET",
148-
"SLF",
149-
"N"
150-
]
122+
select = ["ALL"]
151123

152124
[tool.ruff.lint.mccabe]
153125
max-complexity = 16
154126

127+
[tool.ruff.lint.per-file-ignores]
128+
"scripts/*" = ["S607", "S603", "S310", "ANN"]
129+
155130
[tool.setuptools]
156131
include-package-data = true
157132
# Empty as a workaround for https://github.com/pypa/setuptools/issues/4759

scripts/add-iso

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ for code in sys.argv[1:]:
5454
sys.stderr.write(f"Failed to load data for {code}, using defaults\n")
5555
lines.append(
5656
"{},{},{},{}\n".format(
57-
code, names[code].split(";")[-1].strip(), plurals, formula
58-
)
57+
code,
58+
names[code].split(";")[-1].strip(),
59+
plurals,
60+
formula,
61+
),
5962
)
6063

6164
with open("languages.csv", "w") as handle:

scripts/add-iso-population

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,7 @@ for code, population in POPULATION.items():
3636
continue
3737
if code not in LANGUAGE_CODES and code not in ALIASES:
3838
print(f"Adding {code} ({population})")
39-
subprocess.run(["./scripts/add-iso", code], check=False)
39+
subprocess.run(
40+
["./scripts/add-iso", code],
41+
check=False,
42+
)

scripts/export-cldr

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#
55
# SPDX-License-Identifier: MIT
66

7+
from __future__ import annotations
8+
79
import json
810
import re
911

@@ -106,7 +108,7 @@ def convert_atom(atom: str) -> str | bool:
106108
# For gettext: f == empty, t == empty, c == empty, e == empty
107109
return int(match.group(1)) != 0
108110
raise ValueError(
109-
f"Unable to convert the formula chunk '{atom}' from CLDR to gettext"
111+
f"Unable to convert the formula chunk '{atom}' from CLDR to gettext",
110112
)
111113

112114

@@ -131,7 +133,7 @@ def convert_formula(cldr_formula_and_examples: str) -> str:
131133
# Sanity checkign
132134
if "(" in cldr_formula or ")" in cldr_formula:
133135
raise ValueError(
134-
f"Unable to convert the formula '{cldr_formula}': parenthesis handling not implemented"
136+
f"Unable to convert the formula '{cldr_formula}': parenthesis handling not implemented",
135137
)
136138

137139
# Blank formula for other
@@ -176,7 +178,8 @@ def reverse_formula(formula: str) -> str:
176178
return formula.replace(" == ", " != ").replace(" || ", " && ").strip("()")
177179

178180
if match := re.match(
179-
r"^(n(?: % \d+)?) == (\d+) && (n(?: % \d+)?) != (\d+)$", formula
181+
r"^(n(?: % \d+)?) == (\d+) && (n(?: % \d+)?) != (\d+)$",
182+
formula,
180183
):
181184
return f"{match.group(1)} != {match.group(2)} || {match.group(3)} == {match.group(4)}"
182185

@@ -199,7 +202,7 @@ def merge_formulas(formulas: list[str]) -> str:
199202
for n in range(max_n - 1, -1, -1):
200203
part = formulas[n]
201204

202-
if not re.match("^\([^()]+\)$", part):
205+
if not re.match(r"^\([^()]+\)$", part):
203206
part = f"({part})"
204207
formula = f"{reduce_formula(part)} ? {n} : {formula}"
205208
if n > 0:
@@ -210,7 +213,7 @@ def merge_formulas(formulas: list[str]) -> str:
210213

211214
# Load language names
212215
with open(
213-
"modules/cldr-json/cldr-json/cldr-localenames-full/main/en/languages.json"
216+
"modules/cldr-json/cldr-json/cldr-localenames-full/main/en/languages.json",
214217
) as handle:
215218
data = json.load(handle)
216219
LANGUAGES = {
@@ -279,5 +282,10 @@ with open("cldr.csv", "w") as handle:
279282
for code in sorted(LANGUAGES):
280283
data = LANGUAGES[code]
281284
handle.write(
282-
"{},{},{},{}\n".format(code, data["name"], data["plurals"], data["formula"])
285+
"{},{},{},{}\n".format(
286+
code,
287+
data["name"],
288+
data["plurals"],
289+
data["formula"],
290+
),
283291
)

scripts/export-cldr-case

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#
55
# SPDX-License-Identifier: MIT
66

7-
import json
87
import csv
8+
import json
99

1010
# Read languages
1111
with open("languages.csv") as csvfile:
@@ -25,7 +25,7 @@ with open("case-insensitive.csv") as csvfile:
2525
with open("modules/cldr-json/cldr-json/cldr-core/scriptMetadata.json") as handle:
2626
SCRIPTS = json.load(handle)["scriptMetadata"]
2727
with open(
28-
"modules/cldr-json/cldr-json/cldr-core/supplemental/languageData.json"
28+
"modules/cldr-json/cldr-json/cldr-core/supplemental/languageData.json",
2929
) as handle:
3030
LANGUAGES = json.load(handle)["supplemental"]["languageData"]
3131

scripts/export-cldr-orientation

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#
55
# SPDX-License-Identifier: MIT
66

7+
import csv
78
import json
89
from pathlib import Path
9-
import csv
1010

1111
# Read languages
1212
with open("languages.csv") as csvfile:

scripts/export-cldr-population

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ MAPPING = {
1212
}
1313

1414
with open(
15-
"modules/cldr-json/cldr-json/cldr-core/supplemental/territoryInfo.json"
15+
"modules/cldr-json/cldr-json/cldr-core/supplemental/territoryInfo.json",
1616
) as handle:
1717
languages = defaultdict(int)
1818
for code, territory in json.load(handle)["supplemental"]["territoryInfo"].items():

scripts/export-gettext

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ for line in content.splitlines():
2828
matches[2],
2929
int(matches[3].split(";", 1)[0].split("=")[1]),
3030
matches[3].split(";", 1)[1].split("=", 1)[1].rstrip(";"),
31-
)
31+
),
3232
)
3333

3434
with open("gettext.csv", "w") as handle:

scripts/export-iso-aliases

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ with open(ALIASES) as handle:
7979
if code in names:
8080
if names[code] != replacement:
8181
print(
82-
f"Conflicting replacement for {code}: {names[code]} != {replacement} {alias}"
82+
f"Conflicting replacement for {code}: {names[code]} != {replacement} {alias}",
8383
)
8484
continue
8585
names[code] = replacement

scripts/export-l10n-guide

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ for line in content.splitlines():
2929
matches[2],
3030
int(plural_parts[0].split("=")[1]),
3131
plural_parts[1].split("=", 1)[1].rstrip(";"),
32-
)
32+
),
3333
)
3434

3535
with open("l10n-guide.csv", "w") as handle:

0 commit comments

Comments
 (0)