From fb299d0fb134c603eafe7737bab8d22ec0b1cd59 Mon Sep 17 00:00:00 2001 From: Thaddeus Crews Date: Sun, 10 Mar 2024 12:09:48 -0500 Subject: SCons: Ensure `with` statement where applicable --- modules/text_server_adv/SCsub | 41 +++++----- .../text_server_adv/gdextension_build/methods.py | 92 +++++++++++----------- 2 files changed, 66 insertions(+), 67 deletions(-) (limited to 'modules/text_server_adv') diff --git a/modules/text_server_adv/SCsub b/modules/text_server_adv/SCsub index 79950eaac3..6b53353ec9 100644 --- a/modules/text_server_adv/SCsub +++ b/modules/text_server_adv/SCsub @@ -9,27 +9,26 @@ 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") - - 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") - g.write("#ifndef _ICU_DATA_H\n") - g.write("#define _ICU_DATA_H\n") - g.write('#include "unicode/utypes.h"\n') - g.write('#include "unicode/udata.h"\n') - g.write('#include "unicode/uversion.h"\n') - - f = open(source[0].srcnode().abspath, "rb") - buf = f.read() - - g.write('extern "C" U_EXPORT const size_t U_ICUDATA_SIZE = ' + str(len(buf)) + ";\n") - g.write('extern "C" U_EXPORT const unsigned char U_ICUDATA_ENTRY_POINT[] = {\n') - for i in range(len(buf)): - g.write("\t" + str(buf[i]) + ",\n") - - g.write("};\n") - g.write("#endif") + 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") + g.write("#ifndef _ICU_DATA_H\n") + g.write("#define _ICU_DATA_H\n") + g.write('#include "unicode/utypes.h"\n') + g.write('#include "unicode/udata.h"\n') + g.write('#include "unicode/uversion.h"\n') + + 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") + g.write('extern "C" U_EXPORT const unsigned char U_ICUDATA_ENTRY_POINT[] = {\n') + for i in range(len(buf)): + g.write("\t" + str(buf[i]) + ",\n") + + g.write("};\n") + g.write("#endif") # Thirdparty source files diff --git a/modules/text_server_adv/gdextension_build/methods.py b/modules/text_server_adv/gdextension_build/methods.py index 8456149973..32dbc59fd4 100644 --- a/modules/text_server_adv/gdextension_build/methods.py +++ b/modules/text_server_adv/gdextension_build/methods.py @@ -83,56 +83,56 @@ 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") + g.write("#ifndef _ICU_DATA_H\n") + g.write("#define _ICU_DATA_H\n") + g.write('#include "unicode/utypes.h"\n') + g.write('#include "unicode/udata.h"\n') + g.write('#include "unicode/uversion.h"\n') - 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") - g.write("#ifndef _ICU_DATA_H\n") - g.write("#define _ICU_DATA_H\n") - g.write('#include "unicode/utypes.h"\n') - g.write('#include "unicode/udata.h"\n') - g.write('#include "unicode/uversion.h"\n') + with open(source[0].srcnode().abspath, "rb") as f: + buf = f.read() - f = open(source[0].srcnode().abspath, "rb") - buf = f.read() + g.write('extern "C" U_EXPORT const size_t U_ICUDATA_SIZE = ' + str(len(buf)) + ";\n") + g.write('extern "C" U_EXPORT const unsigned char U_ICUDATA_ENTRY_POINT[] = {\n') + for i in range(len(buf)): + g.write("\t" + str(buf[i]) + ",\n") - g.write('extern "C" U_EXPORT const size_t U_ICUDATA_SIZE = ' + str(len(buf)) + ";\n") - g.write('extern "C" U_EXPORT const unsigned char U_ICUDATA_ENTRY_POINT[] = {\n') - for i in range(len(buf)): - g.write("\t" + str(buf[i]) + ",\n") - - g.write("};\n") - g.write("#endif") + g.write("};\n") + g.write("#endif") 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") - - f.write(f'\n') - f.write(f'\n') - f.write(f'\n') - f.write(f"\n") - f.write(f"\tCFBundleExecutable\n") - f.write(f"\t{binary_name}\n") - f.write(f"\tCFBundleIdentifier\n") - f.write(f"\t{identifier}\n") - f.write(f"\tCFBundleInfoDictionaryVersion\n") - f.write(f"\t6.0\n") - f.write(f"\tCFBundleName\n") - f.write(f"\t{name}\n") - f.write(f"\tCFBundlePackageType\n") - f.write(f"\tFMWK\n") - f.write(f"\tCFBundleShortVersionString\n") - f.write(f"\t1.0.0\n") - f.write(f"\tCFBundleSupportedPlatforms\n") - f.write(f"\t\n") - f.write(f"\t\tMacOSX\n") - f.write(f"\t\n") - f.write(f"\tCFBundleVersion\n") - f.write(f"\t1.0.0\n") - f.write(f"\tLSMinimumSystemVersion\n") - f.write(f"\t10.14\n") - f.write(f"\n") - f.write(f"\n") + with open(f"{target}/Resource/Info.plist", "w", encoding="utf-8", newline="\n") as f: + f.write(f'\n') + f.write( + f'\n' + ) + f.write(f'\n') + f.write(f"\n") + f.write(f"\tCFBundleExecutable\n") + f.write(f"\t{binary_name}\n") + f.write(f"\tCFBundleIdentifier\n") + f.write(f"\t{identifier}\n") + f.write(f"\tCFBundleInfoDictionaryVersion\n") + f.write(f"\t6.0\n") + f.write(f"\tCFBundleName\n") + f.write(f"\t{name}\n") + f.write(f"\tCFBundlePackageType\n") + f.write(f"\tFMWK\n") + f.write(f"\tCFBundleShortVersionString\n") + f.write(f"\t1.0.0\n") + f.write(f"\tCFBundleSupportedPlatforms\n") + f.write(f"\t\n") + f.write(f"\t\tMacOSX\n") + f.write(f"\t\n") + f.write(f"\tCFBundleVersion\n") + f.write(f"\t1.0.0\n") + f.write(f"\tLSMinimumSystemVersion\n") + f.write(f"\t10.14\n") + f.write(f"\n") + f.write(f"\n") -- cgit v1.2.3