Skip to content

Commit d9fa40f

Browse files
committed
Enforce \n eol for Python writes
• Ensure utf-8 encoding if previously unspecified
1 parent f289648 commit d9fa40f

30 files changed

+63
-59
lines changed

core/SCsub

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ if "SCRIPT_AES256_ENCRYPTION_KEY" in os.environ:
3636
Exit(255)
3737

3838
# NOTE: It is safe to generate this file here, since this is still executed serially
39-
with open("script_encryption_key.gen.cpp", "w") as f:
39+
with open("script_encryption_key.gen.cpp", "w", encoding="utf-8", newline="\n") as f:
4040
f.write('#include "core/config/project_settings.h"\nuint8_t script_encryption_key[32]={' + txt + "};\n")
4141

4242

core/core_builders.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def make_certs_header(target, source, env):
3232
src = source[0]
3333
dst = target[0]
3434
f = open(src, "rb")
35-
g = open(dst, "w", encoding="utf-8")
35+
g = open(dst, "w", encoding="utf-8", newline="\n")
3636
buf = f.read()
3737
decomp_size = len(buf)
3838

@@ -79,7 +79,7 @@ def make_authors_header(target, source, env):
7979
src = source[0]
8080
dst = target[0]
8181
f = open(src, "r", encoding="utf-8")
82-
g = open(dst, "w", encoding="utf-8")
82+
g = open(dst, "w", encoding="utf-8", newline="\n")
8383

8484
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
8585
g.write("#ifndef AUTHORS_GEN_H\n")
@@ -141,7 +141,7 @@ def make_donors_header(target, source, env):
141141
src = source[0]
142142
dst = target[0]
143143
f = open(src, "r", encoding="utf-8")
144-
g = open(dst, "w", encoding="utf-8")
144+
g = open(dst, "w", encoding="utf-8", newline="\n")
145145

146146
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
147147
g.write("#ifndef DONORS_GEN_H\n")
@@ -239,7 +239,7 @@ def next_tag(self):
239239
part["copyright_index"] = len(data_list)
240240
data_list += part["Copyright"]
241241

242-
with open(dst, "w", encoding="utf-8") as f:
242+
with open(dst, "w", encoding="utf-8", newline="\n") as f:
243243
f.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
244244
f.write("#ifndef LICENSE_GEN_H\n")
245245
f.write("#define LICENSE_GEN_H\n")

core/extension/make_interface_dumper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def run(target, source, env):
55
src = source[0]
66
dst = target[0]
77
f = open(src, "rb")
8-
g = open(dst, "w", encoding="utf-8")
8+
g = open(dst, "w", encoding="utf-8", newline="\n")
99

1010
buf = f.read()
1111
decomp_size = len(buf)

core/extension/make_wrappers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def run(target, source, env):
142142

143143
txt += "\n#endif\n"
144144

145-
with open(target[0], "w") as f:
145+
with open(target[0], "w", encoding="utf-8", newline="\n") as f:
146146
f.write(txt)
147147

148148

core/input/input_builders.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
def make_default_controller_mappings(target, source, env):
1111
dst = target[0]
12-
g = open(dst, "w")
12+
g = open(dst, "w", encoding="utf-8", newline="\n")
1313

1414
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
1515
g.write('#include "core/typedefs.h"\n')

core/object/make_virtuals.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def run(target, source, env):
201201

202202
txt += "#endif // GDVIRTUAL_GEN_H\n"
203203

204-
with open(target[0], "w") as f:
204+
with open(target[0], "w", encoding="utf-8", newline="\n") as f:
205205
f.write(txt)
206206

207207

