gyp: cherrypick more Python3 changes from node-gyp · nodejs/node@d630cc0 · GitHub
Skip to content

Commit d630cc0

Browse files
cclausstargos
authored andcommitted
gyp: cherrypick more Python3 changes from node-gyp
PR-URL: #28563 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 06d0abe commit d630cc0

16 files changed

Lines changed: 198 additions & 180 deletions

tools/gyp/pylib/gyp/MSVSSettings.py

Lines changed: 22 additions & 18 deletions

tools/gyp/pylib/gyp/MSVSUtil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def InsertLargePdbShims(target_list, target_dicts, vars):
236236

237237
# Set up the shim to output its PDB to the same location as the final linker
238238
# target.
239-
for config_name, config in shim_dict.get('configurations').iteritems():
239+
for config_name, config in shim_dict.get('configurations').items():
240240
pdb_path = _GetPdbPath(target_dict, config_name, vars)
241241

242242
# A few keys that we don't want to propagate.

tools/gyp/pylib/gyp/MSVSVersion.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def _RegistryQuery(key, value=None):
189189
text = None
190190
try:
191191
text = _RegistryQueryBase('Sysnative', key, value)
192-
except OSError, e:
192+
except OSError as e:
193193
if e.errno == errno.ENOENT:
194194
text = _RegistryQueryBase('System32', key, value)
195195
else:
@@ -207,12 +207,18 @@ def _RegistryGetValueUsingWinReg(key, value):
207207
contents of the registry key's value, or None on failure. Throws
208208
ImportError if _winreg is unavailable.
209209
"""
210-
import _winreg
210+
try:
211+
# Python 2
212+
from _winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx
213+
except ImportError:
214+
# Python 3
215+
from winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx
216+
211217
try:
212218
root, subkey = key.split('\\', 1)
213219
assert root == 'HKLM' # Only need HKLM for now.
214-
with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey) as hkey:
215-
return _winreg.QueryValueEx(hkey, value)[0]
220+
with OpenKey(HKEY_LOCAL_MACHINE, subkey) as hkey:
221+
return QueryValueEx(hkey, value)[0]
216222
except WindowsError:
217223
return None
218224

tools/gyp/pylib/gyp/common.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# Use of this source code is governed by a BSD-style license that can be
33
# found in the LICENSE file.
44

5-
from __future__ import with_statement
6-
75
import collections
86
import errno
97
import filecmp
@@ -363,7 +361,7 @@ def close(self):
363361
same = False
364362
try:
365363
same = filecmp.cmp(self.tmp_path, filename, False)
366-
except OSError, e:
364+
except OSError as e:
367365
if e.errno != errno.ENOENT:
368366
raise
369367

@@ -382,9 +380,9 @@ def close(self):
382380
#
383381
# No way to get the umask without setting a new one? Set a safe one
384382
# and then set it back to the old value.
385-
umask = os.umask(077)
383+
umask = os.umask(0o77)
386384
os.umask(umask)
387-
os.chmod(self.tmp_path, 0666 & ~umask)
385+
os.chmod(self.tmp_path, 0o666 & ~umask)
388386
if sys.platform == 'win32' and os.path.exists(filename):
389387
# NOTE: on windows (but not cygwin) rename will not replace an
390388
# existing file, so it must be preceded with a remove. Sadly there
@@ -467,7 +465,7 @@ def CopyTool(flavor, out_path, generator_flags={}):
467465
''.join([source[0], header] + source[1:]))
468466

469467
# Make file executable.
470-
os.chmod(tool_path, 0755)
468+
os.chmod(tool_path, 0o755)
471469

472470

473471
# From Alex Martelli,

tools/gyp/pylib/gyp/easy_xml.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66
import os
77
import locale
8+
from functools import reduce
89

910

1011
def XmlToString(content, encoding='utf-8', pretty=False):
@@ -80,7 +81,7 @@ def _ConstructContentList(xml_parts, specification, pretty, level=0):
8081
# Optionally in second position is a dictionary of the attributes.
8182
rest = specification[1:]
8283
if rest and isinstance(rest[0], dict):
83-
for at, val in sorted(rest[0].iteritems()):
84+
for at, val in sorted(rest[0].items()):
8485
xml_parts.append(' %s="%s"' % (at, _XmlEscape(val, attr=True)))
8586
rest = rest[1:]
8687
if rest:

tools/gyp/pylib/gyp/generator/cmake.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
CMakeLists.txt file.
2929
"""
3030

31+
from __future__ import print_function
32+
3133
import multiprocessing
3234
import os
3335
import signal
@@ -644,8 +646,8 @@ def WriteTarget(namer, qualified_target, target_dicts, build_dir, config_to_use,
644646

645647
cmake_target_type = cmake_target_type_from_gyp_target_type.get(target_type)
646648
if cmake_target_type is None:
647-
print ('Target %s has unknown target type %s, skipping.' %
648-
( target_name, target_type ) )
649+
print('Target %s has unknown target type %s, skipping.' %
650+
( target_name, target_type))
649651
return
650652

651653
SetVariable(output, 'TARGET', target_name)
@@ -868,8 +870,8 @@ def WriteTarget(namer, qualified_target, target_dicts, build_dir, config_to_use,
868870
default_product_ext = generator_default_variables['SHARED_LIB_SUFFIX']
869871

870872
elif target_type != 'executable':
871-
print ('ERROR: What output file should be generated?',
872-
'type', target_type, 'target', target_name)
873+
print('ERROR: What output file should be generated?',
874+
'type', target_type, 'target', target_name)
873875

874876
product_prefix = spec.get('product_prefix', default_product_prefix)
875877
product_name = spec.get('product_name', default_product_name)
@@ -1207,11 +1209,11 @@ def PerformBuild(data, configurations, params):
12071209
output_dir,
12081210
config_name))
12091211
arguments = ['cmake', '-G', 'Ninja']
1210-
print 'Generating [%s]: %s' % (config_name, arguments)
1212+
print('Generating [%s]: %s' % (config_name, arguments))
12111213
subprocess.check_call(arguments, cwd=build_dir)
12121214

12131215
arguments = ['ninja', '-C', build_dir]
1214-
print 'Building [%s]: %s' % (config_name, arguments)
1216+
print('Building [%s]: %s' % (config_name, arguments))
12151217
subprocess.check_call(arguments)
12161218

12171219

@@ -1239,7 +1241,7 @@ def GenerateOutput(target_list, target_dicts, data, params):
12391241
arglists.append((target_list, target_dicts, data,
12401242
params, config_name))
12411243
pool.map(CallGenerateOutputForConfig, arglists)
1242-
except KeyboardInterrupt, e:
1244+
except KeyboardInterrupt as e:
12431245
pool.terminate()
12441246
raise e
12451247
else:

tools/gyp/pylib/gyp/generator/make.py

Lines changed: 13 additions & 11 deletions

0 commit comments

Comments
 (0)