SCons: Ensure `with` statement where applicable

This commit is contained in:
Thaddeus Crews 2024-03-10 12:09:48 -05:00
parent 0ace0a1292
commit fb299d0fb1
No known key found for this signature in database
GPG Key ID: 62181B86FE9E5D84
21 changed files with 1649 additions and 1699 deletions

View File

@ -31,8 +31,7 @@ def escape_string(s):
def make_certs_header(target, source, env):
src = source[0]
dst = target[0]
f = open(src, "rb")
g = open(dst, "w", encoding="utf-8", newline="\n")
with open(src, "rb") as f, open(dst, "w", encoding="utf-8", newline="\n") as g:
buf = f.read()
decomp_size = len(buf)
@ -58,9 +57,6 @@ def make_certs_header(target, source, env):
g.write("};\n")
g.write("#endif // CERTS_COMPRESSED_GEN_H")
g.close()
f.close()
def make_authors_header(target, source, env):
sections = [
@ -78,9 +74,7 @@ def make_authors_header(target, source, env):
src = source[0]
dst = target[0]
f = open(src, "r", encoding="utf-8")
g = open(dst, "w", encoding="utf-8", newline="\n")
with open(src, "r", encoding="utf-8") as f, open(dst, "w", encoding="utf-8", newline="\n") as g:
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("#ifndef AUTHORS_GEN_H\n")
g.write("#define AUTHORS_GEN_H\n")
@ -112,9 +106,6 @@ def make_authors_header(target, source, env):
g.write("#endif // AUTHORS_GEN_H\n")
g.close()
f.close()
def make_donors_header(target, source, env):
sections = [
@ -140,9 +131,7 @@ def make_donors_header(target, source, env):
src = source[0]
dst = target[0]
f = open(src, "r", encoding="utf-8")
g = open(dst, "w", encoding="utf-8", newline="\n")
with open(src, "r", encoding="utf-8") as f, open(dst, "w", encoding="utf-8", newline="\n") as g:
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("#ifndef DONORS_GEN_H\n")
g.write("#define DONORS_GEN_H\n")
@ -174,9 +163,6 @@ def make_donors_header(target, source, env):
g.write("#endif // DONORS_GEN_H\n")
g.close()
f.close()
def make_license_header(target, source, env):
src_copyright = source[0]

View File

@ -4,9 +4,7 @@ import zlib
def run(target, source, env):
src = source[0]
dst = target[0]
f = open(src, "rb")
g = open(dst, "w", encoding="utf-8", newline="\n")
with open(src, "rb") as f, open(dst, "w", encoding="utf-8", newline="\n") as g:
buf = f.read()
decomp_size = len(buf)
@ -55,8 +53,6 @@ class GDExtensionInterfaceDump {
#endif // GDEXTENSION_INTERFACE_DUMP_H
"""
)
g.close()
f.close()
if __name__ == "__main__":

View File

@ -9,8 +9,7 @@ from collections import OrderedDict
def make_default_controller_mappings(target, source, env):
dst = target[0]
g = open(dst, "w", encoding="utf-8", newline="\n")
with open(dst, "w", encoding="utf-8", newline="\n") as g:
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write('#include "core/typedefs.h"\n')
g.write('#include "core/input/default_controller_mappings.h"\n')
@ -62,7 +61,6 @@ def make_default_controller_mappings(target, source, env):
g.write("#endif\n")
g.write("\tnullptr\n};\n")
g.close()
if __name__ == "__main__":

View File

@ -889,12 +889,12 @@ def get_git_branch() -> str:
def make_rst_class(class_def: ClassDef, state: State, dry_run: bool, output_dir: str) -> None:
class_name = class_def.name
if dry_run:
f = open(os.devnull, "w", encoding="utf-8", newline="\n")
else:
f = open(os.path.join(output_dir, f"class_{class_name.lower()}.rst"), "w", encoding="utf-8", newline="\n")
with open(
os.devnull if dry_run else os.path.join(output_dir, f"class_{class_name.lower()}.rst"),
"w",
encoding="utf-8",
newline="\n",
) as f:
# Remove the "Edit on Github" button from the online docs page.
f.write(":github_url: hide\n\n")
@ -1016,7 +1016,9 @@ def make_rst_class(class_def: ClassDef, state: State, dry_run: bool, output_dir:
type_rst = property_def.type_name.to_rst(state)
default = property_def.default_value
if default is not None and property_def.overrides:
ref = f":ref:`{property_def.overrides}<class_{property_def.overrides}_property_{property_def.name}>`"
ref = (
f":ref:`{property_def.overrides}<class_{property_def.overrides}_property_{property_def.name}>`"
)
# Not using translate() for now as it breaks table formatting.
ml.append((type_rst, property_def.name, f"{default} (overrides {ref})"))
else:
@ -1690,11 +1692,9 @@ def make_link(url: str, title: str) -> str:
def make_rst_index(grouped_classes: Dict[str, List[str]], dry_run: bool, output_dir: str) -> None:
if dry_run:
f = open(os.devnull, "w", encoding="utf-8", newline="\n")
else:
f = open(os.path.join(output_dir, "index.rst"), "w", encoding="utf-8", newline="\n")
with open(
os.devnull if dry_run else os.path.join(output_dir, "index.rst"), "w", encoding="utf-8", newline="\n"
) as f:
# Remove the "Edit on Github" button from the online docs page, and disallow user-contributed notes
# on the index page. User-contributed notes are allowed on individual class pages.
f.write(":github_url: hide\n:allow_comments: False\n\n")

View File

@ -11,7 +11,7 @@ import editor_builders
def _make_doc_data_class_path(to_path):
# NOTE: It is safe to generate this file here, since this is still executed serially
g = open(os.path.join(to_path, "doc_data_class_path.gen.h"), "w", encoding="utf-8", newline="\n")
with open(os.path.join(to_path, "doc_data_class_path.gen.h"), "w", encoding="utf-8", newline="\n") as g:
g.write("static const int _doc_data_class_path_count = " + str(len(env.doc_class_path)) + ";\n")
g.write("struct _DocDataClassPath { const char* name; const char* path; };\n")
@ -21,8 +21,6 @@ def _make_doc_data_class_path(to_path):
g.write("\t{nullptr, nullptr}\n")
g.write("};\n")
g.close()
if env.editor_build:
# Register exporters

View File

@ -16,7 +16,7 @@ from platform_methods import subprocess_main
def make_doc_header(target, source, env):
dst = target[0]
g = open(dst, "w", encoding="utf-8", newline="\n")
with open(dst, "w", encoding="utf-8", newline="\n") as g:
buf = ""
docbegin = ""
docend = ""
@ -47,14 +47,11 @@ def make_doc_header(target, source, env):
g.write("#endif")
g.close()
def make_translations_header(target, source, env, category):
dst = target[0]
g = open(dst, "w", encoding="utf-8", newline="\n")
with open(dst, "w", encoding="utf-8", newline="\n") as g:
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("#ifndef _{}_TRANSLATIONS_H\n".format(category.upper()))
g.write("#define _{}_TRANSLATIONS_H\n".format(category.upper()))
@ -118,15 +115,15 @@ def make_translations_header(target, source, env, category):
g.write("static {}TranslationList _{}_translations[] = {{\n".format(category.capitalize(), category))
for x in xl_names:
g.write(
'\t{{ "{}", {}, {}, _{}_translation_{}_compressed }},\n'.format(x[0], str(x[1]), str(x[2]), category, x[0])
'\t{{ "{}", {}, {}, _{}_translation_{}_compressed }},\n'.format(
x[0], str(x[1]), str(x[2]), category, x[0]
)
)
g.write("\t{nullptr, 0, 0, nullptr}\n")
g.write("};\n")
g.write("#endif")
g.close()
def make_editor_translations_header(target, source, env):
make_translations_header(target, source, env, "editor")

View File

@ -15,8 +15,7 @@ def make_editor_icons_action(target, source, env):
dst = target[0]
svg_icons = source
icons_string = StringIO()
with StringIO() as icons_string, StringIO() as s:
for f in svg_icons:
fname = str(f)
@ -33,7 +32,6 @@ def make_editor_icons_action(target, source, env):
icons_string.write(",")
icons_string.write("\n")
s = StringIO()
s.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
s.write("#ifndef _EDITOR_ICONS_H\n")
s.write("#define _EDITOR_ICONS_H\n")
@ -88,9 +86,6 @@ def make_editor_icons_action(target, source, env):
with open(dst, "w", encoding="utf-8", newline="\n") as f:
f.write(s.getvalue())
s.close()
icons_string.close()
if __name__ == "__main__":
subprocess_main(globals())

View File

@ -54,7 +54,7 @@ def parse_template(inherits, source, delimiter):
def make_templates(target, source, env):
dst = target[0]
s = StringIO()
with StringIO() as s:
s.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n\n")
s.write("#ifndef _CODE_TEMPLATES_H\n")
s.write("#define _CODE_TEMPLATES_H\n\n")
@ -77,7 +77,9 @@ def make_templates(target, source, env):
number_of_templates += 1
s.write("\nstatic const int TEMPLATES_ARRAY_SIZE = " + str(number_of_templates) + ";\n")
s.write("\nstatic const struct ScriptLanguage::ScriptTemplate TEMPLATES[" + str(number_of_templates) + "] = {\n")
s.write(
"\nstatic const struct ScriptLanguage::ScriptTemplate TEMPLATES[" + str(number_of_templates) + "] = {\n"
)
s.write(parsed_template_string)
@ -88,8 +90,6 @@ def make_templates(target, source, env):
with open(dst, "w", encoding="utf-8", newline="\n") as f:
f.write(s.getvalue())
s.close()
if __name__ == "__main__":
subprocess_main(globals())

View File

@ -12,8 +12,7 @@ from platform_methods import subprocess_main
def make_fonts_header(target, source, env):
dst = target[0]
g = open(dst, "w", encoding="utf-8", newline="\n")
with open(dst, "w", encoding="utf-8", newline="\n") as g:
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("#ifndef _EDITOR_FONTS_H\n")
g.write("#define _EDITOR_FONTS_H\n")
@ -34,8 +33,6 @@ def make_fonts_header(target, source, env):
g.write("#endif")
g.close()
if __name__ == "__main__":
subprocess_main(globals())

View File

@ -37,7 +37,7 @@ class GLES3HeaderStruct:
def include_file_in_gles3_header(filename: str, header_data: GLES3HeaderStruct, depth: int):
fs = open(filename, "r")
with open(filename, "r") as fs:
line = fs.readline()
while line:
@ -191,8 +191,6 @@ def include_file_in_gles3_header(filename: str, header_data: GLES3HeaderStruct,
line = fs.readline()
header_data.line_offset += 1
fs.close()
return header_data
@ -211,7 +209,7 @@ def build_gles3_header(
else:
out_file = optional_output_filename
fd = open(out_file, "w", encoding="utf-8", newline="\n")
with open(out_file, "w", encoding="utf-8", newline="\n") as fd:
defspec = 0
defvariant = ""
@ -597,7 +595,6 @@ def build_gles3_header(
fd.write("};\n\n")
fd.write("#endif\n\n")
fd.close()
def build_gles3_headers(target, source, env):

View File

@ -44,7 +44,7 @@ class RDHeaderStruct:
def include_file_in_rd_header(filename: str, header_data: RDHeaderStruct, depth: int) -> RDHeaderStruct:
fs = open(filename, "r")
with open(filename, "r") as fs:
line = fs.readline()
while line:
@ -109,8 +109,6 @@ def include_file_in_rd_header(filename: str, header_data: RDHeaderStruct, depth:
line = fs.readline()
header_data.line_offset += 1
fs.close()
return header_data
@ -180,7 +178,7 @@ class RAWHeaderStruct:
def include_file_in_raw_header(filename: str, header_data: RAWHeaderStruct, depth: int) -> None:
fs = open(filename, "r")
with open(filename, "r") as fs:
line = fs.readline()
while line:
@ -195,8 +193,6 @@ def include_file_in_raw_header(filename: str, header_data: RAWHeaderStruct, dept
header_data.code += line
line = fs.readline()
fs.close()
def build_raw_header(
filename: str, optional_output_filename: Optional[str] = None, header_data: Optional[RAWHeaderStruct] = None

View File

@ -179,12 +179,14 @@ def get_version_info(module_version_string="", silent=False):
gitfolder = ".git"
if os.path.isfile(".git"):
module_folder = open(".git", "r").readline().strip()
with open(".git", "r") as file:
module_folder = file.readline().strip()
if module_folder.startswith("gitdir: "):
gitfolder = module_folder[8:]
if os.path.isfile(os.path.join(gitfolder, "HEAD")):
head = open(os.path.join(gitfolder, "HEAD"), "r", encoding="utf8").readline().strip()
with open(os.path.join(gitfolder, "HEAD"), "r", encoding="utf8") as file:
head = file.readline().strip()
if head.startswith("ref: "):
ref = head[5:]
# If this directory is a Git worktree instead of a root clone.
@ -194,7 +196,8 @@ def get_version_info(module_version_string="", silent=False):
head = os.path.join(gitfolder, ref)
packedrefs = os.path.join(gitfolder, "packed-refs")
if os.path.isfile(head):
githash = open(head, "r").readline().strip()
with open(head, "r") as file:
githash = file.readline().strip()
elif os.path.isfile(packedrefs):
# Git may pack refs into a single file. This code searches .git/packed-refs file for the current ref's hash.
# https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-pack-refs.html
@ -230,9 +233,10 @@ def generate_version_header(module_version_string=""):
# NOTE: It is safe to generate these files here, since this is still executed serially.
f = open("core/version_generated.gen.h", "w", encoding="utf-8", newline="\n")
with open("core/version_generated.gen.h", "w", encoding="utf-8", newline="\n") as f:
f.write(
"""/* THIS FILE IS GENERATED DO NOT EDIT */
"""\
/* THIS FILE IS GENERATED DO NOT EDIT */
#ifndef VERSION_GENERATED_GEN_H
#define VERSION_GENERATED_GEN_H
#define VERSION_SHORT_NAME "{short_name}"
@ -251,11 +255,11 @@ def generate_version_header(module_version_string=""):
**version_info
)
)
f.close()
fhash = open("core/version_hash.gen.cpp", "w", encoding="utf-8", newline="\n")
with open("core/version_hash.gen.cpp", "w", encoding="utf-8", newline="\n") as fhash:
fhash.write(
"""/* THIS FILE IS GENERATED DO NOT EDIT */
"""\
/* THIS FILE IS GENERATED DO NOT EDIT */
#include "core/version.h"
const char *const VERSION_HASH = "{git_hash}";
const uint64_t VERSION_TIMESTAMP = {git_timestamp};
@ -263,11 +267,10 @@ const uint64_t VERSION_TIMESTAMP = {git_timestamp};
**version_info
)
)
fhash.close()
def parse_cg_file(fname, uniforms, sizes, conditionals):
fs = open(fname, "r")
with open(fname, "r") as fs:
line = fs.readline()
while line:
@ -293,8 +296,6 @@ def parse_cg_file(fname, uniforms, sizes, conditionals):
line = fs.readline()
fs.close()
def get_cmdline_bool(option, default):
"""We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
@ -384,7 +385,7 @@ def is_module(path):
def write_disabled_classes(class_list):
f = open("core/disabled_classes.gen.h", "w", encoding="utf-8", newline="\n")
with open("core/disabled_classes.gen.h", "w", encoding="utf-8", newline="\n") as f:
f.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
f.write("#ifndef DISABLED_CLASSES_GEN_H\n")
f.write("#define DISABLED_CLASSES_GEN_H\n\n")
@ -1246,7 +1247,8 @@ def generate_vs_project(env, original_args, project_name="godot"):
).hexdigest()
if os.path.exists(f"{project_name}.vcxproj.filters"):
existing_filters = open(f"{project_name}.vcxproj.filters", "r").read()
with open(f"{project_name}.vcxproj.filters", "r") as file:
existing_filters = file.read()
match = re.search(r"(?ms)^<!-- CHECKSUM$.([0-9a-f]{32})", existing_filters)
if match is not None and md5 == match.group(1):
skip_filters = True
@ -1257,7 +1259,8 @@ def generate_vs_project(env, original_args, project_name="godot"):
if not skip_filters:
print(f"Regenerating {project_name}.vcxproj.filters")
filters_template = open("misc/msvs/vcxproj.filters.template", "r").read()
with open("misc/msvs/vcxproj.filters.template", "r") as file:
filters_template = file.read()
for i in range(1, 10):
filters_template = filters_template.replace(f"%%UUID{i}%%", str(uuid.uuid4()))
@ -1410,7 +1413,8 @@ def generate_vs_project(env, original_args, project_name="godot"):
)
output = f'bin\\godot{env["PROGSUFFIX"]}'
props_template = open("misc/msvs/props.template", "r").read()
with open("misc/msvs/props.template", "r") as file:
props_template = file.read()
props_template = props_template.replace("%%VSCONF%%", vsconf)
props_template = props_template.replace("%%CONDITION%%", condition)
@ -1567,7 +1571,8 @@ def generate_vs_project(env, original_args, project_name="godot"):
section2 = sorted(section2)
if not get_bool(original_args, "vsproj_props_only", False):
proj_template = open("misc/msvs/vcxproj.template", "r").read()
with open("misc/msvs/vcxproj.template", "r") as file:
proj_template = file.read()
proj_template = proj_template.replace("%%UUID%%", proj_uuid)
proj_template = proj_template.replace("%%CONFS%%", "\n ".join(configurations))
proj_template = proj_template.replace("%%IMPORTS%%", "\n ".join(imports))
@ -1578,7 +1583,8 @@ def generate_vs_project(env, original_args, project_name="godot"):
f.write(proj_template)
if not get_bool(original_args, "vsproj_props_only", False):
sln_template = open("misc/msvs/sln.template", "r").read()
with open("misc/msvs/sln.template", "r") as file:
sln_template = file.read()
sln_template = sln_template.replace("%%NAME%%", project_name)
sln_template = sln_template.replace("%%UUID%%", proj_uuid)
sln_template = sln_template.replace("%%SLNUUID%%", sln_uuid)

View File

@ -9,8 +9,8 @@ if len(sys.argv) < 2:
fname = sys.argv[1]
fileread = open(fname.strip(), "r")
file_contents = fileread.read()
with open(fname.strip(), "r") as fileread:
file_contents = fileread.read()
# If find "ERROR: AddressSanitizer:", then happens invalid read or write
# This is critical bug, so we need to fix this as fast as possible

View File

@ -65,31 +65,28 @@ text += "\n"
# In a second pass, we skip all consecutive comment lines starting with "/*",
# then we can append the rest (step 2).
fileread = open(fname.strip(), "r")
line = fileread.readline()
header_done = False
with open(fname.strip(), "r") as fileread:
line = fileread.readline()
header_done = False
while line.strip() == "": # Skip empty lines at the top
while line.strip() == "": # Skip empty lines at the top
line = fileread.readline()
if line.find("/**********") == -1: # Godot header starts this way
if line.find("/**********") == -1: # Godot header starts this way
# Maybe starting with a non-Godot comment, abort header magic
header_done = True
while not header_done: # Handle header now
while not header_done: # Handle header now
if line.find("/*") != 0: # No more starting with a comment
header_done = True
if line.strip() != "":
text += line
line = fileread.readline()
while line != "": # Dump everything until EOF
while line != "": # Dump everything until EOF
text += line
line = fileread.readline()
fileread.close()
# Write
filewrite = open(fname.strip(), "w", encoding="utf-8", newline="\n")
filewrite.write(text)
filewrite.close()
with open(fname.strip(), "w", encoding="utf-8", newline="\n") as filewrite:
filewrite.write(text)

View File

@ -314,7 +314,6 @@ def generate_sdk_package_versions():
# We write in ../SdkPackageVersions.props.
with open(os.path.join(dirname(script_path), "SdkPackageVersions.props"), "w", encoding="utf-8", newline="\n") as f:
f.write(props)
f.close()
# Also write the versioned docs URL to a constant for the Source Generators.
@ -342,7 +341,6 @@ def generate_sdk_package_versions():
with open(os.path.join(generators_dir, "Common.Constants.cs"), "w", encoding="utf-8", newline="\n") as f:
f.write(constants)
f.close()
def build_all(msbuild_tool, module_dir, output_dir, godot_platform, dev_debug, push_nupkgs_local, precision):

View File

@ -9,8 +9,7 @@ env_text_server_adv = env_modules.Clone()
def make_icu_data(target, source, env):
dst = target[0].srcnode().abspath
g = open(dst, "w", encoding="utf-8", newline="\n")
with open(dst, "w", encoding="utf-8", newline="\n") as g:
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("/* (C) 2016 and later: Unicode, Inc. and others. */\n")
g.write("/* License & terms of use: https://www.unicode.org/copyright.html */\n")
@ -20,7 +19,7 @@ def make_icu_data(target, source, env):
g.write('#include "unicode/udata.h"\n')
g.write('#include "unicode/uversion.h"\n')
f = open(source[0].srcnode().abspath, "rb")
with open(source[0].srcnode().abspath, "rb") as f:
buf = f.read()
g.write('extern "C" U_EXPORT const size_t U_ICUDATA_SIZE = ' + str(len(buf)) + ";\n")

View File

@ -83,8 +83,7 @@ def disable_warnings(self):
def make_icu_data(target, source, env):
dst = target[0].srcnode().abspath
g = open(dst, "w", encoding="utf-8", newline="\n")
with open(dst, "w", encoding="utf-8", newline="\n") as g:
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("/* (C) 2016 and later: Unicode, Inc. and others. */\n")
g.write("/* License & terms of use: https://www.unicode.org/copyright.html */\n")
@ -94,7 +93,7 @@ def make_icu_data(target, source, env):
g.write('#include "unicode/udata.h"\n')
g.write('#include "unicode/uversion.h"\n')
f = open(source[0].srcnode().abspath, "rb")
with open(source[0].srcnode().abspath, "rb") as f:
buf = f.read()
g.write('extern "C" U_EXPORT const size_t U_ICUDATA_SIZE = ' + str(len(buf)) + ";\n")
@ -108,10 +107,11 @@ def make_icu_data(target, source, env):
def write_macos_plist(target, binary_name, identifier, name):
os.makedirs(f"{target}/Resource/", exist_ok=True)
f = open(f"{target}/Resource/Info.plist", "w", encoding="utf-8", newline="\n")
with open(f"{target}/Resource/Info.plist", "w", encoding="utf-8", newline="\n") as f:
f.write(f'<?xml version="1.0" encoding="UTF-8"?>\n')
f.write(f'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n')
f.write(
f'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n'
)
f.write(f'<plist version="1.0">\n')
f.write(f"<dict>\n")
f.write(f"\t<key>CFBundleExecutable</key>\n")

View File

@ -83,8 +83,7 @@ def disable_warnings(self):
def make_icu_data(target, source, env):
dst = target[0].srcnode().abspath
g = open(dst, "w", encoding="utf-8", newline="\n")
with open(dst, "w", encoding="utf-8", newline="\n") as g:
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("/* (C) 2016 and later: Unicode, Inc. and others. */\n")
g.write("/* License & terms of use: https://www.unicode.org/copyright.html */\n")
@ -94,7 +93,7 @@ def make_icu_data(target, source, env):
g.write('#include "unicode/udata.h"\n')
g.write('#include "unicode/uversion.h"\n')
f = open(source[0].srcnode().abspath, "rb")
with open(source[0].srcnode().abspath, "rb") as f:
buf = f.read()
g.write('extern "C" U_EXPORT const size_t U_ICUDATA_SIZE = ' + str(len(buf)) + ";\n")
@ -108,10 +107,11 @@ def make_icu_data(target, source, env):
def write_macos_plist(target, binary_name, identifier, name):
os.makedirs(f"{target}/Resource/", exist_ok=True)
f = open(f"{target}/Resource/Info.plist", "w", encoding="utf-8", newline="\n")
with open(f"{target}/Resource/Info.plist", "w", encoding="utf-8", newline="\n") as f:
f.write(f'<?xml version="1.0" encoding="UTF-8"?>\n')
f.write(f'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n')
f.write(
f'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n'
)
f.write(f'<plist version="1.0">\n')
f.write(f"<dict>\n")
f.write(f"\t<key>CFBundleExecutable</key>\n")

View File

@ -124,7 +124,7 @@ def generate_export_icons(platform_path, platform_name):
svg_names.append("run_icon")
for name in svg_names:
svgf = open(export_path + "/" + name + ".svg", "rb")
with open(export_path + "/" + name + ".svg", "rb") as svgf:
b = svgf.read(1)
svg_str = " /* AUTOGENERATED FILE, DO NOT EDIT */ \n"
svg_str += " static const char *_" + platform_name + "_" + name + '_svg = "'
@ -134,8 +134,6 @@ def generate_export_icons(platform_path, platform_name):
svg_str += '";\n'
svgf.close()
# NOTE: It is safe to generate this file here, since this is still executed serially.
wf = export_path + "/" + name + "_svg.gen.h"
with open(wf, "w", encoding="utf-8", newline="\n") as svgw:

View File

@ -13,8 +13,7 @@ from platform_methods import subprocess_main
def make_fonts_header(target, source, env):
dst = target[0]
g = open(dst, "w", encoding="utf-8", newline="\n")
with open(dst, "w", encoding="utf-8", newline="\n") as g:
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("#ifndef _DEFAULT_FONTS_H\n")
g.write("#define _DEFAULT_FONTS_H\n")
@ -35,8 +34,6 @@ def make_fonts_header(target, source, env):
g.write("#endif")
g.close()
if __name__ == "__main__":
subprocess_main(globals())

View File

@ -15,8 +15,7 @@ def make_default_theme_icons_action(target, source, env):
dst = target[0]
svg_icons = source
icons_string = StringIO()
with StringIO() as icons_string, StringIO() as s:
for f in svg_icons:
fname = str(f)
@ -33,7 +32,6 @@ def make_default_theme_icons_action(target, source, env):
icons_string.write(",")
icons_string.write("\n")
s = StringIO()
s.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n\n")
s.write('#include "modules/modules_enabled.gen.h"\n\n')
s.write("#ifndef _DEFAULT_THEME_ICONS_H\n")
@ -68,9 +66,6 @@ def make_default_theme_icons_action(target, source, env):
with open(dst, "w", encoding="utf-8", newline="\n") as f:
f.write(s.getvalue())
s.close()
icons_string.close()
if __name__ == "__main__":
subprocess_main(globals())