doc/tools/make_rst.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,9 @@ def make_rst_class(class_def: ClassDef, state: State, dry_run: bool, output_dir:
891891
class_name = class_def.name
892892

893893
if dry_run:
894-
f = open(os.devnull, "w", encoding="utf-8")
894+
f = open(os.devnull, "w", encoding="utf-8", newline="\n")
895895
else:
896-
f = open(os.path.join(output_dir, f"class_{class_name.lower()}.rst"), "w", encoding="utf-8")
896+
f = open(os.path.join(output_dir, f"class_{class_name.lower()}.rst"), "w", encoding="utf-8", newline="\n")
897897

898898
# Remove the "Edit on Github" button from the online docs page.
899899
f.write(":github_url: hide\n\n")
@@ -1691,9 +1691,9 @@ def make_link(url: str, title: str) -> str:
16911691

16921692
def make_rst_index(grouped_classes: Dict[str, List[str]], dry_run: bool, output_dir: str) -> None:
16931693
if dry_run:
1694-
f = open(os.devnull, "w", encoding="utf-8")
1694+
f = open(os.devnull, "w", encoding="utf-8", newline="\n")
16951695
else:
1696-
f = open(os.path.join(output_dir, "index.rst"), "w", encoding="utf-8")
1696+
f = open(os.path.join(output_dir, "index.rst"), "w", encoding="utf-8", newline="\n")
16971697

16981698
# Remove the "Edit on Github" button from the online docs page, and disallow user-contributed notes
16991699
# on the index page. User-contributed notes are allowed on individual class pages.

editor/SCsub

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import editor_builders
1111

1212
def _make_doc_data_class_path(to_path):
1313
# NOTE: It is safe to generate this file here, since this is still executed serially
14-
g = open(os.path.join(to_path, "doc_data_class_path.gen.h"), "w", encoding="utf-8")
14+
g = open(os.path.join(to_path, "doc_data_class_path.gen.h"), "w", encoding="utf-8", newline="\n")
1515
g.write("static const int _doc_data_class_path_count = " + str(len(env.doc_class_path)) + ";\n")
1616
g.write("struct _DocDataClassPath { const char* name; const char* path; };\n")
1717

@@ -41,7 +41,7 @@ if env.editor_build:
4141
reg_exporters += "}\n"
4242

4343
# NOTE: It is safe to generate this file here, since this is still executed serially
44-
with open("register_exporters.gen.cpp", "w", encoding="utf-8") as f:
44+
with open("register_exporters.gen.cpp", "w", encoding="utf-8", newline="\n") as f:
4545
f.write(reg_exporters_inc)
4646
f.write(reg_exporters)
4747

editor/editor_builders.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
def make_doc_header(target, source, env):
1818
dst = target[0]
19-
g = open(dst, "w", encoding="utf-8")
19+
g = open(dst, "w", encoding="utf-8", newline="\n")
2020
buf = ""
2121
docbegin = ""
2222
docend = ""
@@ -53,7 +53,7 @@ def make_doc_header(target, source, env):
5353
def make_translations_header(target, source, env, category):
5454
dst = target[0]
5555

56-
g = open(dst, "w", encoding="utf-8")
56+
g = open(dst, "w", encoding="utf-8", newline="\n")
5757

5858
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
5959
g.write("#ifndef _{}_TRANSLATIONS_H\n".format(category.upper()))

editor/icons/editor_icons_builders.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def make_editor_icons_action(target, source, env):
8585

8686
s.write("#endif\n")
8787

88-
with open(dst, "w") as f:
88+
with open(dst, "w", encoding="utf-8", newline="\n") as f:
8989
f.write(s.getvalue())
9090

9191
s.close()

editor/template_builders.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def make_templates(target, source, env):
8585

8686
s.write("\n#endif\n")
8787

88-
with open(dst, "w") as f:
88+
with open(dst, "w", encoding="utf-8", newline="\n") as f:
8989
f.write(s.getvalue())
9090

9191
s.close()

editor/themes/editor_theme_builders.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
def make_fonts_header(target, source, env):
1313
dst = target[0]
1414

15-
g = open(dst, "w", encoding="utf-8")
15+
g = open(dst, "w", encoding="utf-8", newline="\n")
1616

1717
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
1818
g.write("#ifndef _EDITOR_FONTS_H\n")

gles3_builders.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def build_gles3_header(
211211
else:
212212
out_file = optional_output_filename
213213

214-
fd = open(out_file, "w")
214+
fd = open(out_file, "w", encoding="utf-8", newline="\n")
215215
defspec = 0
216216
defvariant = ""
217217

glsl_builders.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class {out_file_class} : public ShaderRD {{
165165
#endif
166166
"""
167167

168-
with open(out_file, "w") as fd:
168+
with open(out_file, "w", encoding="utf-8", newline="\n") as fd:
169169
fd.write(shader_template)
170170

171171

@@ -224,7 +224,7 @@ def build_raw_header(
224224
#endif
225225
"""
226226

227-
with open(out_file, "w") as f:
227+
with open(out_file, "w", encoding="utf-8", newline="\n") as f:
228228
f.write(shader_template)
229229

230230

main/main_builders.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def make_splash(target, source, env):
1414
with open(src, "rb") as f:
1515
buf = f.read()
1616

17-
with open(dst, "w") as g:
17+
with open(dst, "w", encoding="utf-8", newline="\n") as g:
1818
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
1919
g.write("#ifndef BOOT_SPLASH_H\n")
2020
g.write("#define BOOT_SPLASH_H\n")
@@ -34,7 +34,7 @@ def make_splash_editor(target, source, env):
3434
with open(src, "rb") as f:
3535
buf = f.read()
3636

37-
with open(dst, "w") as g:
37+
with open(dst, "w", encoding="utf-8", newline="\n") as g:
3838
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
3939
g.write("#ifndef BOOT_SPLASH_EDITOR_H\n")
4040
g.write("#define BOOT_SPLASH_EDITOR_H\n")
@@ -55,7 +55,7 @@ def make_app_icon(target, source, env):
5555
with open(src, "rb") as f:
5656
buf = f.read()
5757

58-
with open(dst, "w") as g:
58+
with open(dst, "w", encoding="utf-8", newline="\n") as g:
5959
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
6060
g.write("#ifndef APP_ICON_H\n")
6161
g.write("#define APP_ICON_H\n")

methods.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def generate_version_header(module_version_string=""):
230230

231231
# NOTE: It is safe to generate these files here, since this is still executed serially.
232232

233-
f = open("core/version_generated.gen.h", "w")
233+
f = open("core/version_generated.gen.h", "w", encoding="utf-8", newline="\n")
234234
f.write(
235235
"""/* THIS FILE IS GENERATED DO NOT EDIT */
236236
#ifndef VERSION_GENERATED_GEN_H
@@ -253,7 +253,7 @@ def generate_version_header(module_version_string=""):
253253
)
254254
f.close()
255255

256-
fhash = open("core/version_hash.gen.cpp", "w")
256+
fhash = open("core/version_hash.gen.cpp", "w", encoding="utf-8", newline="\n")
257257
fhash.write(
258258
"""/* THIS FILE IS GENERATED DO NOT EDIT */
259259
#include "core/version.h"
@@ -384,7 +384,7 @@ def is_module(path):
384384

385385

386386
def write_disabled_classes(class_list):
387-
f = open("core/disabled_classes.gen.h", "w")
387+
f = open("core/disabled_classes.gen.h", "w", encoding="utf-8", newline="\n")
388388
f.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
389389
f.write("#ifndef DISABLED_CLASSES_GEN_H\n")
390390
f.write("#define DISABLED_CLASSES_GEN_H\n\n")
@@ -435,7 +435,7 @@ def write_modules(modules):
435435
)
436436

437437
# NOTE: It is safe to generate this file here, since this is still executed serially
438-
with open("modules/register_module_types.gen.cpp", "w") as f:
438+
with open("modules/register_module_types.gen.cpp", "w", encoding="utf-8", newline="\n") as f:
439439
f.write(modules_cpp)
440440

441441

@@ -757,7 +757,7 @@ def generate_cpp_hint_file(filename):
757757
pass
758758
else:
759759
try:
760-
with open(filename, "w") as fd:
760+
with open(filename, "w", encoding="utf-8", newline="\n") as fd:
761761
fd.write("#define GDCLASS(m_class, m_inherits)\n")
762762
except OSError:
763763
print("Could not write cpp.hint file.")
@@ -1062,7 +1062,7 @@ def get_size(self, start_path="."):
10621062
def progress_finish(target, source, env):
10631063
nonlocal node_count, progressor
10641064
try:
1065-
with open(node_count_fname, "w") as f:
1065+
with open(node_count_fname, "w", encoding="utf-8", newline="\n") as f:
10661066
f.write("%d\n" % node_count)
10671067
progressor.delete(progressor.file_list())
10681068
except Exception:
@@ -1092,7 +1092,7 @@ def dump(env):
10921092
def non_serializable(obj):
10931093
return "<<non-serializable: %s>>" % (type(obj).__qualname__)
10941094

1095-
with open(".scons_env.json", "w") as f:
1095+
with open(".scons_env.json", "w", encoding="utf-8", newline="\n") as f:
10961096
dump(env.Dictionary(), f, indent=4, default=non_serializable)
10971097

10981098

@@ -1294,7 +1294,7 @@ def format_key_value(v):
12941294

12951295
filters_template = filters_template.replace("%%HASH%%", md5)
12961296

1297-
with open(f"{project_name}.vcxproj.filters", "w") as f:
1297+
with open(f"{project_name}.vcxproj.filters", "w", encoding="utf-8", newline="\n") as f:
12981298
f.write(filters_template)
12991299

13001300
envsources = []
@@ -1469,7 +1469,9 @@ def format_key_value(v):
14691469
cmd = " ^&amp; ".join(common_build_prefix + [" ".join([commands] + cmd_clean)])
14701470
props_template = props_template.replace("%%CLEAN%%", cmd)
14711471

1472-
with open(f"{project_name}.{platform}.{target}.{arch}.generated.props", "w") as f:
1472+
with open(
1473+
f"{project_name}.{platform}.{target}.{arch}.generated.props", "w", encoding="utf-8", newline="\n"
1474+
) as f:
14731475
f.write(props_template)
14741476

14751477
proj_uuid = str(uuid.uuid4())
@@ -1572,7 +1574,7 @@ def format_key_value(v):
15721574
proj_template = proj_template.replace("%%DEFAULT_ITEMS%%", "\n ".join(all_items))
15731575
proj_template = proj_template.replace("%%PROPERTIES%%", "\n ".join(properties))
15741576

1575-
with open(f"{project_name}.vcxproj", "w") as f:
1577+
with open(f"{project_name}.vcxproj", "w", encoding="utf-8", newline="\n") as f:
15761578
f.write(proj_template)
15771579

15781580
if not get_bool(original_args, "vsproj_props_only", False):
@@ -1583,7 +1585,7 @@ def format_key_value(v):
15831585
sln_template = sln_template.replace("%%SECTION1%%", "\n ".join(section1))
15841586
sln_template = sln_template.replace("%%SECTION2%%", "\n ".join(section2))
15851587

1586-
with open(f"{project_name}.sln", "w") as f:
1588+
with open(f"{project_name}.sln", "w", encoding="utf-8", newline="\n") as f:
15871589
f.write(sln_template)
15881590

15891591
if get_bool(original_args, "vsproj_gen_only", True):

misc/scripts/copyright_headers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,6 @@
9090
fileread.close()
9191

9292
# Write
93-
filewrite = open(fname.strip(), "w")
93+
filewrite = open(fname.strip(), "w", encoding="utf-8", newline="\n")
9494
filewrite.write(text)
9595
filewrite.close()

misc/scripts/dotnet_format.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"modules/mono/SdkPackageVersions.props",
1111
]:
1212
os.makedirs(os.path.dirname(path), exist_ok=True)
13-
with open(path, "w") as f:
13+
with open(path, "w", encoding="utf-8", newline="\n") as f:
1414
f.write("<Project />")
1515

1616
# Avoid importing GeneratedIncludes.props.

modules/modules_builders.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88

99
def generate_modules_enabled(target, source, env):
10-
with open(target[0].path, "w") as f:
10+
with open(target[0].path, "w", encoding="utf-8", newline="\n") as f:
1111
for module in env.module_list:
1212
f.write("#define %s\n" % ("MODULE_" + module.upper() + "_ENABLED"))
1313

1414

1515
def generate_modules_tests(target, source, env):
1616
import os
1717

18-
with open(target[0].path, "w") as f:
18+
with open(target[0].path, "w", encoding="utf-8", newline="\n") as f:
1919
for header in source:
2020
f.write('#include "%s"\n' % (os.path.normpath(header.path)))
2121

modules/mono/build_scripts/build_assemblies.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def generate_sdk_package_versions():
312312
)
313313

314314
# We write in ../SdkPackageVersions.props.
315-
with open(os.path.join(dirname(script_path), "SdkPackageVersions.props"), "w", encoding="utf-8") as f:
315+
with open(os.path.join(dirname(script_path), "SdkPackageVersions.props"), "w", encoding="utf-8", newline="\n") as f:
316316
f.write(props)
317317
f.close()
318318

@@ -340,7 +340,7 @@ def generate_sdk_package_versions():
340340
)
341341
os.makedirs(generators_dir, exist_ok=True)
342342

343-
with open(os.path.join(generators_dir, "Common.Constants.cs"), "w", newline="\n", encoding="utf-8") as f:
343+
with open(os.path.join(generators_dir, "Common.Constants.cs"), "w", encoding="utf-8", newline="\n") as f:
344344
f.write(constants)
345345
f.close()
346346

0 commit comments

Comments
 (0)