Skip to content

Commit 3d2dd79

Browse files
committed
SCons: Drop support for Python 2
We now require SCons 3.0+ (first version with Python 3 support), and we set min required Python 3 version to 3.5 (3.4 and earlier are EOL).
1 parent 35e700e commit 3d2dd79

14 files changed

+61
-133
lines changed

SConstruct

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22

3-
EnsureSConsVersion(0, 98, 1)
3+
EnsureSConsVersion(3, 0, 0)
4+
EnsurePythonVersion(3, 5)
45

56
# System
67
import glob
@@ -13,7 +14,7 @@ import methods
1314
import gles_builders
1415
from platform_methods import run_in_subprocess
1516

16-
# scan possible build platforms
17+
# Scan possible build platforms
1718

1819
platform_list = [] # list of platforms
1920
platform_opts = {} # options for each platform

compat.py

-68
This file was deleted.

core/core_builders.py

+32-14
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,33 @@
44
"""
55

66
from platform_methods import subprocess_main
7-
from compat import iteritems, itervalues, open_utf8, escape_string, byte_to_str
87

98

10-
def make_certs_header(target, source, env):
9+
def escape_string(s):
10+
def charcode_to_c_escapes(c):
11+
rev_result = []
12+
while c >= 256:
13+
c, low = (c // 256, c % 256)
14+
rev_result.append('\\%03o' % low)
15+
rev_result.append('\\%03o' % c)
16+
return ''.join(reversed(rev_result))
17+
18+
result = ''
19+
if isinstance(s, str):
20+
s = s.encode('utf-8')
21+
for c in s:
22+
if not(32 <= c < 127) or c in (ord('\\'), ord('"')):
23+
result += charcode_to_c_escapes(c)
24+
else:
25+
result += chr(c)
26+
return result
1127

28+
29+
def make_certs_header(target, source, env):
1230
src = source[0]
1331
dst = target[0]
1432
f = open(src, "rb")
15-
g = open_utf8(dst, "w")
33+
g = open(dst, "w", encoding="utf-8")
1634
buf = f.read()
1735
decomp_size = len(buf)
1836
import zlib
@@ -32,7 +50,7 @@ def make_certs_header(target, source, env):
3250
g.write("static const int _certs_uncompressed_size = " + str(decomp_size) + ";\n")
3351
g.write("static const unsigned char _certs_compressed[] = {\n")
3452
for i in range(len(buf)):
35-
g.write("\t" + byte_to_str(buf[i]) + ",\n")
53+
g.write("\t" + str(buf[i]) + ",\n")
3654
g.write("};\n")
3755
g.write("#endif // CERTS_COMPRESSED_GEN_H")
3856

@@ -46,8 +64,8 @@ def make_authors_header(target, source, env):
4664

4765
src = source[0]
4866
dst = target[0]
49-
f = open_utf8(src, "r")
50-
g = open_utf8(dst, "w")
67+
f = open(src, "r", encoding="utf-8")
68+
g = open(dst, "w", encoding="utf-8")
5169

5270
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
5371
g.write("#ifndef AUTHORS_GEN_H\n")
@@ -92,8 +110,8 @@ def make_donors_header(target, source, env):
92110

93111
src = source[0]
94112
dst = target[0]
95-
f = open_utf8(src, "r")
96-
g = open_utf8(dst, "w")
113+
f = open(src, "r", encoding="utf-8")
114+
g = open(dst, "w", encoding="utf-8")
97115

98116
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
99117
g.write("#ifndef DONORS_GEN_H\n")
@@ -163,7 +181,7 @@ def next_tag(self):
163181
projects = OrderedDict()
164182
license_list = []
165183

166-
with open_utf8(src_copyright, "r") as copyright_file:
184+
with open(src_copyright, "r", encoding="utf-8") as copyright_file:
167185
reader = LicenseReader(copyright_file)
168186
part = {}
169187
while reader.current:
@@ -183,21 +201,21 @@ def next_tag(self):
183201
reader.next_line()
184202

185203
data_list = []
186-
for project in itervalues(projects):
204+
for project in iter(projects.values()):
187205
for part in project:
188206
part["file_index"] = len(data_list)
189207
data_list += part["Files"]
190208
part["copyright_index"] = len(data_list)
191209
data_list += part["Copyright"]
192210

193-
with open_utf8(dst, "w") as f:
211+
with open(dst, "w", encoding="utf-8") as f:
194212

195213
f.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
196214
f.write("#ifndef LICENSE_GEN_H\n")
197215
f.write("#define LICENSE_GEN_H\n")
198216
f.write("const char *const GODOT_LICENSE_TEXT =")
199217

200-
with open_utf8(src_license, "r") as license_file:
218+
with open(src_license, "r", encoding="utf-8") as license_file:
201219
for line in license_file:
202220
escaped_string = escape_string(line.strip())
203221
f.write("\n\t\t\"" + escaped_string + "\\n\"")
@@ -225,7 +243,7 @@ def next_tag(self):
225243
f.write("const ComponentCopyrightPart COPYRIGHT_PROJECT_PARTS[] = {\n")
226244
part_index = 0
227245
part_indexes = {}
228-
for project_name, project in iteritems(projects):
246+
for project_name, project in iter(projects.items()):
229247
part_indexes[project_name] = part_index
230248
for part in project:
231249
f.write("\t{ \"" + escape_string(part["License"][0]) + "\", "
@@ -239,7 +257,7 @@ def next_tag(self):
239257
f.write("const int COPYRIGHT_INFO_COUNT = " + str(len(projects)) + ";\n")
240258

241259
f.write("const ComponentCopyright COPYRIGHT_INFO[] = {\n")
242-
for project_name, project in iteritems(projects):
260+
for project_name, project in iter(projects.items()):
243261
f.write("\t{ \"" + escape_string(project_name) + "\", "
244262
+ "&COPYRIGHT_PROJECT_PARTS[" + str(part_indexes[project_name]) + "], "
245263
+ str(len(project)) + " },\n")

doc/Makefile

-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ doxygen:
1313
mkdir -p $(OUTPUTDIR)/doxygen
1414
doxygen Doxyfile
1515

16-
markdown:
17-
rm -rf $(OUTPUTDIR)/markdown
18-
mkdir -p $(OUTPUTDIR)/markdown
19-
pushd $(OUTPUTDIR)/markdown
20-
python2 $(TOOLSDIR)/makemd.py $(CLASSES)
21-
popd
22-
2316
rst:
2417
rm -rf $(OUTPUTDIR)/rst
2518
mkdir -p $(OUTPUTDIR)/rst

editor/SCsub

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ env.editor_sources = []
77
import os
88
import os.path
99
from platform_methods import run_in_subprocess
10-
from compat import open_utf8
1110
import editor_builders
1211

1312

1413
def _make_doc_data_class_path(to_path):
1514
# NOTE: It is safe to generate this file here, since this is still executed serially
16-
g = open_utf8(os.path.join(to_path, "doc_data_class_path.gen.h"), "w")
15+
g = open(os.path.join(to_path, "doc_data_class_path.gen.h"), "w", encoding="utf-8")
1716
g.write("static const int _doc_data_class_path_count = " + str(len(env.doc_class_path)) + ";\n")
1817
g.write("struct _DocDataClassPath { const char* name; const char* path; };\n")
1918

@@ -37,7 +36,7 @@ if env['tools']:
3736
reg_exporters += '}\n'
3837

3938
# NOTE: It is safe to generate this file here, since this is still executed serially
40-
with open_utf8("register_exporters.gen.cpp", "w") as f:
39+
with open("register_exporters.gen.cpp", "w", encoding="utf-8") as f:
4140
f.write(reg_exporters_inc)
4241
f.write(reg_exporters)
4342

editor/editor_builders.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@
66
import os
77
import os.path
88
from platform_methods import subprocess_main
9-
from compat import encode_utf8, byte_to_str, open_utf8
109

1110

1211
def make_doc_header(target, source, env):
1312

1413
dst = target[0]
15-
g = open_utf8(dst, "w")
14+
g = open(dst, "w", encoding="utf-8")
1615
buf = ""
1716
docbegin = ""
1817
docend = ""
1918
for src in source:
2019
if not src.endswith(".xml"):
2120
continue
22-
with open_utf8(src, "r") as f:
21+
with open(src, "r", encoding="utf-8") as f:
2322
content = f.read()
2423
buf += content
2524

26-
buf = encode_utf8(docbegin + buf + docend)
25+
buf = (docbegin + buf + docend).encode("utf-8")
2726
decomp_size = len(buf)
2827
import zlib
2928
buf = zlib.compress(buf)
@@ -35,7 +34,7 @@ def make_doc_header(target, source, env):
3534
g.write("static const int _doc_data_uncompressed_size = " + str(decomp_size) + ";\n")
3635
g.write("static const unsigned char _doc_data_compressed[] = {\n")
3736
for i in range(len(buf)):
38-
g.write("\t" + byte_to_str(buf[i]) + ",\n")
37+
g.write("\t" + str(buf[i]) + ",\n")
3938
g.write("};\n")
4039

4140
g.write("#endif")
@@ -47,7 +46,7 @@ def make_fonts_header(target, source, env):
4746

4847
dst = target[0]
4948

50-
g = open_utf8(dst, "w")
49+
g = open(dst, "w", encoding="utf-8")
5150

5251
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
5352
g.write("#ifndef _EDITOR_FONTS_H\n")
@@ -64,7 +63,7 @@ def make_fonts_header(target, source, env):
6463
g.write("static const int _font_" + name + "_size = " + str(len(buf)) + ";\n")
6564
g.write("static const unsigned char _font_" + name + "[] = {\n")
6665
for j in range(len(buf)):
67-
g.write("\t" + byte_to_str(buf[j]) + ",\n")
66+
g.write("\t" + str(buf[j]) + ",\n")
6867

6968
g.write("};\n")
7069

@@ -77,7 +76,7 @@ def make_translations_header(target, source, env, category):
7776

7877
dst = target[0]
7978

80-
g = open_utf8(dst, "w")
79+
g = open(dst, "w", encoding="utf-8")
8180

8281
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
8382
g.write("#ifndef _{}_TRANSLATIONS_H\n".format(category.upper()))
@@ -98,7 +97,7 @@ def make_translations_header(target, source, env, category):
9897

9998
g.write("static const unsigned char _{}_translation_{}_compressed[] = {{\n".format(category, name))
10099
for j in range(len(buf)):
101-
g.write("\t" + byte_to_str(buf[j]) + ",\n")
100+
g.write("\t" + str(buf[j]) + ",\n")
102101

103102
g.write("};\n")
104103

editor/icons/editor_icons_builders.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
All such functions are invoked in a subprocess on Windows to prevent build flakiness.
44
55
"""
6+
67
import os
8+
from io import StringIO
79
from platform_methods import subprocess_main
8-
from compat import StringIO
910

