Skip to content

Commit

Permalink
Merge pull request godotengine#89333 from Repiteo/enforce-eol-python
Browse files Browse the repository at this point in the history
Enforce `\n` eol for Python writes
  • Loading branch information
akien-mga committed Mar 9, 2024
2 parents 7d6ae13 + d9fa40f commit 0ace0a1
Show file tree
Hide file tree
Showing 30 changed files with 63 additions and 59 deletions.
2 changes: 1 addition & 1 deletion core/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if "SCRIPT_AES256_ENCRYPTION_KEY" in os.environ:
Exit(255)

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


Expand Down
8 changes: 4 additions & 4 deletions core/core_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def make_certs_header(target, source, env):
src = source[0]
dst = target[0]
f = open(src, "rb")
g = open(dst, "w", encoding="utf-8")
g = open(dst, "w", encoding="utf-8", newline="\n")
buf = f.read()
decomp_size = len(buf)

Expand Down Expand Up @@ -79,7 +79,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")
g = open(dst, "w", encoding="utf-8", newline="\n")

g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("#ifndef AUTHORS_GEN_H\n")
Expand Down Expand Up @@ -141,7 +141,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")
g = open(dst, "w", encoding="utf-8", newline="\n")

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

with open(dst, "w", encoding="utf-8") as f:
with open(dst, "w", encoding="utf-8", newline="\n") as f:
f.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
f.write("#ifndef LICENSE_GEN_H\n")
f.write("#define LICENSE_GEN_H\n")
Expand Down
2 changes: 1 addition & 1 deletion core/extension/make_interface_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def run(target, source, env):
src = source[0]
dst = target[0]
f = open(src, "rb")
g = open(dst, "w", encoding="utf-8")
g = open(dst, "w", encoding="utf-8", newline="\n")

buf = f.read()
decomp_size = len(buf)
Expand Down
2 changes: 1 addition & 1 deletion core/extension/make_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def run(target, source, env):

txt += "\n#endif\n"

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


Expand Down
2 changes: 1 addition & 1 deletion core/input/input_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write('#include "core/typedefs.h"\n')
Expand Down
2 changes: 1 addition & 1 deletion core/object/make_virtuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def run(target, source, env):

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

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


