diff --git a/tools/asm_sizes.py b/tools/asm_sizes.py index 05dad64aece..21809e5ed60 100755 --- a/tools/asm_sizes.py +++ b/tools/asm_sizes.py @@ -20,7 +20,7 @@ # Calculate the number of instructions in a .s file def calc_insns(f_path): ret = 0 - with open(f_path) as f: + with open(f_path, "r", encoding="utf-8") as f: f_lines = f.readlines() for line in f_lines: if line.startswith("/* "): diff --git a/tools/build/actor_types.py b/tools/build/actor_types.py index 2a9b500f043..01fa3db33a7 100644 --- a/tools/build/actor_types.py +++ b/tools/build/actor_types.py @@ -44,7 +44,7 @@ def __init__(self, entry): def read_actors_yaml(in_yaml: Path) -> List[ActorTypeEntry]: actors: List[ActorTypeEntry] = [] - with open(in_yaml) as f: + with open(in_yaml, "r", encoding="utf-8") as f: entry_list = yaml.load(f.read(), Loader=yaml.SafeLoader) for entry in entry_list: @@ -129,7 +129,7 @@ def generate_actors_enums(fout: TextIOWrapper, actors: List[ActorTypeEntry]): actors = read_actors_yaml(args.actors_yaml) - with open(args.out_data, "w") as fout: + with open(args.out_data, "w", encoding="utf-8") as fout: fout.write("/* This file is auto-generated. Do not edit. */\n") fout.write('#include "common.h"\n') fout.write('#include "message_ids.h"\n') @@ -137,7 +137,7 @@ def generate_actors_enums(fout: TextIOWrapper, actors: List[ActorTypeEntry]): generate_actors_data(fout, actors) - with open(args.out_enum, "w") as fout: + with open(args.out_enum, "w", encoding="utf-8") as fout: fout.write("/* This file is auto-generated. Do not edit. */\n") fout.write("\n") diff --git a/tools/build/audio/sbn.py b/tools/build/audio/sbn.py index af483498415..03c8a70fd41 100644 --- a/tools/build/audio/sbn.py +++ b/tools/build/audio/sbn.py @@ -32,7 +32,7 @@ def get_id(item): def from_yaml(yaml_path: Path, asset_stack: Tuple[Path, ...]) -> SBN: sbn = SBN() - with yaml_path.open("r") as f: + with yaml_path.open("r", encoding="utf-8") as f: config = yaml.safe_load(f) unknown_bin_path = get_asset_path("audio/unknown.bin", asset_stack) diff --git a/tools/build/effects.py b/tools/build/effects.py index 9705280c90f..c864e34f607 100644 --- a/tools/build/effects.py +++ b/tools/build/effects.py @@ -38,11 +38,11 @@ args.out_dir.mkdir(parents=True, exist_ok=True) - with open(args.out_dir / "effect_macros.h", "w") as f: + with open(args.out_dir / "effect_macros.h", "w", encoding="utf-8") as f: f.write(macro_defs) - with open(args.out_dir / "effect_table.c", "w") as f: + with open(args.out_dir / "effect_table.c", "w", encoding="utf-8") as f: f.write(main_decls_text + "\n" + effect_table_text + "};\n") - with open(args.out_dir / "effect_defs.h", "w") as f: + with open(args.out_dir / "effect_defs.h", "w", encoding="utf-8") as f: f.write(effect_enum_text + "};\n\n" + fx_decls_text) diff --git a/tools/build/genobjcopy.py b/tools/build/genobjcopy.py index e70b0671eb0..714c0029cbe 100755 --- a/tools/build/genobjcopy.py +++ b/tools/build/genobjcopy.py @@ -14,10 +14,10 @@ infile, outfile = sys.argv[1:] # generate output based on input - file_data = open(infile, "r").read().split("\n") + file_data = open(infile, "r", encoding="utf-8").read().split("\n") if len(file_data[-1]) == 0: file_data.pop() outdata = "-j " + " -j ".join(file_data) - with open(outfile, "w") as f: + with open(outfile, "w", encoding="utf-8") as f: f.write(outdata) diff --git a/tools/build/icons.py b/tools/build/icons.py index ccc69ea0ca5..33b037f98a7 100644 --- a/tools/build/icons.py +++ b/tools/build/icons.py @@ -86,7 +86,7 @@ def build(out_bin: Path, out_header: Path, asset_stack: Tuple[Path, ...]): with open(out_bin, "wb") as f: f.write(out_bytes) - with open(out_header, "w") as f: + with open(out_header, "w", encoding="utf-8") as f: f.write("#ifndef ICON_OFFSETS_H\n") f.write("#define ICON_OFFSETS_H\n") f.write(f"/* This file is auto-generated. Do not edit. */\n\n") diff --git a/tools/build/img/header.py b/tools/build/img/header.py index 875d4cbf525..3d772f70bc0 100755 --- a/tools/build/img/header.py +++ b/tools/build/img/header.py @@ -23,7 +23,7 @@ img = png.Reader(infile) width, height, rows, info = img.read() - with open(outfile, "w") as f: + with open(outfile, "w", encoding="utf-8") as f: f.write("// Generated file, do not edit.\n") f.write(f"#ifndef _{cname.upper()}_\n") f.write(f"#define _{cname.upper()}_\n") diff --git a/tools/build/imgfx/imgfx_data.py b/tools/build/imgfx/imgfx_data.py index 9056ba1bb18..67229d2cdb6 100755 --- a/tools/build/imgfx/imgfx_data.py +++ b/tools/build/imgfx/imgfx_data.py @@ -94,14 +94,14 @@ def fromJSON(name: str, data: Any) -> "Anim": def build(inputs: List[Path], output: Path): - with open(output, "w") as f: + with open(output, "w", encoding="utf-8") as f: f.write("/* NOTE: This file is autogenerated, do not edit */\n\n") f.write('#include "PR/gbi.h"\n') f.write('#include "macros.h"\n') f.write('#include "imgfx.h"\n\n') for input in inputs: - with open(input, "r") as fin: + with open(input, "r", encoding="utf-8") as fin: in_json = json.load(fin) anim = Anim.fromJSON(input.name[:-5], in_json) diff --git a/tools/build/item_data.py b/tools/build/item_data.py index 40cc6291b39..c6caccb6d8e 100644 --- a/tools/build/item_data.py +++ b/tools/build/item_data.py @@ -35,7 +35,7 @@ def __init__(self, entry): def read_items_yaml(in_yaml: Path) -> List[ItemEntry]: items: List[ItemEntry] = [] - with open(in_yaml) as f: + with open(in_yaml, "r", encoding="utf-8") as f: entry_list = yaml.load(f.read(), Loader=yaml.SafeLoader) for entry in entry_list: @@ -309,7 +309,7 @@ def generate_item_icon_tables(fout: TextIOWrapper, items: List[ItemEntry]): } items.sort(key=lambda x: CATEGORY_ORDER.get(x.category, 999)) - with open(args.out_data, "w") as fout: + with open(args.out_data, "w", encoding="utf-8") as fout: fout.write("/* This file is auto-generated. Do not edit. */\n") fout.write('#include "common.h"\n') fout.write('#include "message_ids.h"\n') @@ -334,7 +334,7 @@ def generate_item_icon_tables(fout: TextIOWrapper, items: List[ItemEntry]): generate_item_entity_scripts_table(fout, items) generate_item_icon_tables(fout, items) - with open(args.out_enum, "w") as fout: + with open(args.out_enum, "w", encoding="utf-8") as fout: fout.write("/* This file is auto-generated. Do not edit. */\n") fout.write("\n") diff --git a/tools/build/mapfs/shape.py b/tools/build/mapfs/shape.py index a2ee8ddff6a..ccbc64be01b 100755 --- a/tools/build/mapfs/shape.py +++ b/tools/build/mapfs/shape.py @@ -646,7 +646,7 @@ def run(in_bin: Path, out: Path) -> None: shape = ShapeFile(map_name, file_bytes) shape.digest() - with open(out, "w") as out_file: + with open(out, "w", encoding="utf-8") as out_file: shape.write_to_c(out_file) diff --git a/tools/build/mapfs/tex.py b/tools/build/mapfs/tex.py index de7b961f67e..642bbb5d410 100644 --- a/tools/build/mapfs/tex.py +++ b/tools/build/mapfs/tex.py @@ -150,7 +150,7 @@ def build(out_path: Path, tex_name: str, asset_stack: Tuple[Path, ...], endian: json_path = get_asset_path(Path(f"mapfs/tex/{tex_name}.json"), asset_stack) - with open(json_path) as json_file: + with open(json_path, "r", encoding="utf-8") as json_file: json_str = json_file.read() json_data = json.loads(json_str) diff --git a/tools/build/move_data.py b/tools/build/move_data.py index d1cae9ed255..b8525f0405d 100644 --- a/tools/build/move_data.py +++ b/tools/build/move_data.py @@ -31,7 +31,7 @@ def __init__(self, entry): def read_moves_yaml(in_yaml: Path) -> List[MoveEntry]: items: List[MoveEntry] = [] - with open(in_yaml) as f: + with open(in_yaml, "r", encoding="utf-8") as f: entry_list = yaml.load(f.read(), Loader=yaml.SafeLoader) for entry in entry_list: @@ -98,7 +98,7 @@ def generate_move_enum(fout: TextIOWrapper, moves: List[MoveEntry]): moves = read_moves_yaml(args.moves_yaml) - with open(args.out_data, "w") as fout: + with open(args.out_data, "w", encoding="utf-8") as fout: fout.write("/* This file is auto-generated. Do not edit. */\n") fout.write('#include "common.h"\n') fout.write('#include "message_ids.h"\n') @@ -106,7 +106,7 @@ def generate_move_enum(fout: TextIOWrapper, moves: List[MoveEntry]): generate_move_table(fout, moves) - with open(args.out_enum, "w") as fout: + with open(args.out_enum, "w", encoding="utf-8") as fout: fout.write("/* This file is auto-generated. Do not edit. */\n") fout.write("\n") diff --git a/tools/build/msg/combine.py b/tools/build/msg/combine.py index fb04c44cef0..71b4c30d950 100755 --- a/tools/build/msg/combine.py +++ b/tools/build/msg/combine.py @@ -111,7 +111,7 @@ def __init__(self, d: dict, header_file_index: int): f.write(b"\0\0\0\0") if header_file is not None: - with open(header_file, "w") as f: + with open(header_file, "w", encoding="utf-8") as f: f.write(f"#ifndef _MESSAGE_IDS_H_\n" f"#define _MESSAGE_IDS_H_\n" "\n" '#include "messages.h"\n' "\n") for message in messages: diff --git a/tools/build/msg/parse_compile.py b/tools/build/msg/parse_compile.py index b07de7a12a0..2068ef9f7f0 100755 --- a/tools/build/msg/parse_compile.py +++ b/tools/build/msg/parse_compile.py @@ -3173,7 +3173,7 @@ def replacer(match): messages = [] message = None - with open(filename, "r") as f: + with open(filename, "r", encoding="utf-8") as f: source = strip_c_comments(f.read()) lineno = 1 @@ -4452,7 +4452,7 @@ def replacer(match): exit(1) if is_output_format_c: - with open(outfile, "w") as f: + with open(outfile, "w", encoding="utf-8") as f: f.write(f"#include \n") for message in messages: diff --git a/tools/build/recipes.py b/tools/build/recipes.py index f709a5ea6c7..ccc22689bc4 100644 --- a/tools/build/recipes.py +++ b/tools/build/recipes.py @@ -25,7 +25,7 @@ def __init__(self, entry: List[str], order: Dict[str, int]): def generate(in_yaml: Path, out_c: Path): - with open(in_yaml) as f: + with open(in_yaml, "r", encoding="utf-8") as f: data = yaml.load(f.read(), Loader=yaml.SafeLoader) products = data["Products"] @@ -69,7 +69,7 @@ def generate(in_yaml: Path, out_c: Path): # if not recipe[2] in product_idx: # raise Exception(f"Product {recipe[2]} for ExtraDoubleRecipe ({recipe[0]}, {recipe[1]}) not listed in Products") - with open(out_c, "w") as f: + with open(out_c, "w", encoding="utf-8") as f: f.write("/* This file is auto-generated. Do not edit. */\n\n") f.write('#include "common.h"\n\n') diff --git a/tools/build/sprite/header.py b/tools/build/sprite/header.py index cb4b9d4c789..d714efbaf73 100755 --- a/tools/build/sprite/header.py +++ b/tools/build/sprite/header.py @@ -16,7 +16,7 @@ asset_stack = tuple(Path(d) for d in asset_stack_raw.split(",")) - with open(outfile, "w") as f: + with open(outfile, "w", encoding="utf-8") as f: # get sprite index s = int(s_in) assert s >= 1 diff --git a/tools/build/sprite/sprite_shading_profiles.py b/tools/build/sprite/sprite_shading_profiles.py index 3c5aee2c5c9..9b73d5df4b4 100755 --- a/tools/build/sprite/sprite_shading_profiles.py +++ b/tools/build/sprite/sprite_shading_profiles.py @@ -95,13 +95,13 @@ def build( ): END = ">" if endian == "big" else "<" - with open(input, "r") as f: + with open(input, "r", encoding="utf-8") as f: json_data = json.load(f) groups = groups_from_json(json_data) # Header creation - with open(header_out, "w") as f: + with open(header_out, "w", encoding="utf-8") as f: f.write("#ifndef SHADING_PROFILES_H\n") f.write("#define SHADING_PROFILES_H\n") f.write(f"/* This file is auto-generated from {input.name}. Do not edit. */\n\n") diff --git a/tools/build/sprite/sprites.py b/tools/build/sprite/sprites.py index 6cc5f59f0c6..f70359f6c42 100755 --- a/tools/build/sprite/sprites.py +++ b/tools/build/sprite/sprites.py @@ -418,7 +418,7 @@ def write_player_sprite_header( sprite_id += 1 out_file.parent.mkdir(exist_ok=True, parents=True) - with open(out_file, "w") as f: + with open(out_file, "w", encoding="utf-8") as f: f.write(f"#ifndef {ifdef_name}\n") f.write(f"#define {ifdef_name}\n\n") diff --git a/tools/build/world_map.py b/tools/build/world_map.py index 0024e75ffcc..21f1acf44a1 100644 --- a/tools/build/world_map.py +++ b/tools/build/world_map.py @@ -32,7 +32,7 @@ def generate(in_xml: Path, out_c: Path): xml = ET.parse(in_xml) ScriptList = xml.getroot() - with open(out_c, "w") as f: + with open(out_c, "w", encoding="utf-8") as f: f.write("#ifndef WORLD_MAP_H\n") f.write("#define WORLD_MAP_H\n") f.write("/* This file is auto-generated. Do not edit. */\n\n") diff --git a/tools/configure/src/configure/main.py b/tools/configure/src/configure/main.py index b652a180c2c..5ab8a0c8018 100755 --- a/tools/configure/src/configure/main.py +++ b/tools/configure/src/configure/main.py @@ -1461,7 +1461,7 @@ def main(): # add tools/build to import path sys.path.insert(0, str(BUILD_TOOLS.resolve())) - ninja = ninja_syntax.Writer(open(str(ROOT / "build.ninja"), "w"), width=9999) + ninja = ninja_syntax.Writer(open(str(ROOT / "build.ninja"), "w", encoding="utf-8"), width=9999) non_matching = args.non_matching or args.modern_gcc or args.shift diff --git a/tools/disasm_hud_element_animation.py b/tools/disasm_hud_element_animation.py index 25abef28f60..340dd50f802 100755 --- a/tools/disasm_hud_element_animation.py +++ b/tools/disasm_hud_element_animation.py @@ -151,7 +151,7 @@ def print(self): args = parser.parse_args() - with open(args.file, "r") as f: + with open(args.file, "r", encoding="utf-8") as f: lines = f.readlines() current_script = None diff --git a/tools/disasm_script.py b/tools/disasm_script.py index ba4ae36fe86..3463518c906 100755 --- a/tools/disasm_script.py +++ b/tools/disasm_script.py @@ -21,7 +21,7 @@ def script_lib(offset=0): LIB_LINE_RE = re.compile(r"\s+:\s+") NAME_RE = re.compile(r"({[^}]*})?\s*([a-zA-Z0-9_]+)") for filename in Path(path.dirname(__file__), "star-rod", "database").rglob("*.lib"): - with open(filename, "r") as file: + with open(filename, "r", encoding="utf-8") as file: for line in file.readlines(): parts = LIB_LINE_RE.split(line) if len(parts) >= 3: @@ -37,7 +37,7 @@ def script_lib(offset=0): repo_root = Path(__file__).resolve().parent.parent symbols = Path(repo_root / "ver" / "current" / "symbol_addrs.txt") - with open(symbols, "r") as file: + with open(symbols, "r", encoding="utf-8") as file: for line in file.readlines(): s = [s.strip() for s in line.split("=", 1)] name = s[0] diff --git a/tools/find_duplicates.py b/tools/find_duplicates.py index 46d75f98f05..55a2cf956c8 100755 --- a/tools/find_duplicates.py +++ b/tools/find_duplicates.py @@ -68,7 +68,7 @@ def parse_map(fname): syms = {} prev_sym = None prev_line = "" - with open(fname) as f: + with open(fname, "r", encoding="utf-8") as f: for line in f: if "load address" in line: if "noload" in line or "noload" in prev_line: @@ -246,26 +246,23 @@ def output_match_dict( num_perfect_dupes, num_checked_files, ): - out_file = open(datetime.today().strftime("%Y-%m-%d-%H-%M-%S") + "_all_matches.txt", "w+") - - out_file.write( - "Number of s-files: " + str(len(s_files)) + "\n" - "Number of checked s-files: " + str(round(num_checked_files)) + "\n" - "Number of decompiled duplicates found: " + str(num_decomped_dupes) + "\n" - "Number of undecompiled duplicates found: " + str(num_undecomped_dupes) + "\n" - "Number of overall exact duplicates found: " + str(num_perfect_dupes) + "\n\n" - ) - - sorted_dict = OrderedDict(sorted(match_dict.items(), key=lambda item: item[1][0], reverse=True)) - - print("Creating output file: " + out_file.name, end="\n") - for file_name, matches in sorted_dict.items(): - out_file.write(file_name + " - found " + str(matches[0]) + " matches total:\n") - for match in matches[1]: - out_file.write(match + "\n") - out_file.write("\n") - - out_file.close() + with open(datetime.today().strftime("%Y-%m-%d-%H-%M-%S") + "_all_matches.txt", "w+", encoding="utf-8") as out_file: + out_file.write( + "Number of s-files: " + str(len(s_files)) + "\n" + "Number of checked s-files: " + str(round(num_checked_files)) + "\n" + "Number of decompiled duplicates found: " + str(num_decomped_dupes) + "\n" + "Number of undecompiled duplicates found: " + str(num_undecomped_dupes) + "\n" + "Number of overall exact duplicates found: " + str(num_perfect_dupes) + "\n\n" + ) + + sorted_dict = OrderedDict(sorted(match_dict.items(), key=lambda item: item[1][0], reverse=True)) + + print("Creating output file: " + out_file.name, end="\n") + for file_name, matches in sorted_dict.items(): + out_file.write(file_name + " - found " + str(matches[0]) + " matches total:\n") + for match in matches[1]: + out_file.write(match + "\n") + out_file.write("\n") def is_decompiled(sym): diff --git a/tools/fix_sprite_xmls.py b/tools/fix_sprite_xmls.py index c3a2f4d7f38..b57d3f2fdb5 100644 --- a/tools/fix_sprite_xmls.py +++ b/tools/fix_sprite_xmls.py @@ -6,7 +6,7 @@ def process_file(file_path): - with open(file_path, "r") as file: + with open(file_path, "r", encoding="utf-8") as file: content = file.read() # Skip files that already have fixed="true" @@ -35,7 +35,7 @@ def process_file(file_path): r'', lambda m: f'', content ) - with open(file_path, "w") as file: + with open(file_path, "w", encoding="utf-8") as file: file.write(content) print(f"Updated: {file_path}") diff --git a/tools/migrate_data_to_c.py b/tools/migrate_data_to_c.py index 42e0485334f..011d899252f 100755 --- a/tools/migrate_data_to_c.py +++ b/tools/migrate_data_to_c.py @@ -16,8 +16,8 @@ def find_dir(query): def data_to_c(file_path): - file = open(file_path) - s = file.read() + with open(file_path, "r", encoding="utf-8") as f: + s = f.read() output = "" pattern = re.compile(r"(dlabel (jtbl_.*|.+_.*)\n.(\w+) (.*))") @@ -33,7 +33,6 @@ def data_to_c(file_path): else: output += all + "\n\n" - file.close() return output @@ -43,9 +42,8 @@ def out_to_file(output, file_path): os.mkdir(output_dir) file_name = file_path[file_path.rfind("/") : -7] - file = open("data2c/" + file_name + ".c", "w+") - file.write(output) - file.close() + with open("data2c/" + file_name + ".c", "w+", encoding="utf-8") as file: + file.write(output) def get_all(): diff --git a/tools/mv_segment.py b/tools/mv_segment.py index b73f9fe5565..d5839081c64 100755 --- a/tools/mv_segment.py +++ b/tools/mv_segment.py @@ -18,10 +18,10 @@ print("moving c file") os.rename(f"src/{args.src}.c", f"src/{args.dest}.c") - with open(f"src/{args.dest}.c") as f: + with open(f"src/{args.dest}.c", "r", encoding="utf-8") as f: content = f.read() - with open(f"src/{args.dest}.c", "w") as f: + with open(f"src/{args.dest}.c", "w", encoding="utf-8") as f: f.write(content.replace(f'"{args.src}"', f'"{args.dest}"')) if os.path.exists(f"ver/current/asm/nonmatchings/{args.src}"): diff --git a/tools/old/asset_rework.py b/tools/old/asset_rework.py index 4d407803177..e3d41748784 100644 --- a/tools/old/asset_rework.py +++ b/tools/old/asset_rework.py @@ -14,7 +14,7 @@ def img_replacer(match): for version in ["us", "pal", "ique", "jp"]: try: - with open(f"ver/{version}/build/include/" + png_inc_c_path, "r") as f: + with open(f"ver/{version}/build/include/" + png_inc_c_path, "r", encoding="utf-8") as f: png_inc_c_content = f.read() break except FileNotFoundError: @@ -35,7 +35,7 @@ def img_replacer(match): for dirs, subdirs, files in os.walk("src"): for file in files: if file.endswith(".c"): - with open(os.path.join(dirs, file), "r") as f: + with open(os.path.join(dirs, file), "r", encoding="utf-8") as f: source_lines = f.readlines() if any(IMG_C_RE.match(l) or PAL_C_RE.match(l) for l in source_lines): @@ -59,5 +59,5 @@ def img_replacer(match): source_lines[i] = re.sub(IMG_C_RE, img_replacer, source_lines[i]) source_lines[i] = re.sub(PAL_C_RE, img_replacer, source_lines[i]) - with open(os.path.join(dirs, file), "w") as f: + with open(os.path.join(dirs, file), "w", encoding="utf-8") as f: f.writelines(source_lines) diff --git a/tools/old/bootstrap_effects.py b/tools/old/bootstrap_effects.py index c591461d6c7..58be324ad1a 100755 --- a/tools/old/bootstrap_effects.py +++ b/tools/old/bootstrap_effects.py @@ -20,7 +20,7 @@ effect_num = f_name.split("_")[1] - with open(f_path) as f: + with open(f_path, "r", encoding="utf-8") as f: asm_text = f.read() funcs = [] @@ -37,5 +37,5 @@ renames.append(f"{funcs[0]} fx_{effect_num}_appendGfx\n") -with open("tools/to_rename.txt", "w", newline="\n") as f: +with open("tools/to_rename.txt", "w", newline="\n", encoding="utf-8") as f: f.writelines(renames) diff --git a/tools/old/create_renames.py b/tools/old/create_renames.py index 4811d4662be..d52d8752148 100644 --- a/tools/old/create_renames.py +++ b/tools/old/create_renames.py @@ -1,4 +1,4 @@ -with open("errs.txt") as f: +with open("errs.txt", "r", encoding="utf-8") as f: inlines = f.readlines() renames = {} @@ -25,11 +25,11 @@ for k, v in sorted(renames.items()): pairs.append((k, v)) -with open("bloop.txt") as f: +with open("bloop.txt", "r", encoding="utf-8") as f: blooplines = f.readlines() -with open("duplicate_renames.txt", "w", newline="\n") as f: +with open("duplicate_renames.txt", "w", newline="\n", encoding="utf-8") as f: for pair in pairs: first = pair[0] second = pair[1] diff --git a/tools/old/fix_bad_evt_changes.py b/tools/old/fix_bad_evt_changes.py index e2ce853113d..ffa0265e6a2 100644 --- a/tools/old/fix_bad_evt_changes.py +++ b/tools/old/fix_bad_evt_changes.py @@ -19,7 +19,7 @@ old_line = old_lines[line_number - 1].strip() - with open(filename, "r") as f: + with open(filename, "r", encoding="utf-8") as f: lines = f.readlines() line = lines[line_number - 1] @@ -36,5 +36,5 @@ lines[line_number - 1] = line.replace(bad_symbol_name, good_symbol_name) - with open(filename, "w") as f: + with open(filename, "w", encoding="utf-8") as f: f.writelines(lines) diff --git a/tools/old/fix_s_filenames.py b/tools/old/fix_s_filenames.py index 4fd73c460b4..c1b6e46f584 100755 --- a/tools/old/fix_s_filenames.py +++ b/tools/old/fix_s_filenames.py @@ -15,7 +15,7 @@ if f_name.endswith(".s"): f_path = os.path.join(root, f_name) - with open(f_path, "r") as f: + with open(f_path, "r", encoding="utf-8") as f: line = f.readlines()[3] if not line.startswith("glabel "): diff --git a/tools/old/gen_effect_renames.py b/tools/old/gen_effect_renames.py index 2e30139752e..6691f341c82 100755 --- a/tools/old/gen_effect_renames.py +++ b/tools/old/gen_effect_renames.py @@ -44,7 +44,7 @@ def main(args): to_write.append(f"fx_{id}_appendGfx {to}_appendGfx") to_write.append(f"EFFECT_ID_{hex_str} EFFECT_{to.upper()}") - with open(os.path.join(script_dir, "to_rename.txt"), "a") as f: + with open(os.path.join(script_dir, "to_rename.txt"), "a", encoding="utf-8") as f: for line in to_write: f.write(f"{line}\n") diff --git a/tools/old/m_map_funcs.py b/tools/old/m_map_funcs.py index 755fb588d6e..5bf381baa9e 100755 --- a/tools/old/m_map_funcs.py +++ b/tools/old/m_map_funcs.py @@ -21,11 +21,11 @@ for fname in files: if fname.endswith(".s"): prefix = Path(root).parent.name + "_" - with open(os.path.join(root, fname)) as f: + with open(os.path.join(root, fname), "r", encoding="utf-8") as f: orig_text = f.read() new_text = orig_text for common in common_files: new_text = new_text.replace(" " + common, " " + prefix + common) if new_text != orig_text: - with open(os.path.join(root, fname), "w", newline="\n") as f: + with open(os.path.join(root, fname), "w", newline="\n", encoding="utf-8") as f: f.write(new_text) diff --git a/tools/old/migrate_effect_rodata.py b/tools/old/migrate_effect_rodata.py index 07ffb0b17aa..e2176354407 100755 --- a/tools/old/migrate_effect_rodata.py +++ b/tools/old/migrate_effect_rodata.py @@ -97,7 +97,7 @@ def handle_symbol(effect, symbol): if f_name.endswith(".s"): f_path = os.path.join(root, f_name) - with open(f_path) as f: + with open(f_path, "r", encoding="utf-8") as f: asm_lines = f.readlines() has_rodata_section = False @@ -115,7 +115,7 @@ def handle_symbol(effect, symbol): asm_lines.insert(6, f"{symbol[2]}\n") asm_lines.insert(7, "\n") - with open(f_path, "w", newline="\n") as f: + with open(f_path, "w", newline="\n", encoding="utf-8") as f: f.write("".join(asm_lines)) return True @@ -123,7 +123,7 @@ def handle_symbol(effect, symbol): def handle_file(f_path): - with open(f_path) as f: + with open(f_path, "r", encoding="utf-8") as f: rodata_lines = f.readlines()[4:] effect = f_path.split("/")[-1].split(".")[0] diff --git a/tools/old/migrate_exit_strings.py b/tools/old/migrate_exit_strings.py index 93ae109d0a8..96173b51996 100755 --- a/tools/old/migrate_exit_strings.py +++ b/tools/old/migrate_exit_strings.py @@ -13,7 +13,7 @@ asm_data_dir = asm_dir + "data/" src_dir = root_dir + "src/" -with open(root_dir + "ver/current/splat.yaml") as f: +with open(root_dir + "ver/current/splat.yaml", "r", encoding="utf-8") as f: config = yaml.load(f.read(), Loader=yaml.SafeLoader) for segment in config["segments"]: @@ -23,7 +23,7 @@ if not os.path.exists(c_file_path): continue - with open(c_file_path) as f: + with open(c_file_path, "r", encoding="utf-8") as f: c_lines = f.readlines() if len(c_lines[1].strip()) != 0: @@ -42,7 +42,7 @@ if not os.path.exists(asm_file_path): continue - with open(asm_file_path) as f: + with open(asm_file_path, "r", encoding="utf-8") as f: asm_lines = f.readlines() exit_data = asm_lines[5].strip() @@ -62,5 +62,5 @@ c_lines.insert(2 + i, f'static char* N(exit_str_{i}) = "{exit_strings[i]}";\n') c_lines.insert(2 + len(exit_strings), "\n") - with open(c_file_path, "w", newline="\n") as f: + with open(c_file_path, "w", newline="\n", encoding="utf-8") as f: f.write("".join(c_lines)) diff --git a/tools/old/migrate_rodata.py b/tools/old/migrate_rodata.py index 1eb60364f27..2580d590775 100755 --- a/tools/old/migrate_rodata.py +++ b/tools/old/migrate_rodata.py @@ -16,7 +16,7 @@ def handle_symbol(area, symbol): if f_name.endswith(".s"): f_path = os.path.join(root, f_name) - with open(f_path) as f: + with open(f_path, "r", encoding="utf-8") as f: asm_lines = f.readlines() has_rodata_section = False @@ -34,7 +34,7 @@ def handle_symbol(area, symbol): asm_lines.insert(6, f"{symbol[2]}\n") asm_lines.insert(7, "\n") - with open(f_path, "w", newline="\n") as f: + with open(f_path, "w", newline="\n", encoding="utf-8") as f: f.write("".join(asm_lines)) return True @@ -42,7 +42,7 @@ def handle_symbol(area, symbol): def handle_file(f_path): - with open(f_path) as f: + with open(f_path, "r", encoding="utf-8") as f: rodata_lines = f.readlines()[4:] area = Path(f_path).parent.parts[-2:] diff --git a/tools/old/sortsymz.py b/tools/old/sortsymz.py index 000ae6c500b..6e5a438ee70 100755 --- a/tools/old/sortsymz.py +++ b/tools/old/sortsymz.py @@ -20,7 +20,7 @@ for root, dirs, files in os.walk("src"): for file in files: if file.endswith(".c") and "bss" not in file: - with open(os.path.join(root, file)) as f: + with open(os.path.join(root, file), "r", encoding="utf-8") as f: text = f.read() for sym in syms: if sym["name"] in text: @@ -30,7 +30,7 @@ for root, dirs, files in os.walk("ver/us/asm"): for file in files: if file.endswith(".s"): - with open(os.path.join(root, file)) as f: + with open(os.path.join(root, file), "r", encoding="utf-8") as f: text = f.read() for sym in syms: if sym["name"] in text: diff --git a/tools/old/substitute.py b/tools/old/substitute.py index 7251b5963d9..64818465de8 100755 --- a/tools/old/substitute.py +++ b/tools/old/substitute.py @@ -21,7 +21,7 @@ from_funcs = [] -with open(args.from_list) as f: +with open(args.from_list, "r", encoding="utf-8") as f: from_text = f.readlines() to_line = """ @@ -46,7 +46,7 @@ for f_name in files: if f_name.endswith(".c"): f_path = os.path.join(root, f_name) - with open(f_path) as f: + with open(f_path, "r", encoding="utf-8") as f: f_text_orig = f.read() f_text = f_text_orig @@ -54,7 +54,7 @@ search_pattern = re.compile("\n.*" + func + "\).*\n") f_text = re.sub(search_pattern, to_line, f_text) if f_text != f_text_orig: - with open(f_path, "w", newline="\n") as f: + with open(f_path, "w", newline="\n", encoding="utf-8") as f: f.write(f_text) # # Rename symbols in from_funcs to namespace equivalents @@ -66,7 +66,7 @@ for f_name in files: if f_name.endswith(".s"): f_path = os.path.join(root, f_name) - with open(f_path) as f: + with open(f_path, "r", encoding="utf-8") as f: f_text_orig = f.read() f_text = f_text_orig @@ -89,8 +89,8 @@ to_replace.append(syms[0] + " " + namespace + "_ItemChoice_HasSelectedItem\n") to_replace.append(syms[1] + " " + namespace + "_ItemChoice_SelectedItemID\n") - with open(f_path, "w", newline="\n") as f: + with open(f_path, "w", newline="\n", encoding="utf-8") as f: f.write(f_text) -with open("to_rename.txt", "w") as f: +with open("to_rename.txt", "w", encoding="utf-8") as f: f.writelines(to_replace) diff --git a/tools/old/update_evts.py b/tools/old/update_evts.py index fc920e86b3f..904c6a6fc7f 100755 --- a/tools/old/update_evts.py +++ b/tools/old/update_evts.py @@ -41,7 +41,7 @@ def __init__(self, ram_addr, rom_addr): def parse_symbol_addrs(): - with open("ver/us/symbol_addrs.txt", "r") as f: + with open("ver/us/symbol_addrs.txt", "r", encoding="utf-8") as f: lines = f.readlines() symbol_addrs = {} @@ -97,7 +97,7 @@ def eval_namespace(sym, namespace): def replace_old_script_macros(filename, symbol_addrs): - with open(filename, "r") as f: + with open(filename, "r", encoding="utf-8") as f: lines = f.readlines() with open("ver/us/baserom.z64", "rb") as rom: @@ -158,7 +158,7 @@ def replace_old_script_macros(filename, symbol_addrs): num_scripts_replaced += 1 if num_scripts_replaced > 0: - with open(filename, "w") as f: + with open(filename, "w", encoding="utf-8") as f: f.writelines(lines) return num_scripts_replaced diff --git a/tools/rename.py b/tools/rename.py index aacc02069d2..b35b83f07a8 100755 --- a/tools/rename.py +++ b/tools/rename.py @@ -18,7 +18,7 @@ def handle_file(f_path, try_rename_file=False): - with open(f_path) as f: + with open(f_path, "r", encoding="utf-8") as f: f_text_orig = f.read() if try_rename_file: @@ -44,7 +44,7 @@ def handle_file(f_path, try_rename_file=False): to_join.append(f_text[pos:]) f_text = "".join(to_join) # save changes - with open(f_path, "w", newline="\n") as f: + with open(f_path, "w", newline="\n", encoding="utf-8") as f: f.write(f_text) @@ -53,7 +53,7 @@ def apply_renames(file_path: str): # Read input file # One valid whitespace-separated find-replace pair is given per line - with open(file_path) as f: + with open(file_path, "r", encoding="utf-8") as f: renames_text = f.readlines() # Create dict of old -> new names diff --git a/tools/sort_symbol_addrs.py b/tools/sort_symbol_addrs.py index 38d452c09e8..748f04d0619 100755 --- a/tools/sort_symbol_addrs.py +++ b/tools/sort_symbol_addrs.py @@ -11,7 +11,7 @@ syms = {} file_path = os.path.join(script_dir, f"../ver/{version}/symbol_addrs.txt") - with open(file_path) as f: + with open(file_path, "r", encoding="utf-8") as f: symbol_lines = f.readlines() for line in symbol_lines: @@ -22,6 +22,6 @@ sys.exit(55) syms[addr] = line - with open(file_path, newline="\n", mode="w") as f: + with open(file_path, "w", newline="\n", encoding="utf-8") as f: for addr in sorted(syms): f.write(syms[addr]) diff --git a/tools/splat_ext/pm_effect_loads.py b/tools/splat_ext/pm_effect_loads.py index 9278071af8c..fcfbaa997af 100644 --- a/tools/splat_ext/pm_effect_loads.py +++ b/tools/splat_ext/pm_effect_loads.py @@ -24,7 +24,7 @@ def get_macro_call(self, func_name: str) -> str: def effects_from_yaml(yaml_path: Path) -> List[Effect]: - with open(yaml_path) as f: + with open(yaml_path, "r", encoding="utf-8") as f: effects_yaml = yaml_loader.load(f.read(), Loader=yaml_loader.SafeLoader) effects: List[Effect] = [] @@ -116,7 +116,7 @@ def split(self, rom_bytes): self.effect_s_path("").parent.mkdir(parents=True, exist_ok=True) - with open(self.effect_s_path(effect.name), "w") as f: + with open(self.effect_s_path(effect.name), "w", encoding="utf-8") as f: f.write(effect_asm) def get_linker_entries(self): diff --git a/tools/splat_ext/pm_effect_shims.py b/tools/splat_ext/pm_effect_shims.py index c34571279e9..424c999e6a6 100644 --- a/tools/splat_ext/pm_effect_shims.py +++ b/tools/splat_ext/pm_effect_shims.py @@ -49,7 +49,7 @@ def __init__( yaml=yaml, ) - with open(options.opts.src_path / "effect_shims.yaml") as f: + with open(options.opts.src_path / "effect_shims.yaml", "r", encoding="utf-8") as f: self.shims = yaml_loader.load(f.read(), Loader=yaml_loader.SafeLoader) def split(self, rom_bytes): @@ -58,7 +58,7 @@ def split(self, rom_bytes): self.shim_path("").parent.mkdir(parents=True, exist_ok=True) - with open(self.shim_path(shim), "w") as f: + with open(self.shim_path(shim), "w", encoding="utf-8") as f: f.write(shim_asm) def get_linker_entries(self): diff --git a/tools/splat_ext/pm_icons.py b/tools/splat_ext/pm_icons.py index 732de51d8ae..23e179f78e1 100644 --- a/tools/splat_ext/pm_icons.py +++ b/tools/splat_ext/pm_icons.py @@ -33,7 +33,7 @@ def pretty_print_xml(tree: ET.ElementTree, path: Path): indent(root) xml_str = ET.tostring(root, encoding="unicode") xml_str = re.sub(" />", "/>", xml_str) - with open(path, "w") as f: + with open(path, "w", encoding="utf-8") as f: f.write(xml_str) @@ -50,7 +50,7 @@ class N64SegPm_icons(Segment): def split(self, rom_bytes): self.out_dir = options.opts.asset_path / "icon" - with open(script_dir / "icon.yaml") as f: + with open(script_dir / "icon.yaml", "r", encoding="utf-8") as f: self.icons = yaml_loader.load(f.read(), Loader=yaml_loader.SafeLoader) data = rom_bytes[self.rom_start : self.rom_end] diff --git a/tools/splat_ext/pm_imgfx_data.py b/tools/splat_ext/pm_imgfx_data.py index dba97d78334..3cddad3f8b0 100644 --- a/tools/splat_ext/pm_imgfx_data.py +++ b/tools/splat_ext/pm_imgfx_data.py @@ -109,7 +109,7 @@ def unpack_tri(word: int, vtx_buf: List[int]) -> Tuple[int, int, int]: def split(self, rom_bytes): self.OUT_DIR.mkdir(parents=True, exist_ok=True) for anim in self.anims: - with open(f"{self.OUT_DIR}/{anim.name}.json", "w") as f: + with open(f"{self.OUT_DIR}/{anim.name}.json", "w", encoding="utf-8") as f: f.write(anim.toJSON()) def get_linker_entries(self): diff --git a/tools/splat_ext/pm_map_data.py b/tools/splat_ext/pm_map_data.py index 6b25960c6e7..f5e1854e9f9 100644 --- a/tools/splat_ext/pm_map_data.py +++ b/tools/splat_ext/pm_map_data.py @@ -95,7 +95,7 @@ def __init__( cfg_name = "mapfs.yaml" self.files = {} - with open(script_dir / cfg_name) as f: + with open(script_dir / cfg_name, "r", encoding="utf-8") as f: mapfs_cfg = yaml_loader.load(f.read(), Loader=yaml_loader.SafeLoader) for file in mapfs_cfg: if isinstance(file, dict): diff --git a/tools/splat_ext/pm_msg.py b/tools/splat_ext/pm_msg.py index 0499f9df5fb..8d21695f653 100644 --- a/tools/splat_ext/pm_msg.py +++ b/tools/splat_ext/pm_msg.py @@ -3298,7 +3298,7 @@ def __init__( self.generate_header = yaml.get("generate_header", True) toc_file = yaml.get("toc", self.name) + ".yaml" - with (Path(__file__).parent / toc_file).open("r") as f: + with open(Path(__file__).parent / toc_file, "r", encoding="utf-8") as f: self.msg_names = yaml_loader.load(f.read(), Loader=yaml_loader.SafeLoader) def split(self, rom_bytes): @@ -3338,7 +3338,7 @@ def split(self, rom_bytes): path = msg_dir / Path(name + ".msg") - with open(path, "w") as self.f: + with open(path, "w", encoding="utf-8") as self.f: for j, msg_offset in enumerate(msg_offsets): if j != 0: self.f.write("\n") diff --git a/tools/splat_ext/pm_sbn.py b/tools/splat_ext/pm_sbn.py index a7c8079c10a..2023f413c13 100644 --- a/tools/splat_ext/pm_sbn.py +++ b/tools/splat_ext/pm_sbn.py @@ -212,7 +212,7 @@ def write(self, path: Path): except Exception as e: raise Exception(f"Failed to write {sbn_file}: {e}") - with open(path / "sbn.yaml", "w") as f: + with open(path / "sbn.yaml", "w", encoding="utf-8") as f: # Filename->ID map f.write("# Mapping of filenames to entry IDs. Use 'id: auto' to automatically assign a unique ID.\n") f.write( diff --git a/tools/splat_ext/pm_sprite_shading_profiles.py b/tools/splat_ext/pm_sprite_shading_profiles.py index f7c314c9add..e0d9d667145 100644 --- a/tools/splat_ext/pm_sprite_shading_profiles.py +++ b/tools/splat_ext/pm_sprite_shading_profiles.py @@ -204,7 +204,7 @@ def scan(self, rom_bytes): def split(self, rom_bytes): self.out_path().parent.mkdir(parents=True, exist_ok=True) - with open(self.out_path(), "w") as f: + with open(self.out_path(), "w", encoding="utf-8") as f: f.write(self.json_out) def out_path(self) -> Path: diff --git a/tools/splat_ext/pm_sprites.py b/tools/splat_ext/pm_sprites.py index 007f945e77a..c9bdb71bb77 100644 --- a/tools/splat_ext/pm_sprites.py +++ b/tools/splat_ext/pm_sprites.py @@ -125,7 +125,7 @@ def pretty_print_xml(tree: ET.ElementTree, path: Path): indent(root) xml_str = ET.tostring(root, encoding="unicode") xml_str = re.sub(" />", "/>", xml_str) - with open(path, "w") as f: + with open(path, "w", encoding="utf-8") as f: f.write(xml_str) @@ -720,12 +720,12 @@ def __init__(self, rom_start, rom_end, type, name, vram_start, args, yaml) -> No super().__init__(rom_start, rom_end, type, name, vram_start, args=args, yaml=yaml) path = Path(__file__).parent / f"npc_sprite_names.yaml" - with path.open("r") as f: + with path.open("r", encoding="utf-8") as f: self.npc_cfg = yaml_loader.load(f.read(), Loader=yaml_loader.SafeLoader) self.npc_cfg_modified_time = path.stat().st_mtime path = Path(__file__).parent / f"player_sprite_names.yaml" - with path.open("r") as f: + with path.open("r", encoding="utf-8") as f: self.player_cfg = yaml_loader.load(f.read(), Loader=yaml_loader.SafeLoader) self.player_cfg_modified_time = path.stat().st_mtime diff --git a/tools/splat_ext/tex_archives.py b/tools/splat_ext/tex_archives.py index 3006136a027..69331e51554 100644 --- a/tools/splat_ext/tex_archives.py +++ b/tools/splat_ext/tex_archives.py @@ -574,5 +574,5 @@ def extract(bytes, tex_path: Path): json_out = json.dumps(out, sort_keys=False, indent=4) json_fn = str(tex_path) + ".json" - with open(json_fn, "w") as f: + with open(json_fn, "w", encoding="utf-8") as f: f.write(json_out) diff --git a/tools/star_rod_enum_to_decomp.py b/tools/star_rod_enum_to_decomp.py index 2eed0cfa4e4..61bd0e8e925 100755 --- a/tools/star_rod_enum_to_decomp.py +++ b/tools/star_rod_enum_to_decomp.py @@ -54,9 +54,8 @@ def single_translation(file_path): ret = "" try: - file = open(file_path) - file_content = file.read() - file.close() + with open(file_path, "r", encoding="utf-8") as file: + file_content = file.read() except: print("File not found at the given path.") return "t", "y" @@ -80,9 +79,8 @@ def recursive_translation(database_path): stuff = [f for f in glob(database_path + "/**/*.*", recursive=True) if f.endswith(".enum") or f.endswith(".flags")] for element in stuff: try: - file = open(element) - file_content = file.read() - file.close() + with open(element, "r", encoding="utf-8") as file: + file_content = file.read() except: continue @@ -111,9 +109,8 @@ def main(args): ret += result - file = open("" + enum_name + ".txt", "w+") - file.write(ret) - file.close() + with open("" + enum_name + ".txt", "w+", encoding="utf-8") as file: + file.write(ret) parser = argparse.ArgumentParser( diff --git a/tools/star_rod_idx_to_c.py b/tools/star_rod_idx_to_c.py index 1e36abc329b..4197f9bc586 100755 --- a/tools/star_rod_idx_to_c.py +++ b/tools/star_rod_idx_to_c.py @@ -1205,7 +1205,7 @@ def add_to_symbol_map(addr, pair): disasm_script.get_constants() - with open(os.path.join(DIR, "../ver/current/splat.yaml")) as f: + with open(os.path.join(DIR, "../ver/current/splat.yaml"), "r", encoding="utf-8") as f: splat_config = yaml.safe_load(f.read()) rom_offset = -1 @@ -1227,7 +1227,7 @@ def add_to_symbol_map(addr, pair): else: function_replacements = {} - with open(args.idxfile, "r") as f: + with open(args.idxfile, "r", encoding="utf-8") as f: midx = parse_midx(f, vram=vram) with open(os.path.join(DIR, "../ver/current/baserom.z64"), "rb") as romfile: diff --git a/tools/sym_info.py b/tools/sym_info.py index cfe6c07655c..591c64399df 100755 --- a/tools/sym_info.py +++ b/tools/sym_info.py @@ -33,7 +33,7 @@ def search_address(target_addr, map=get_map()): cur_file = "" prev_file = cur_file prev_line = "" - with open(map) as f: + with open(map, "r", encoding="utf-8") as f: for line in f: if "load address" in line: # Ignore .bss sections if we're looking for a ROM address @@ -79,7 +79,7 @@ def search_symbol(target_sym, map=get_map()): ram_offset = None cur_file = "" prev_line = "" - with open(map) as f: + with open(map, "r", encoding="utf-8") as f: for line in f: if "load address" in line: ram = int(line[16 : 16 + 18], 0) diff --git a/tools/update_symbol_addrs.py b/tools/update_symbol_addrs.py index c3df51f049e..52d7e54f1c3 100755 --- a/tools/update_symbol_addrs.py +++ b/tools/update_symbol_addrs.py @@ -28,7 +28,7 @@ def read_ignores(): - with open(ignores_path) as f: + with open(ignores_path, "r", encoding="utf-8") as f: lines = f.readlines() for line in lines: @@ -41,7 +41,7 @@ def scan_map(): ram_offset = None cur_file = "" prev_line = "" - with open(map_path) as f: + with open(map_path, "r", encoding="utf-8") as f: for line in f: if "load address" in line: ram = int(line[16 : 16 + 18], 0) @@ -71,7 +71,7 @@ def scan_map(): def read_symbol_addrs(): unique_lines = set() - with open(symbol_addrs_path, "r") as f: + with open(symbol_addrs_path, "r", encoding="utf-8") as f: for line in f.readlines(): unique_lines.add(line) @@ -212,7 +212,7 @@ def reconcile_symbols(): def write_new_symbol_addrs(): - with open(symbol_addrs_path, "w", newline="\n") as f: + with open(symbol_addrs_path, "w", newline="\n", encoding="utf-8") as f: for symbol in sorted(symbol_addrs, key=lambda x: (x[3] == -1, x[3], x[1], x[0])): line = f"{symbol[0]} = 0x{symbol[1]:X}; //" if symbol[2] and len(symbol[2]) > 0: diff --git a/tools/warnings_count/compare_warnings.py b/tools/warnings_count/compare_warnings.py index 0300bf2ea64..e496adc6c2c 100755 --- a/tools/warnings_count/compare_warnings.py +++ b/tools/warnings_count/compare_warnings.py @@ -22,7 +22,7 @@ def main(): current_warnings = [line for line in current_warnings if line] # Write the current warnings to a file - with open(script_dir / "warnings.txt", "w") as f: + with open(script_dir / "warnings.txt", "w", encoding="utf-8") as f: for line in current_warnings: f.write(line + "\n") @@ -31,11 +31,11 @@ def main(): print("build_log.txt not found. Exiting.") sys.exit(1) - with open(root_dir / "build_log.txt") as f: + with open(root_dir / "build_log.txt", "r", encoding="utf-8") as f: new_warnings = [line for line in f.readlines() if "warning" in line] # Write the new warnings to a file - with open(script_dir / "warnings_new.txt", "w") as f: + with open(script_dir / "warnings_new.txt", "w", encoding="utf-8") as f: f.writelines(new_warnings) num_current_warnings = len(current_warnings)