1011

1112
def make_editor_icons_action(target, source, env):

main/main_builders.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
55
"""
66
from platform_methods import subprocess_main
7-
from compat import byte_to_str
87
from collections import OrderedDict
98

109

@@ -22,7 +21,7 @@ def make_splash(target, source, env):
2221
g.write('static const Color boot_splash_bg_color = Color(0.14, 0.14, 0.14);\n')
2322
g.write("static const unsigned char boot_splash_png[] = {\n")
2423
for i in range(len(buf)):
25-
g.write(byte_to_str(buf[i]) + ",\n")
24+
g.write(str(buf[i]) + ",\n")
2625
g.write("};\n")
2726
g.write("#endif")
2827

@@ -41,7 +40,7 @@ def make_splash_editor(target, source, env):
4140
g.write('static const Color boot_splash_editor_bg_color = Color(0.14, 0.14, 0.14);\n')
4241
g.write("static const unsigned char boot_splash_editor_png[] = {\n")
4342
for i in range(len(buf)):
44-
g.write(byte_to_str(buf[i]) + ",\n")
43+
g.write(str(buf[i]) + ",\n")
4544
g.write("};\n")
4645
g.write("#endif")
4746

@@ -59,7 +58,7 @@ def make_app_icon(target, source, env):
5958
g.write("#define APP_ICON_H\n")
6059
g.write("static const unsigned char app_icon_png[] = {\n")
6160
for i in range(len(buf)):
62-
g.write(byte_to_str(buf[i]) + ",\n")
61+
g.write(str(buf[i]) + ",\n")
6362
g.write("};\n")
6463
g.write("#endif")
6564

0 commit comments

Comments
 (0)