Skip to content

Commit f94f090

Browse files
rtibblesclaude
andcommitted
Reformat codebase with ruff (replacing black 20.8b1 + flake8 + reorder-python-imports)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1987ddb commit f94f090

439 files changed

Lines changed: 4660 additions & 15213 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-hooks/check_lfs_pointers.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
not binary data. This works whether or not Git LFS is installed in the environment
1010
running the check.
1111
"""
12+
1213
import logging
1314
import subprocess
1415
import sys
@@ -90,9 +91,7 @@ def main(filenames):
9091
logger.error("ERROR: LFS Pointer Check Failed")
9192
logger.error("=" * 80)
9293
logger.error("")
93-
logger.error(
94-
"The following files should be LFS pointers but contain binary data:"
95-
)
94+
logger.error("The following files should be LFS pointers but contain binary data:")
9695
logger.error("")
9796

9897
for filepath in failed_files:
@@ -105,9 +104,7 @@ def main(filenames):
105104
logger.error("")
106105
logger.error("To fix this issue:")
107106
logger.error(" 1. Ensure Git LFS is installed: git lfs install")
108-
logger.error(
109-
" 2. Remove the binary files from staging: git rm --cached <file>"
110-
)
107+
logger.error(" 2. Remove the binary files from staging: git rm --cached <file>")
111108
logger.error(" 3. Re-add the files (Git LFS will handle them): git add <file>")
112109
logger.error("=" * 80)
113110
logger.error("")

build_tools/customize_build.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
For more detail see the documentation in __init__.py
77
"""
8+
89
import logging
910
import os
1011
import sys
@@ -23,43 +24,28 @@ def load_plugins_from_file(file_path):
2324
if file_path not in plugins_cache:
2425
# We have been passed a URL, not a local file path
2526
if file_path.startswith("http"):
26-
logger.info(
27-
"Downloading plugins manifest from {file_path}".format(
28-
file_path=file_path
29-
)
30-
)
27+
logger.info("Downloading plugins manifest from {file_path}".format(file_path=file_path))
3128
_, path = tempfile.mkstemp(suffix=".txt", text=True)
3229
with open(path, "w") as f:
3330
r = requests.get(file_path)
3431
f.write(r.content)
3532
file_path = path
3633
with open(file_path, "r") as f:
37-
plugins_cache[file_path] = [
38-
plugin.strip() for plugin in f.readlines() if plugin.strip()
39-
]
34+
plugins_cache[file_path] = [plugin.strip() for plugin in f.readlines() if plugin.strip()]
4035
return plugins_cache[file_path]
4136

4237

43-
build_config_path = os.path.join(
44-
os.path.dirname(__file__), "../kolibri/utils/build_config"
45-
)
38+
build_config_path = os.path.join(os.path.dirname(__file__), "../kolibri/utils/build_config")
4639

4740
default_settings_template = "settings_path = '{path}'"
4841

4942

5043
def set_default_settings_module():
51-
if (
52-
"DEFAULT_SETTINGS_MODULE" in os.environ
53-
and os.environ["DEFAULT_SETTINGS_MODULE"]
54-
):
44+
if "DEFAULT_SETTINGS_MODULE" in os.environ and os.environ["DEFAULT_SETTINGS_MODULE"]:
5545
default_settings_path = os.environ["DEFAULT_SETTINGS_MODULE"]
5646
with open(os.path.join(build_config_path, "default_settings.py"), "w") as f:
5747
# Just write out settings_path = '<settings_path>'
58-
logger.info(
59-
"Setting default settings module to {path}".format(
60-
path=default_settings_path
61-
)
62-
)
48+
logger.info("Setting default settings module to {path}".format(path=default_settings_path))
6349
f.write(default_settings_template.format(path=default_settings_path))
6450

6551

