diff --git a/utils/codegen/generate-config-info.py b/utils/codegen/generate-config-info.py index a25167affb4..c54a5cf2536 100644 --- a/utils/codegen/generate-config-info.py +++ b/utils/codegen/generate-config-info.py @@ -945,7 +945,7 @@ def generate(config, output_dir, source_mrdocs_dir): # metadata the header carries, so there are no longer any generated # ConfigSchema.cpp or PublicToolArgs sources. config_schema_hpp = generate_config_schema_hpp(config) - with open(os.path.join(mrdocs_build_include_dir, 'ConfigSchema.hpp'), 'w') as f: + with open(os.path.join(mrdocs_build_include_dir, 'ConfigSchema.hpp'), 'w', encoding='utf-8') as f: f.write(config_schema_hpp) @@ -963,7 +963,7 @@ def main(): sys.exit(1) # parse input file - with open(input_file, 'r') as f: + with open(input_file, 'r', encoding='utf-8') as f: config = json.load(f) generate(config, output_dir, os.path.dirname(os.path.abspath(input_file))) diff --git a/utils/codegen/generate-version-header.py b/utils/codegen/generate-version-header.py index e6982fa2c9e..a246d59e4bd 100644 --- a/utils/codegen/generate-version-header.py +++ b/utils/codegen/generate-version-header.py @@ -157,7 +157,7 @@ def main(): } content = '' - with open(args.template, "r") as f: + with open(args.template, "r", encoding="utf-8") as f: content = f.read() for name, value in substitutions.items(): content = content.replace(f"@{name}@", value) @@ -166,12 +166,12 @@ def main(): # file (and never triggers a rebuild of everything that includes it). previous = None if os.path.exists(args.output): - with open(args.output, "r") as f: + with open(args.output, "r", encoding="utf-8") as f: previous = f.read() if content != previous: if os.path.dirname(args.output): os.makedirs(os.path.dirname(args.output), exist_ok=True) - with open(args.output, "w") as f: + with open(args.output, "w", encoding="utf-8") as f: f.write(content) diff --git a/utils/codegen/generate-yaml-schema.py b/utils/codegen/generate-yaml-schema.py index 2adda4b2694..e8393799912 100644 --- a/utils/codegen/generate-yaml-schema.py +++ b/utils/codegen/generate-yaml-schema.py @@ -172,13 +172,13 @@ def main(): # Generate the schema mrdocs_config_path = os.path.join(mrdocs_root_dir, 'src', 'mrdocs', 'ConfigOptions.json') - with open(mrdocs_config_path, 'r') as f: + with open(mrdocs_config_path, 'r', encoding='utf-8') as f: config = json.loads(f.read()) yaml_schema = generate_yaml_schema(config) if args.check: # Check if the generated schema matches the existing schema - with open(mrdocs_schema_path, 'r') as f: + with open(mrdocs_schema_path, 'r', encoding='utf-8') as f: existing_schema = f.read() if yaml_schema != existing_schema: print( @@ -190,7 +190,7 @@ def main(): print("The generated schema matches the existing schema.") else: # Write the schema to the file - with open(mrdocs_schema_path, 'w') as f: + with open(mrdocs_schema_path, 'w', encoding='utf-8', newline='\n') as f: f.write(yaml_schema) diff --git a/utils/codegen/generate.py b/utils/codegen/generate.py index ee4198c2e83..0bd8748afed 100644 --- a/utils/codegen/generate.py +++ b/utils/codegen/generate.py @@ -124,7 +124,7 @@ def GenerateIndexedCppFiles(parentDirectory, fileContents): for index, aDeclaration in enumerate(contents): fileName = name_fmt.format(index) filePath = os.path.join(parentDirectory, fileName) - with open(filePath, "w") as f: + with open(filePath, "w", encoding="utf-8") as f: f.write(aDeclaration)