Browse Source

Add explicit file encoding to `open` calls

Mads Møller Jensen 1 year ago
parent
commit
a951c12a6e
1 changed files with 4 additions and 4 deletions
  1. 4 4
      book/build.py

+ 4 - 4
book/build.py

@@ -15,14 +15,14 @@ def generate_example(
     print(path_out)
 
     code = []
-    with open(path_in, "r") as fin:
+    with open(path_in, "r", encoding="utf-8") as fin:
         for line in fin:
             if not (strip_asserts and "assert_eq" in line):
                 code.append(line)
 
     url = f"https://numbat.dev/?q={urllib.parse.quote_plus(''.join(code))}"
 
-    with open(path_out, "w") as fout:
+    with open(path_out, "w", encoding="utf-8") as fout:
         fout.write("<!-- This file is autogenerated! Do not modify it -->\n")
         fout.write("\n")
         fout.write(f"# {title}\n")
@@ -80,7 +80,7 @@ generate_example(
 )
 
 path_units = SCRIPT_DIR / "src" / "list-units.md"
-with open(path_units, "w") as f:
+with open(path_units, "w", encoding="utf-8") as f:
     print("Generating list of units...", flush=True)
     subprocess.run(
         ["cargo", "run", "--release", "--quiet", "--example=inspect", "units"],
@@ -91,7 +91,7 @@ with open(path_units, "w") as f:
 
 def list_of_functions(file_name, document):
     path = SCRIPT_DIR / "src" / f"list-functions-{file_name}.md"
-    with open(path, "w") as f:
+    with open(path, "w", encoding="utf-8") as f:
         print(f"# {document['title']}\n", file=f, flush=True)
 
         if introduction := document.get("introduction"):