build_tools/customize_docker_envlist.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
55
For more detail see the documentation in __init__.py
66
"""
7+
78
import logging
89
import os
910

1011
BUILD_ENV_PREFIX = "KOLIBRI_BUILD_"
11-
ENVLIST_FILE = os.path.abspath(
12-
os.path.join(os.path.dirname(os.path.dirname(__file__)), "docker", "env.list")
13-
)
12+
ENVLIST_FILE = os.path.abspath(os.path.join(os.path.dirname(os.path.dirname(__file__)), "docker", "env.list"))
1413

1514
logger = logging.getLogger(__name__)
1615

@@ -26,11 +25,7 @@ def add_env_var_to_docker():
2625
if env.startswith(BUILD_ENV_PREFIX):
2726
key = env.replace(BUILD_ENV_PREFIX, "")
2827
f.write("\n{key}={value}".format(key=key, value=envs[env]))
29-
logger.info(
30-
"Writing value of environment variable {} to Docker env.list\n".format(
31-
key
32-
)
33-
)
28+
logger.info("Writing value of environment variable {} to Docker env.list\n".format(key))
3429

3530

3631
if __name__ == "__main__":

build_tools/customize_requirements.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
For more detail see the documentation in __init__.py
66
"""
7+
78
import logging
89
import os
910
import tempfile
@@ -18,27 +19,17 @@ def add_requirements_to_base():
1819
file_path = os.environ["EXTRA_REQUIREMENTS"]
1920
# We have been passed a URL, not a local file path
2021
if file_path.startswith("http"):
21-
logger.info(
22-
"Downloading extra requirements from {file_path}".format(
23-
file_path=file_path
24-
)
25-
)
22+
logger.info("Downloading extra requirements from {file_path}".format(file_path=file_path))
2623
_, path = tempfile.mkstemp(suffix=".txt", text=True)
2724
with open(path, "w") as f:
2825
r = requests.get(file_path)
2926
f.write(r.content)
3027
file_path = path
3128
try:
3229
with open(file_path, "r") as f:
33-
requirements = [
34-
requirement.strip()
35-
for requirement in f.readlines()
36-
if requirement.strip()
37-
]
30+
requirements = [requirement.strip() for requirement in f.readlines() if requirement.strip()]
3831
if requirements:
39-
with open(
40-
os.path.join(os.path.dirname(__file__), "../requirements.txt"), "a"
41-
) as f:
32+
with open(os.path.join(os.path.dirname(__file__), "../requirements.txt"), "a") as f:
4233
f.writelines(requirements)
4334
except OSError:
4435
pass

build_tools/i18n/cleanup_unsupported_languages.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
This script should be run after downloading translations from Crowdin to clean up
66
any languages that were downloaded but are not officially supported by Kolibri.
77
"""
8+
89
import logging
910
import os
1011
import shutil
@@ -40,9 +41,7 @@ def cleanup_unsupported_languages():
4041
removed_locales.append(item)
4142

4243
if removed_locales:
43-
logging.info(
44-
f"Removed unsupported language directories: {', '.join(sorted(removed_locales))}"
45-
)
44+
logging.info(f"Removed unsupported language directories: {', '.join(sorted(removed_locales))}")
4645
else:
4746
logging.info("No unsupported language directories found")
4847

build_tools/i18n/fonts.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
For usage instructions, see:
33
https://kolibri-dev.readthedocs.io/en/develop/references/i18n.html
44
"""
5+
56
import argparse
67
import base64
78
import functools
@@ -32,9 +33,7 @@
3233
utils.install_requirement(f"fonttools=={font_tools_version}")
3334
except AssertionError:
3435
utils.install_requirement(f"fonttools=={font_tools_version}")
35-
logging.error(
36-
"Wrong fontTools version was installed. This has been updated. Please re-run the command."
37-
)
36+
logging.error("Wrong fontTools version was installed. This has been updated. Please re-run the command.")
3837
sys.exit(1)
3938

4039
import noto_source # noqa E402
@@ -328,9 +327,7 @@ def _full_font_face(font_family, font_name, weight, omit_glyphs=None):
328327
glyphs = _font_glyphs(hashed_path) - omit_glyphs
329328
if not glyphs:
330329
return ""
331-
return _gen_font_face(
332-
font_family, hashed_filename, weight, unicodes=_fmt_range(glyphs)
333-
)
330+
return _gen_font_face(font_family, hashed_filename, weight, unicodes=_fmt_range(glyphs))
334331

335332

336333
def _gen_full_css_modern(lang_info):
@@ -345,11 +342,7 @@ def _gen_full_css_modern(lang_info):
345342
font_faces = []
346343
for font_name in _font_priorities(lang_info[utils.KEY_DEFAULT_FONT]):
347344
for weight in noto_source.WEIGHTS:
348-
font_faces.append(
349-
_full_font_face(
350-
SCOPE_FULL, font_name, weight, omit_glyphs=previous_glyphs
351-
)
352-
)
345+
font_faces.append(_full_font_face(SCOPE_FULL, font_name, weight, omit_glyphs=previous_glyphs))
353346

