Skip to content

Commit de10141

Browse files
Copilotbrunoborges
andcommitted
Fix Windows benchmark: add encoding='utf-8' to all open() calls in generators
Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
1 parent e89d382 commit de10141

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

.github/workflows/benchmark.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
OG_AOT="html-generators/generateog.aot"
4545
STEADY_RUNS=5
4646
47-
snippet_count=$(find content -name '*.json' | wc -l | tr -d ' ')
47+
snippet_count=$(find content \( -name '*.json' -o -name '*.yaml' -o -name '*.yml' \) -not -name 'template.*' | wc -l | tr -d ' ')
4848
java_ver=$(java -version 2>&1 | head -1 | sed 's/.*"\(.*\)".*/\1/')
4949
os_name="${{ matrix.os }}"
5050
@@ -232,7 +232,7 @@ jobs:
232232
run: |
233233
os_name="${{ matrix.os }}"
234234
java_ver=$(java -version 2>&1 | head -1 | sed 's/.*"\(.*\)".*/\1/')
235-
snippet_count=$(find content -name '*.json' | wc -l | tr -d ' ')
235+
snippet_count=$(find content \( -name '*.json' -o -name '*.yaml' -o -name '*.yml' \) -not -name 'template.*' | wc -l | tr -d ' ')
236236
237237
measure() {
238238
TIMEFORMAT='%R'

html-generators/generate.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
def _load_properties(path):
4141
"""Load a .properties file into an OrderedDict, preserving insertion order."""
4242
props = OrderedDict()
43-
with open(path) as f:
43+
with open(path, encoding="utf-8") as f:
4444
for line in f:
4545
line = line.strip()
4646
if not line or line.startswith("#"):
@@ -70,7 +70,7 @@ def _find_with_extensions(directory, base_name):
7070

7171
def _read_auto(path):
7272
"""Read a JSON or YAML file based on its extension."""
73-
with open(path) as f:
73+
with open(path, encoding="utf-8") as f:
7474
if path.endswith(".yaml") or path.endswith(".yml"):
7575
return yaml.safe_load(f)
7676
return json.load(f)
@@ -604,7 +604,7 @@ def build_locale(locale, templates, all_snippets):
604604
out_dir = os.path.join(SITE_DIR, locale, snippet["category"])
605605
os.makedirs(out_dir, exist_ok=True)
606606
out_path = os.path.join(out_dir, f"{snippet['slug']}.html")
607-
with open(out_path, "w", newline="") as f:
607+
with open(out_path, "w", newline="", encoding="utf-8") as f:
608608
f.write(html_content)
609609

610610
print(f"Generated {len(all_snippets)} HTML files for {locale}")
@@ -622,7 +622,7 @@ def build_locale(locale, templates, all_snippets):
622622
else os.path.join(SITE_DIR, locale, "data")
623623
)
624624
os.makedirs(data_dir, exist_ok=True)
625-
with open(os.path.join(data_dir, "snippets.json"), "w") as f:
625+
with open(os.path.join(data_dir, "snippets.json"), "w", encoding="utf-8") as f:
626626
json.dump(snippets_list, f, indent=2, ensure_ascii=False)
627627
f.write("\n")
628628
print(f"Rebuilt data/snippets.json for {locale} with {len(snippets_list)} entries")
@@ -655,7 +655,7 @@ def build_locale(locale, templates, all_snippets):
655655
index_dir = os.path.join(SITE_DIR, locale)
656656
os.makedirs(index_dir, exist_ok=True)
657657
index_path = os.path.join(index_dir, "index.html")
658-
with open(index_path, "w") as f:
658+
with open(index_path, "w", encoding="utf-8") as f:
659659
f.write(index_html)
660660
print(f"Generated index.html for {locale} with {len(all_snippets)} cards")
661661

@@ -667,7 +667,7 @@ def build_locale(locale, templates, all_snippets):
667667
def load_templates():
668668
"""Load all HTML templates."""
669669
def _read(path):
670-
with open(path) as f:
670+
with open(path, encoding="utf-8") as f:
671671
return f.read()
672672
return {
673673
"page": _read("templates/slug-template.html"),

html-generators/generateog.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898

9999
def load_properties(path):
100100
props = OrderedDict()
101-
with open(path) as f:
101+
with open(path, encoding="utf-8") as f:
102102
for line in f:
103103
line = line.strip()
104104
if not line or line.startswith("#"):
@@ -113,7 +113,7 @@ def load_properties(path):
113113

114114

115115
def read_auto(path):
116-
with open(path) as f:
116+
with open(path, encoding="utf-8") as f:
117117
if path.endswith((".yaml", ".yml")):
118118
if yaml is None:
119119
raise ImportError("PyYAML is required for YAML files: pip install pyyaml")
@@ -320,7 +320,7 @@ def main():
320320

321321
svg = generate_svg(data)
322322
svg_path = os.path.join(out_dir, f"{slug}.svg")
323-
with open(svg_path, "w") as f:
323+
with open(svg_path, "w", encoding="utf-8") as f:
324324
f.write(svg)
325325

326326
png_path = os.path.join(out_dir, f"{slug}.png")

0 commit comments

Comments
 (0)