summaryrefslogtreecommitdiffstats
path: root/core/extension
diff options
context:
space:
mode:
authorThaddeus Crews <repiteo@outlook.com>2024-03-10 12:09:48 -0500
committerThaddeus Crews <repiteo@outlook.com>2024-03-10 12:57:57 -0500
commitfb299d0fb134c603eafe7737bab8d22ec0b1cd59 (patch)
tree7f8bfac3259a5c6f55d09c5e041357e98b3c7fe9 /core/extension
parent0ace0a129284ffc6646b199699c1607a316fcec0 (diff)
downloadredot-engine-fb299d0fb134c603eafe7737bab8d22ec0b1cd59.tar.gz
SCons: Ensure `with` statement where applicable
Diffstat (limited to 'core/extension')
-rw-r--r--core/extension/make_interface_dumper.py40
1 files changed, 18 insertions, 22 deletions
diff --git a/core/extension/make_interface_dumper.py b/core/extension/make_interface_dumper.py
index f5662bdbbb..87f9a71522 100644
--- a/core/extension/make_interface_dumper.py
+++ b/core/extension/make_interface_dumper.py
@@ -4,18 +4,16 @@ 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)
- buf = f.read()
- decomp_size = len(buf)
+ # Use maximum zlib compression level to further reduce file size
+ # (at the cost of initial build times).
+ buf = zlib.compress(buf, zlib.Z_BEST_COMPRESSION)
- # Use maximum zlib compression level to further reduce file size
- # (at the cost of initial build times).
- buf = zlib.compress(buf, zlib.Z_BEST_COMPRESSION)
-
- g.write(
- """/* THIS FILE IS GENERATED DO NOT EDIT */
+ g.write(
+ """/* THIS FILE IS GENERATED DO NOT EDIT */
#ifndef GDEXTENSION_INTERFACE_DUMP_H
#define GDEXTENSION_INTERFACE_DUMP_H
@@ -26,17 +24,17 @@ def run(target, source, env):
#include "core/string/ustring.h"
"""
- )
+ )
- g.write("static const int _gdextension_interface_data_compressed_size = " + str(len(buf)) + ";\n")
- g.write("static const int _gdextension_interface_data_uncompressed_size = " + str(decomp_size) + ";\n")
- g.write("static const unsigned char _gdextension_interface_data_compressed[] = {\n")
- for i in range(len(buf)):
- g.write("\t" + str(buf[i]) + ",\n")
- g.write("};\n")
+ g.write("static const int _gdextension_interface_data_compressed_size = " + str(len(buf)) + ";\n")
+ g.write("static const int _gdextension_interface_data_uncompressed_size = " + str(decomp_size) + ";\n")
+ g.write("static const unsigned char _gdextension_interface_data_compressed[] = {\n")
+ for i in range(len(buf)):
+ g.write("\t" + str(buf[i]) + ",\n")
+ g.write("};\n")
- g.write(
- """
+ g.write(
+ """
class GDExtensionInterfaceDump {
public:
static void generate_gdextension_interface_file(const String &p_path) {
@@ -54,9 +52,7 @@ class GDExtensionInterfaceDump {
#endif // GDEXTENSION_INTERFACE_DUMP_H
"""
- )
- g.close()
- f.close()
+ )
if __name__ == "__main__":