354347
# Assumes all four variants have the same glyphs, from the content Regular font
355348
regular_path = _woff_font_path(_scoped(SCOPE_FULL, font_name), "Regular")
@@ -358,9 +351,7 @@ def _gen_full_css_modern(lang_info):
358351
hashed_path = os.path.join(OUTPUT_PATH, hashed_filename)
359352
previous_glyphs |= _font_glyphs(hashed_path)
360353

361-
original_filename = "{}.modern.css".format(
362-
_scoped(SCOPE_FULL, lang_info[utils.KEY_INTL_CODE])
363-
)
354+
original_filename = "{}.modern.css".format(_scoped(SCOPE_FULL, lang_info[utils.KEY_INTL_CODE]))
364355
temp_path = os.path.join(OUTPUT_PATH, original_filename + ".tmp")
365356

366357
# Write to temporary file
@@ -380,9 +371,7 @@ def _gen_full_css_modern(lang_info):
380371

381372

382373
def _gen_full_css_basic(lang_info):
383-
original_filename = "{}.basic.css".format(
384-
_scoped(SCOPE_FULL, lang_info[utils.KEY_INTL_CODE])
385-
)
374+
original_filename = "{}.basic.css".format(_scoped(SCOPE_FULL, lang_info[utils.KEY_INTL_CODE]))
386375
temp_path = os.path.join(OUTPUT_PATH, original_filename + ".tmp")
387376

388377
# Write to temporary file
@@ -493,9 +482,7 @@ def _write_inline_font(file_object, font_path, font_family, weight):
493482
"""
494483
with open(font_path, mode="rb") as f:
495484
data = f.read()
496-
data_uri = "data:application/x-font-woff;charset=utf-8;base64,\\\n{}".format(
497-
"\\\n".join(_chunks(base64.b64encode(data).decode()))
498-
)
485+
data_uri = "data:application/x-font-woff;charset=utf-8;base64,\\\n{}".format("\\\n".join(_chunks(base64.b64encode(data).decode())))
499486
glyphs = _font_glyphs(font_path)
500487
if not glyphs:
501488
return
@@ -658,7 +645,6 @@ def _subset_and_merge_fonts(text, default_font, scope):
658645
remaining_glyphs = set([ord(c) for c in text])
659646

660647
for font_name in _font_priorities(default_font):
661-
662648
if font_name in FONTS_TO_EXCLUDE_FROM_SUBSET:
663649
continue
664650

build_tools/i18n/generate_mapping.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Reads language_info.json and uses our copy of Django's locale utilities
55
to convert intl_code to locale format.
66
"""
7+
78
import json
89
import os
910