Expand Down
8 changes: 4 additions & 4 deletions doc/tools/make_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,9 @@ def make_rst_class(class_def: ClassDef, state: State, dry_run: bool, output_dir:
class_name = class_def.name

if dry_run:
f = open(os.devnull, "w", encoding="utf-8")
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")
f = open(os.path.join(output_dir, f"class_{class_name.lower()}.rst"), "w", encoding="utf-8", newline="\n")

# Remove the "Edit on Github" button from the online docs page.
f.write(":github_url: hide\n\n")
Expand Down Expand Up @@ -1691,9 +1691,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")
f = open(os.devnull, "w", encoding="utf-8", newline="\n")
else:
f = open(os.path.join(output_dir, "index.rst"), "w", encoding="utf-8")
f = open(os.path.join(output_dir, "index.rst"), "w", encoding="utf-8", newline="\n")

# 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.
Expand Down
4 changes: 2 additions & 2 deletions editor/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -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")
g = open(os.path.join(to_path, "doc_data_class_path.gen.h"), "w", encoding="utf-8", newline="\n")
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")

Expand Down Expand Up @@ -41,7 +41,7 @@ if env.editor_build:
reg_exporters += "}\n"

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

Expand Down
4 changes: 2 additions & 2 deletions editor/editor_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

def make_doc_header(target, source, env):
dst = target[0]
g = open(dst, "w", encoding="utf-8")
g = open(dst, "w", encoding="utf-8", newline="\n")
buf = ""
docbegin = ""
docend = ""
Expand Down Expand Up @@ -53,7 +53,7 @@ def make_doc_header(target, source, env):
def make_translations_header(target, source, env, category):
dst = target[0]

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

g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("#ifndef _{}_TRANSLATIONS_H\n".format(category.upper()))
Expand Down
2 changes: 1 addition & 1 deletion editor/icons/editor_icons_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def make_editor_icons_action(target, source, env):

s.write("#endif\n")

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

s.close()
Expand Down
2 changes: 1 addition & 1 deletion editor/template_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def make_templates(target, source, env):

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

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

s.close()
Expand Down
2 changes: 1 addition & 1 deletion editor/themes/editor_theme_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def make_fonts_header(target, source, env):
dst = target[0]

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

g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("#ifndef _EDITOR_FONTS_H\n")
Expand Down
2 changes: 1 addition & 1 deletion gles3_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def build_gles3_header(
else:
out_file = optional_output_filename

fd = open(out_file, "w")
fd = open(out_file, "w", encoding="utf-8", newline="\n")
defspec = 0
defvariant = ""

Expand Down
4 changes: 2 additions & 2 deletions glsl_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class {out_file_class} : public ShaderRD {{
#endif
"""

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


Expand Down Expand Up @@ -224,7 +224,7 @@ def build_raw_header(
#endif
"""

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


Expand Down
6 changes: 3 additions & 3 deletions main/main_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def make_splash(target, source, env):
with open(src, "rb") as f:
buf = f.read()

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

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

with open(dst, "w") as g:
with open(dst, "w", encoding="utf-8", newline="\n") as g:
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
g.write("#ifndef APP_ICON_H\n")
g.write("#define APP_ICON_H\n")
Expand Down
24 changes: 13 additions & 11 deletions methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ 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")
f = open("core/version_generated.gen.h", "w", encoding="utf-8", newline="\n")
f.write(
"""/* THIS FILE IS GENERATED DO NOT EDIT */
#ifndef VERSION_GENERATED_GEN_H
Expand All @@ -253,7 +253,7 @@ def generate_version_header(module_version_string=""):
)
f.close()

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


def write_disabled_classes(class_list):
f = open("core/disabled_classes.gen.h", "w")
f = open("core/disabled_classes.gen.h", "w", encoding="utf-8", newline="\n")
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")
Expand Down Expand Up @@ -435,7 +435,7 @@ def write_modules(modules):
)

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


Expand Down Expand Up @@ -757,7 +757,7 @@ def generate_cpp_hint_file(filename):
pass
else:
try:
with open(filename, "w") as fd:
with open(filename, "w", encoding="utf-8", newline="\n") as fd:
fd.write("#define GDCLASS(m_class, m_inherits)\n")
except OSError:
print("Could not write cpp.hint file.")
Expand Down Expand Up @@ -1062,7 +1062,7 @@ def get_size(self, start_path="."):
def progress_finish(target, source, env):
nonlocal node_count, progressor
try:
with open(node_count_fname, "w") as f:
with open(node_count_fname, "w", encoding="utf-8", newline="\n") as f:
f.write("%d\n" % node_count)
progressor.delete(progressor.file_list())
except Exception:
Expand Down Expand Up @@ -1092,7 +1092,7 @@ def dump(env):
def non_serializable(obj):
return "<<non-serializable: %s>>" % (type(obj).__qualname__)

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


Expand Down Expand Up @@ -1294,7 +1294,7 @@ def format_key_value(v):

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

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

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

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

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

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

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

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

if get_bool(original_args, "vsproj_gen_only", True):
Expand Down
2 changes: 1 addition & 1 deletion misc/scripts/copyright_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@
fileread.close()

# Write
filewrite = open(fname.strip(), "w")
filewrite = open(fname.strip(), "w", encoding="utf-8", newline="\n")
filewrite.write(text)
filewrite.close()
2 changes: 1 addition & 1 deletion misc/scripts/dotnet_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"modules/mono/SdkPackageVersions.props",
]:
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "w") as f:
with open(path, "w", encoding="utf-8", newline="\n") as f:
f.write("<Project />")

# Avoid importing GeneratedIncludes.props.
Expand Down
4 changes: 2 additions & 2 deletions modules/modules_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@


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


def generate_modules_tests(target, source, env):
import os

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

Expand Down
4 changes: 2 additions & 2 deletions modules/mono/build_scripts/build_assemblies.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def generate_sdk_package_versions():
)

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

Expand Down Expand Up @@ -340,7 +340,7 @@ def generate_sdk_package_versions():
)
os.makedirs(generators_dir, exist_ok=True)

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

Expand Down
Loading

0 comments on commit 0ace0a1

Please sign in to comment.