@@ -19,9 +20,7 @@ def get_language_mapping():
1920
"""
2021
# Get the path to language_info.json relative to this script
2122
script_dir = os.path.dirname(os.path.abspath(__file__))
22-
json_path = os.path.join(
23-
script_dir, "..", "..", "kolibri", "locale", "language_info.json"
24-
)
23+
json_path = os.path.join(script_dir, "..", "..", "kolibri", "locale", "language_info.json")
2524

2625
with open(json_path, "r", encoding="utf-8") as f:
2726
languages = json.load(f)

build_tools/i18n/noto_source.py

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,13 @@
7272
# filename and directory patterns
7373
HINTED_PATH_PATTERN = r"^fonts\/[^\/]+\/hinted\/ttf\/(NotoSans\w*)-\w*.ttf$"
7474

75-
VARIABLE_SLIM_LINE_PATTERN = (
76-
r"^fonts/[^/]+\/unhinted\/variable-ttf\/(NotoSans\w*)\[\w*\].ttf$"
77-
)
75+
VARIABLE_SLIM_LINE_PATTERN = r"^fonts/[^/]+\/unhinted\/variable-ttf\/(NotoSans\w*)\[\w*\].ttf$"
7876

79-
VARIABLE_PATTERN = (
80-
r"^fonts/[^/]+\/unhinted\/slim-variable-ttf\/(NotoSans\w*)\[\w*\].ttf$"
81-
)
77+
VARIABLE_PATTERN = r"^fonts/[^/]+\/unhinted\/slim-variable-ttf\/(NotoSans\w*)\[\w*\].ttf$"
8278

8379
WEIGHT_REGEXES = [re.compile(f"^(NotoSans\\w*)-{weight}\\.ttf$") for weight in WEIGHTS]
8480

85-
DOWNLOAD_URL = (
86-
"https://raw.githubusercontent.com/notofonts/notofonts.github.io/{ref}/{path}"
87-
)
81+
DOWNLOAD_URL = "https://raw.githubusercontent.com/notofonts/notofonts.github.io/{ref}/{path}"
8882

8983

9084
def _request(path):
@@ -118,11 +112,7 @@ def _is_base_font(name):
118112

119113
@functools.cache
120114
def _get_fixed_weight_fonts(recursive_tree):
121-
file_paths = [
122-
item["path"]
123-
for item in recursive_tree["tree"]
124-
if re.match(HINTED_PATH_PATTERN, item["path"])
125-
]
115+
file_paths = [item["path"] for item in recursive_tree["tree"] if re.match(HINTED_PATH_PATTERN, item["path"])]
126116

127117
# Accumulate dicts of github info objects for font weights
128118
fixed_weight_fonts = {}
@@ -163,22 +153,12 @@ def _get_all_typefaces(git_tree):
163153
variable_slim_fonts = _get_variable_slim_fonts(git_tree)
164154

165155
# these are the fonts that have all weight variants or variable fonts
166-
all_typefaces = (
167-
reduce(and_, (set(v) for v in fixed_weight_fonts.values()))
168-
| set(variable_fonts.keys())
169-
| set(variable_slim_fonts.keys())
170-
)
156+
all_typefaces = reduce(and_, (set(v) for v in fixed_weight_fonts.values())) | set(variable_fonts.keys()) | set(variable_slim_fonts.keys())
171157

172158
# remove UI variants as we will automatically pick these if available
173159
# also coerce to a list for dumping to JSON
174160

175-
return {
176-
font_name
177-
for font_name in all_typefaces
178-
if not font_name.endswith("UI")
179-
and font_name not in EXCLUDED_TYPEFACES
180-
and _is_base_font(font_name)
181-
}
161+
return {font_name for font_name in all_typefaces if not font_name.endswith("UI") and font_name not in EXCLUDED_TYPEFACES and _is_base_font(font_name)}
182162

183163

184164
def _font_info(recursive_tree, ref):
@@ -208,17 +188,11 @@ def _font_info(recursive_tree, ref):
208188
output[font_name] = {}
209189
for weight in WEIGHTS:
210190
if base_font_name in fixed_weight_fonts[weight]:
211-
output[font_name][weight] = DOWNLOAD_URL.format(
212-
ref=ref, path=fixed_weight_fonts[weight][base_font_name]
213-
)
191+
output[font_name][weight] = DOWNLOAD_URL.format(ref=ref, path=fixed_weight_fonts[weight][base_font_name])
214192
elif base_font_name in variable_slim_fonts:
215-
output[font_name]["Variable"] = DOWNLOAD_URL.format(
216-
ref=ref, path=variable_slim_fonts[base_font_name]
217-
)
193+
output[font_name]["Variable"] = DOWNLOAD_URL.format(ref=ref, path=variable_slim_fonts[base_font_name])
218194
elif base_font_name in variable_fonts:
219-
output[font_name]["Variable"] = DOWNLOAD_URL.format(
220-
ref=ref, path=variable_fonts[base_font_name]
221-
)
195+
output[font_name]["Variable"] = DOWNLOAD_URL.format(ref=ref, path=variable_fonts[base_font_name])
222196

223197
return output
224198

@@ -317,9 +291,7 @@ def fetch_fonts():
317291
for instance in font["fvar"].instances:
318292
name = font["name"].getDebugName(instance.subfamilyNameID)
319293
if name == weight:
320-
instancer.instantiateVariableFont(
321-
font, instance.coordinates, inplace=True
322-
)
294+
instancer.instantiateVariableFont(font, instance.coordinates, inplace=True)
323295
break
324296
else:
325297
# No named font, so set the weight specifically

0 commit comments

Comments
 (0)