From d7134788963a475a6500a0f7183dcf61e3a401b3 Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Thu, 25 Oct 2018 13:28:15 +0200 Subject: [PATCH] gyp: more py3 compat --- gyp/pylib/gyp/MSVSNew.py | 3 +- gyp/pylib/gyp/MSVSSettings.py | 2 +- gyp/pylib/gyp/MSVSSettings_test.py | 4 +- gyp/pylib/gyp/MSVSVersion.py | 8 +- gyp/pylib/gyp/__init__.py | 7 +- gyp/pylib/gyp/compat.py | 24 ++ gyp/pylib/gyp/easy_xml_test.py | 4 +- gyp/pylib/gyp/generator/analyzer.py | 2 +- gyp/pylib/gyp/generator/android.py | 11 +- gyp/pylib/gyp/generator/eclipse.py | 3 +- gyp/pylib/gyp/generator/make.py | 37 ++- gyp/pylib/gyp/generator/msvs.py | 6 +- gyp/pylib/gyp/generator/msvs_test.py | 4 +- gyp/pylib/gyp/generator/ninja.py | 26 +- gyp/pylib/gyp/generator/ninja_test.py | 1 - gyp/pylib/gyp/input.py | 4 +- gyp/pylib/gyp/msvs_emulation.py | 36 +-- gyp/pylib/gyp/ninja_syntax.py | 4 +- gyp/pylib/gyp/ordered_dict.py | 290 +----------------- gyp/pylib/gyp/simple_copy.py | 10 +- gyp/pylib/gyp/xcode_emulation.py | 2 +- gyp/pylib/gyp/xcode_ninja.py | 2 +- gyp/pylib/gyp/xcodeproj_file.py | 24 +- gyp/tools/pretty_vcproj.py | 5 +- lib/configure.js | 10 +- test/fixtures/test-charmap.py | 12 +- test/test-addon.js | 2 +- test/test-find-python.js | 10 +- .../gyp/generator/compile_commands_json.py | 6 +- 29 files changed, 152 insertions(+), 407 deletions(-) create mode 100644 gyp/pylib/gyp/compat.py diff --git a/gyp/pylib/gyp/MSVSNew.py b/gyp/pylib/gyp/MSVSNew.py index 593f0e5b0b..dabc03f296 100644 --- a/gyp/pylib/gyp/MSVSNew.py +++ b/gyp/pylib/gyp/MSVSNew.py @@ -8,6 +8,7 @@ import random import gyp.common +from gyp.common import compat_cmp # hashlib is supplied as of Python 2.5 as the replacement interface for md5 # and other secure hashes. In 2.6, md5 is deprecated. Import hashlib if @@ -62,7 +63,7 @@ def MakeGuid(name, seed='msvs_new'): class MSVSSolutionEntry(object): def __cmp__(self, other): # Sort by name then guid (so things are in order on vs2008). - return cmp((self.name, self.get_guid()), (other.name, other.get_guid())) + return compat_cmp((self.name, self.get_guid()), (other.name, other.get_guid())) class MSVSFolder(MSVSSolutionEntry): diff --git a/gyp/pylib/gyp/MSVSSettings.py b/gyp/pylib/gyp/MSVSSettings.py index 8073f92b8d..a77b150774 100644 --- a/gyp/pylib/gyp/MSVSSettings.py +++ b/gyp/pylib/gyp/MSVSSettings.py @@ -16,7 +16,7 @@ from __future__ import print_function -from gyp import string_types +from gyp.compat import string_types import sys import re diff --git a/gyp/pylib/gyp/MSVSSettings_test.py b/gyp/pylib/gyp/MSVSSettings_test.py index bf6ea6b802..1978bda7f0 100755 --- a/gyp/pylib/gyp/MSVSSettings_test.py +++ b/gyp/pylib/gyp/MSVSSettings_test.py @@ -6,7 +6,7 @@ """Unit tests for the MSVSSettings.py file.""" -import StringIO +from gyp.compat import StringIO import unittest import gyp.MSVSSettings as MSVSSettings @@ -14,7 +14,7 @@ class TestSequenceFunctions(unittest.TestCase): def setUp(self): - self.stderr = StringIO.StringIO() + self.stderr = StringIO() def _ExpectedWarnings(self, expected): """Compares recorded lines to expected warnings.""" diff --git a/gyp/pylib/gyp/MSVSVersion.py b/gyp/pylib/gyp/MSVSVersion.py index 293b4145c1..f4af9193be 100644 --- a/gyp/pylib/gyp/MSVSVersion.py +++ b/gyp/pylib/gyp/MSVSVersion.py @@ -177,16 +177,14 @@ def _RegistryGetValueUsingWinReg(key, value): ImportError if _winreg is unavailable. """ try: - # Python 2 - from _winreg import OpenKey, QueryValueEx + from winreg import OpenKey, QueryValueEx, HKEY_LOCAL_MACHINE except ImportError: - # Python 3 - from winreg import OpenKey, QueryValueEx + from _winreg import OpenKey, QueryValueEx, HKEY_LOCAL_MACHINE try: root, subkey = key.split('\\', 1) assert root == 'HKLM' # Only need HKLM for now. - with OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey) as hkey: + with OpenKey(HKEY_LOCAL_MACHINE, subkey) as hkey: return QueryValueEx(hkey, value)[0] except WindowsError: return None diff --git a/gyp/pylib/gyp/__init__.py b/gyp/pylib/gyp/__init__.py index d5fa9ecf50..9619c588ce 100755 --- a/gyp/pylib/gyp/__init__.py +++ b/gyp/pylib/gyp/__init__.py @@ -15,13 +15,8 @@ import sys import traceback from gyp.common import GypError +from gyp.compat import string_types -try: - # Python 2 - string_types = basestring -except NameError: - # Python 3 - string_types = str # Default debug modes for GYP debug = {} diff --git a/gyp/pylib/gyp/compat.py b/gyp/pylib/gyp/compat.py new file mode 100644 index 0000000000..b3b3552973 --- /dev/null +++ b/gyp/pylib/gyp/compat.py @@ -0,0 +1,24 @@ +import sys + +if sys.version_info[0] == 2: + from cStringIO import StringIO + string_types = (basestring,) # noqa: F821 + simple_types = types = (type(None), int, long, float, bool, # noqa: F821 + str, unicode, type, basestring) # noqa: F821 + unicode_type = unicode # noqa: F821 + compat_cmp = cmp # noqa: F821 +else: + from io import StringIO + string_types = (str, ) + simple_types = types = (type(None), int, float, bool, str, type) + unicode_type = str + + def compat_cmp(x, y): + + if x == y: + return 0 + + if x < y: + return -1 + + return 1 diff --git a/gyp/pylib/gyp/easy_xml_test.py b/gyp/pylib/gyp/easy_xml_test.py index df64354982..103633eb72 100755 --- a/gyp/pylib/gyp/easy_xml_test.py +++ b/gyp/pylib/gyp/easy_xml_test.py @@ -8,13 +8,13 @@ import gyp.easy_xml as easy_xml import unittest -import StringIO +from gyp.compat import StringIO class TestSequenceFunctions(unittest.TestCase): def setUp(self): - self.stderr = StringIO.StringIO() + self.stderr = StringIO() def test_EasyXml_simple(self): self.assertEqual( diff --git a/gyp/pylib/gyp/generator/analyzer.py b/gyp/pylib/gyp/generator/analyzer.py index dc17c96524..0416b5d9be 100644 --- a/gyp/pylib/gyp/generator/analyzer.py +++ b/gyp/pylib/gyp/generator/analyzer.py @@ -671,7 +671,7 @@ def find_matching_compile_target_names(self): assert self.is_build_impacted(); # Compile targets are found by searching up from changed targets. # Reset the visited status for _GetBuildTargets. - for target in self._name_to_target.itervalues(): + for target in self._name_to_target.values(): target.visited = False supplied_targets = _LookupTargets(self._supplied_target_names_no_all(), diff --git a/gyp/pylib/gyp/generator/android.py b/gyp/pylib/gyp/generator/android.py index b7f9842888..98f67ebc35 100644 --- a/gyp/pylib/gyp/generator/android.py +++ b/gyp/pylib/gyp/generator/android.py @@ -383,7 +383,7 @@ def WriteRules(self, rules, extra_sources, extra_outputs): # We set up a rule to build the first output, and then set up # a rule for each additional output to depend on the first. - outputs = map(self.LocalPathify, outputs) + outputs = list(map(self.LocalPathify, outputs)) main_output = outputs[0] self.WriteLn('%s: gyp_local_path := $(LOCAL_PATH)' % main_output) self.WriteLn('%s: gyp_var_prefix := $(GYP_VAR_PREFIX)' % main_output) @@ -475,7 +475,7 @@ def WriteSourceFlags(self, spec, configs): self.WriteLn('\n# Include paths placed before CFLAGS/CPPFLAGS') includes = list(config.get('include_dirs', [])) includes.extend(extracted_includes) - includes = map(Sourceify, map(self.LocalPathify, includes)) + includes = list(map(Sourceify, map(self.LocalPathify, includes))) includes = self.NormalizeIncludePaths(includes) self.WriteList(includes, 'LOCAL_C_INCLUDES_%s' % configname) @@ -510,9 +510,9 @@ def WriteSources(self, spec, configs, extra_sources): spec, configs: input from gyp. extra_sources: Sources generated from Actions or Rules. """ - sources = filter(make.Compilable, spec.get('sources', [])) + sources = list(filter(make.Compilable, spec.get('sources', []))) generated_not_sources = [x for x in extra_sources if not make.Compilable(x)] - extra_sources = filter(make.Compilable, extra_sources) + extra_sources = list(filter(make.Compilable, extra_sources)) # Determine and output the C++ extension used by these sources. # We simply find the first C++ file and use that extension. @@ -574,7 +574,8 @@ def WriteSources(self, spec, configs, extra_sources): self.WriteList(final_generated_sources, 'LOCAL_GENERATED_SOURCES') origin_src_dirs = gyp.common.uniquer(origin_src_dirs) - origin_src_dirs = map(Sourceify, map(self.LocalPathify, origin_src_dirs)) + origin_src_dirs = list(map(Sourceify, map(self.LocalPathify, + origin_src_dirs))) self.WriteList(origin_src_dirs, 'GYP_COPIED_SOURCE_ORIGIN_DIRS') self.WriteList(local_files, 'LOCAL_SRC_FILES') diff --git a/gyp/pylib/gyp/generator/eclipse.py b/gyp/pylib/gyp/generator/eclipse.py index b7c6aa951f..57250a44c4 100644 --- a/gyp/pylib/gyp/generator/eclipse.py +++ b/gyp/pylib/gyp/generator/eclipse.py @@ -272,7 +272,7 @@ def WriteMacros(out, eclipse_langs, defines): out.write(' \n') for lang in eclipse_langs: out.write(' \n' % lang) - for key in sorted(defines.iterkeys()): + for key in sorted(defines.keys()): out.write(' %s%s\n' % (escape(key), escape(defines[key]))) out.write(' \n') @@ -422,4 +422,3 @@ def GenerateOutput(target_list, target_dicts, data, params): for config_name in config_names: GenerateOutputForConfig(target_list, target_dicts, data, params, config_name) - diff --git a/gyp/pylib/gyp/generator/make.py b/gyp/pylib/gyp/generator/make.py index d549e899d8..6ab1114db8 100644 --- a/gyp/pylib/gyp/generator/make.py +++ b/gyp/pylib/gyp/generator/make.py @@ -821,7 +821,7 @@ def Write(self, qualified_target, base_path, output_filename, spec, configs, gyp.xcode_emulation.MacPrefixHeader( self.xcode_settings, lambda p: Sourceify(self.Absolutify(p)), self.Pchify)) - sources = filter(Compilable, all_sources) + sources = list(filter(Compilable, all_sources)) if sources: self.WriteLn(SHARED_HEADER_SUFFIX_RULES_COMMENT1) extensions = set([os.path.splitext(s)[1] for s in sources]) @@ -950,7 +950,7 @@ def WriteActions(self, actions, extra_sources, extra_outputs, '%s%s' % (name, cd_action, command)) self.WriteLn() - outputs = map(self.Absolutify, outputs) + outputs = list(map(self.Absolutify, outputs)) # The makefile rules are all relative to the top dir, but the gyp actions # are defined relative to their containing dir. This replaces the obj # variable for the action rule with an absolute version so that the output @@ -974,8 +974,9 @@ def WriteActions(self, actions, extra_sources, extra_outputs, outputs = [gyp.xcode_emulation.ExpandEnvVars(o, env) for o in outputs] inputs = [gyp.xcode_emulation.ExpandEnvVars(i, env) for i in inputs] - self.WriteDoCmd(outputs, map(Sourceify, map(self.Absolutify, inputs)), - part_of_all=part_of_all, command=name) + self.WriteDoCmd( + outputs, list(map(Sourceify, map(self.Absolutify, inputs))), + part_of_all=part_of_all, command=name) # Stuff the outputs in a variable so we can refer to them later. outputs_variable = 'action_%s_outputs' % name @@ -1023,8 +1024,8 @@ def WriteRules(self, rules, extra_sources, extra_outputs, extra_sources += outputs if int(rule.get('process_outputs_as_mac_bundle_resources', False)): extra_mac_bundle_resources += outputs - inputs = map(Sourceify, map(self.Absolutify, [rule_source] + - rule.get('inputs', []))) + inputs = list(map(Sourceify, map(self.Absolutify, [rule_source] + + rule.get('inputs', [])))) actions = ['$(call do_cmd,%s_%d)' % (name, count)] if name == 'resources_grit': @@ -1040,7 +1041,7 @@ def WriteRules(self, rules, extra_sources, extra_outputs, outputs = [gyp.xcode_emulation.ExpandEnvVars(o, env) for o in outputs] inputs = [gyp.xcode_emulation.ExpandEnvVars(i, env) for i in inputs] - outputs = map(self.Absolutify, outputs) + outputs = list(map(self.Absolutify, outputs)) all_outputs += outputs # Only write the 'obj' and 'builddir' rules for the "primary" output # (:1); it's superfluous for the "extra outputs", and this avoids @@ -1158,7 +1159,7 @@ def WriteMacBundleResources(self, resources, bundle_deps): for output, res in gyp.xcode_emulation.GetMacBundleResources( generator_default_variables['PRODUCT_DIR'], self.xcode_settings, - map(Sourceify, map(self.Absolutify, resources))): + list(map(Sourceify, map(self.Absolutify, resources)))): _, ext = os.path.splitext(output) if ext != '.xcassets': # Make does not supports '.xcassets' emulation. @@ -1238,11 +1239,12 @@ def WriteSources(self, configs, deps, sources, self.WriteList(cflags_objcc, 'CFLAGS_OBJCC_%s' % configname) includes = config.get('include_dirs') if includes: - includes = map(Sourceify, map(self.Absolutify, includes)) + includes = list(map(Sourceify, map(self.Absolutify, includes))) self.WriteList(includes, 'INCS_%s' % configname, prefix='-I') - compilable = filter(Compilable, sources) - objs = map(self.Objectify, map(self.Absolutify, map(Target, compilable))) + compilable = list(filter(Compilable, sources)) + objs = list(map( + self.Objectify, map(self.Absolutify, map(Target, compilable)))) self.WriteList(objs, 'OBJS') for obj in objs: @@ -1314,7 +1316,7 @@ def WriteSources(self, configs, deps, sources, # If there are any object files in our input file list, link them into our # output. - extra_link_deps += filter(Linkable, sources) + extra_link_deps += list(filter(Linkable, sources)) self.WriteLn() @@ -1564,7 +1566,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps, # Bundle dependencies. Note that the code below adds actions to this # target, so if you move these two lines, move the lines below as well. - self.WriteList(map(QuoteSpaces, bundle_deps), 'BUNDLE_DEPS') + self.WriteList(list(map(QuoteSpaces, bundle_deps)), 'BUNDLE_DEPS') self.WriteLn('%s: $(BUNDLE_DEPS)' % QuoteSpaces(self.output)) # After the framework is built, package it. Needs to happen before @@ -1746,8 +1748,8 @@ def WriteMakeRule(self, outputs, inputs, actions=None, comment=None, output is just a name to run the rule command: (optional) command name to generate unambiguous labels """ - outputs = map(QuoteSpaces, outputs) - inputs = map(QuoteSpaces, inputs) + outputs = list(map(QuoteSpaces, outputs)) + inputs = list(map(QuoteSpaces, inputs)) if comment: self.WriteLn('# ' + comment) @@ -1836,8 +1838,9 @@ def WriteAndroidNdkModuleRule(self, module_name, all_sources, link_deps): default_cpp_ext = ext self.WriteLn('LOCAL_CPP_EXTENSION := ' + default_cpp_ext) - self.WriteList(map(self.Absolutify, filter(Compilable, all_sources)), - 'LOCAL_SRC_FILES') + self.WriteList(list(map(self.Absolutify, list(filter(Compilable, + all_sources))), + 'LOCAL_SRC_FILES')) # Filter out those which do not match prefix and suffix and produce # the resulting list without prefix and suffix. diff --git a/gyp/pylib/gyp/generator/msvs.py b/gyp/pylib/gyp/generator/msvs.py index fb2549d025..fddd1451bd 100644 --- a/gyp/pylib/gyp/generator/msvs.py +++ b/gyp/pylib/gyp/generator/msvs.py @@ -2682,7 +2682,7 @@ def _GetMSBuildGlobalProperties(spec, guid, gyp_file_name): platform_name = None msvs_windows_target_platform_version = None - for configuration in spec['configurations'].itervalues(): + for configuration in spec['configurations'].values(): platform_name = platform_name or _ConfigPlatform(configuration) msvs_windows_target_platform_version = \ msvs_windows_target_platform_version or \ @@ -3242,7 +3242,7 @@ def _GetMSBuildProjectReferences(project): ['Project', guid], ['ReferenceOutputAssembly', 'false'] ] - for config in dependency.spec.get('configurations', {}).itervalues(): + for config in dependency.spec.get('configurations', {}).values(): if config.get('msvs_use_library_dependency_inputs', 0): project_ref.append(['UseLibraryDependencyInputs', 'true']) break @@ -3311,7 +3311,7 @@ def _GenerateMSBuildProject(project, options, version, generator_flags): extension_to_rule_name) missing_sources = _VerifySourcesExist(sources, project_dir) - for configuration in configurations.itervalues(): + for configuration in configurations.values(): _FinalizeMSBuildSettings(spec, configuration) # Add attributes to root element diff --git a/gyp/pylib/gyp/generator/msvs_test.py b/gyp/pylib/gyp/generator/msvs_test.py index c0b021df50..0bb22ee45c 100755 --- a/gyp/pylib/gyp/generator/msvs_test.py +++ b/gyp/pylib/gyp/generator/msvs_test.py @@ -7,13 +7,13 @@ import gyp.generator.msvs as msvs import unittest -import StringIO +from gyp.compat import StringIO class TestSequenceFunctions(unittest.TestCase): def setUp(self): - self.stderr = StringIO.StringIO() + self.stderr = StringIO() def test_GetLibraries(self): self.assertEqual( diff --git a/gyp/pylib/gyp/generator/ninja.py b/gyp/pylib/gyp/generator/ninja.py index aae5b71310..851edd715e 100644 --- a/gyp/pylib/gyp/generator/ninja.py +++ b/gyp/pylib/gyp/generator/ninja.py @@ -19,7 +19,7 @@ import gyp.msvs_emulation import gyp.MSVSUtil as MSVSUtil import gyp.xcode_emulation -from cStringIO import StringIO +from gyp.compat import StringIO from gyp.common import GetEnvironFallback import gyp.ninja_syntax as ninja_syntax @@ -348,7 +348,7 @@ def WriteCollapsedDependencies(self, name, targets, order_only=None): Uses a stamp file if necessary.""" - assert targets == filter(None, targets), targets + assert targets == list(filter(None, targets)), targets if len(targets) == 0: assert not order_only return None @@ -768,7 +768,7 @@ def WriteMacBundleResources(self, resources, bundle_depends): xcassets = [] for output, res in gyp.xcode_emulation.GetMacBundleResources( generator_default_variables['PRODUCT_DIR'], - self.xcode_settings, map(self.GypPathToNinja, resources)): + self.xcode_settings, list(map(self.GypPathToNinja, resources))): output = self.ExpandSpecial(output) if os.path.splitext(output)[-1] != '.xcassets': isBinary = self.xcode_settings.IsBinaryOutputFormat(self.config_name) @@ -937,7 +937,7 @@ def WriteSourcesForArch(self, ninja_file, config_name, config, sources, [Define(d, self.flavor) for d in defines]) if self.flavor == 'win': self.WriteVariableList(ninja_file, 'asmflags', - map(self.ExpandSpecial, asmflags)) + list(map(self.ExpandSpecial, asmflags))) self.WriteVariableList(ninja_file, 'rcflags', [QuoteShellArgument(self.ExpandSpecial(f), self.flavor) for f in self.msvs_settings.GetRcflags(config_name, @@ -972,18 +972,18 @@ def WriteSourcesForArch(self, ninja_file, config_name, config, sources, arflags = config.get('arflags', []) self.WriteVariableList(ninja_file, 'cflags', - map(self.ExpandSpecial, cflags)) + list(map(self.ExpandSpecial, cflags))) self.WriteVariableList(ninja_file, 'cflags_c', - map(self.ExpandSpecial, cflags_c)) + list(map(self.ExpandSpecial, cflags_c))) self.WriteVariableList(ninja_file, 'cflags_cc', - map(self.ExpandSpecial, cflags_cc)) + list(map(self.ExpandSpecial, cflags_cc))) if self.flavor == 'mac': self.WriteVariableList(ninja_file, 'cflags_objc', - map(self.ExpandSpecial, cflags_objc)) + list(map(self.ExpandSpecial, cflags_objc))) self.WriteVariableList(ninja_file, 'cflags_objcc', - map(self.ExpandSpecial, cflags_objcc)) + list(map(self.ExpandSpecial, cflags_objcc))) self.WriteVariableList(ninja_file, 'arflags', - map(self.ExpandSpecial, arflags)) + list(map(self.ExpandSpecial, arflags))) ninja_file.newline() outputs = [] has_rc_source = False @@ -1182,7 +1182,7 @@ def WriteLinkForArch(self, ninja_file, spec, config_name, config, ldflags.append(r'-Wl,-rpath=\$$ORIGIN/%s' % rpath) ldflags.append('-Wl,-rpath-link=%s' % rpath) self.WriteVariableList(ninja_file, 'ldflags', - map(self.ExpandSpecial, ldflags)) + list(map(self.ExpandSpecial, ldflags))) library_dirs = config.get('library_dirs', []) if self.flavor == 'win': @@ -1196,8 +1196,8 @@ def WriteLinkForArch(self, ninja_file, spec, config_name, config, self.flavor) for l in library_dirs] - libraries = gyp.common.uniquer(map(self.ExpandSpecial, - spec.get('libraries', []))) + libraries = gyp.common.uniquer(list(map(self.ExpandSpecial, + spec.get('libraries', [])))) if self.flavor == 'mac': libraries = self.xcode_settings.AdjustLibraries(libraries, config_name) elif self.flavor == 'win': diff --git a/gyp/pylib/gyp/generator/ninja_test.py b/gyp/pylib/gyp/generator/ninja_test.py index 1767b2f45a..1ad68e4fc9 100644 --- a/gyp/pylib/gyp/generator/ninja_test.py +++ b/gyp/pylib/gyp/generator/ninja_test.py @@ -8,7 +8,6 @@ import gyp.generator.ninja as ninja import unittest -import StringIO import sys import TestCommon diff --git a/gyp/pylib/gyp/input.py b/gyp/pylib/gyp/input.py index 68e51131d8..98920c94cf 100644 --- a/gyp/pylib/gyp/input.py +++ b/gyp/pylib/gyp/input.py @@ -1847,7 +1847,7 @@ def VerifyNoGYPFileCircularDependencies(targets): # Create a DependencyGraphNode for each gyp file containing a target. Put # it into a dict for easy access. dependency_nodes = {} - for target in targets.iterkeys(): + for target in targets.keys(): build_file = gyp.common.BuildFile(target) if not build_file in dependency_nodes: dependency_nodes[build_file] = DependencyGraphNode(build_file) @@ -1878,7 +1878,7 @@ def VerifyNoGYPFileCircularDependencies(targets): # Files that have no dependencies are treated as dependent on root_node. root_node = DependencyGraphNode(None) - for build_file_node in dependency_nodes.itervalues(): + for build_file_node in dependency_nodes.values(): if len(build_file_node.dependencies) == 0: build_file_node.dependencies.append(root_node) root_node.dependents.append(build_file_node) diff --git a/gyp/pylib/gyp/msvs_emulation.py b/gyp/pylib/gyp/msvs_emulation.py index 75da78526c..088e3d792f 100644 --- a/gyp/pylib/gyp/msvs_emulation.py +++ b/gyp/pylib/gyp/msvs_emulation.py @@ -87,16 +87,16 @@ def _AddPrefix(element, prefix): return prefix + element -def _DoRemapping(element, map): - """If |element| then remap it through |map|. If |element| is iterable then +def _DoRemapping(element, map_func): + """If |element| then remap it through |map_func|. If |element| is iterable then each item will be remapped. Any elements not found will be removed.""" - if map is not None and element is not None: - if not callable(map): - map = map.get # Assume it's a dict, otherwise a callable to do the remap. + if map_func is not None and element is not None: + if not callable(map_func): + map_func = map_func.get # Assume it's a dict, otherwise a callable to do the remap. if isinstance(element, list) or isinstance(element, tuple): - element = filter(None, [map(elem) for elem in element]) + element = list(filter(None, [map_func(elem) for elem in element])) else: - element = map(element) + element = map_func(element) return element @@ -105,7 +105,7 @@ def _AppendOrReturn(append, element): then add |element| to it, adding each item in |element| if it's a list or tuple.""" if append is not None and element is not None: - if isinstance(element, list) or isinstance(element, tuple): + if isinstance(element, (list, tuple)): append.extend(element) else: append.append(element) @@ -472,7 +472,7 @@ def GetCflags(self, config): # New flag required in 2013 to maintain previous PDB behavior. cflags.append('/FS') # ninja handles parallelism by itself, don't have the compiler do it too. - cflags = filter(lambda x: not x.startswith('/MP'), cflags) + cflags = list(filter(lambda x: not x.startswith('/MP'), cflags)) return cflags def _GetPchFlags(self, config, extension): @@ -637,8 +637,7 @@ def GetLdflags(self, config, gyp_to_build_path, expand_special, # If the base address is not specifically controlled, DYNAMICBASE should # be on by default. - base_flags = filter(lambda x: 'DYNAMICBASE' in x or x == '/FIXED', - ldflags) + base_flags = list(filter(lambda x: 'DYNAMICBASE' in x or x == '/FIXED', ldflags)) if not base_flags: ldflags.append('/DYNAMICBASE') @@ -646,10 +645,10 @@ def GetLdflags(self, config, gyp_to_build_path, expand_special, # documentation that says this only defaults to on when the subsystem is # Vista or greater (which applies to the linker), the IDE defaults it on # unless it's explicitly off. - if not filter(lambda x: 'NXCOMPAT' in x, ldflags): + if not any(map(lambda x: 'NXCOMPAT' in x, ldflags)): ldflags.append('/NXCOMPAT') - have_def_file = filter(lambda x: x.startswith('/DEF:'), ldflags) + have_def_file = list(filter(lambda x: x.startswith('/DEF:'), ldflags)) manifest_flags, intermediate_manifest, manifest_files = \ self._GetLdManifestFlags(config, manifest_base_name, gyp_to_build_path, is_executable and not have_def_file, build_dir) @@ -915,12 +914,11 @@ def GetFlagsModifications(self, input, output, implicit, command, for the pch compilation step.""" if input == self.pch_source: pch_output = ['/Yc' + self._PchHeader()] + expanded_flags = list(map(expand_special, cflags_cc + pch_output)) if command == 'cxx': - return ([('cflags_cc', map(expand_special, cflags_cc + pch_output))], - self.output_obj, []) + return ([('cflags_cc', expanded_flags)], self.output_obj, []) elif command == 'cc': - return ([('cflags_c', map(expand_special, cflags_c + pch_output))], - self.output_obj, []) + return ([('cflags_c', expanded_flags)], self.output_obj, []) return [], output, implicit @@ -1058,9 +1056,9 @@ def VerifyMissingSources(sources, build_dir, generator_flags, gyp_to_ninja): VS, and we want this check to match for people/bots that build using ninja, so they're not surprised when the VS build fails.""" if int(generator_flags.get('msvs_error_on_missing_sources', 0)): - no_specials = filter(lambda x: '$' not in x, sources) + no_specials = list(filter(lambda x: '$' not in x, sources)) relative = [os.path.join(build_dir, gyp_to_ninja(s)) for s in no_specials] - missing = filter(lambda x: not os.path.exists(x), relative) + missing = list(filter(lambda x: not os.path.exists(x), relative)) if missing: # They'll look like out\Release\..\..\stuff\things.cc, so normalize the # path for a slightly less crazy looking output. diff --git a/gyp/pylib/gyp/ninja_syntax.py b/gyp/pylib/gyp/ninja_syntax.py index d2948f06c0..c51476a7d0 100644 --- a/gyp/pylib/gyp/ninja_syntax.py +++ b/gyp/pylib/gyp/ninja_syntax.py @@ -68,11 +68,11 @@ def build(self, outputs, rule, inputs=None, implicit=None, order_only=None, all_inputs = list(map(escape_path, all_inputs)) if implicit: - implicit = map(escape_path, self._as_list(implicit)) + implicit = list(map(escape_path, self._as_list(implicit))) all_inputs.append('|') all_inputs.extend(implicit) if order_only: - order_only = map(escape_path, self._as_list(order_only)) + order_only = list(map(escape_path, self._as_list(order_only))) all_inputs.append('||') all_inputs.extend(order_only) diff --git a/gyp/pylib/gyp/ordered_dict.py b/gyp/pylib/gyp/ordered_dict.py index 6fe9c1f6c7..b7613b042e 100644 --- a/gyp/pylib/gyp/ordered_dict.py +++ b/gyp/pylib/gyp/ordered_dict.py @@ -1,289 +1 @@ -# Unmodified from http://code.activestate.com/recipes/576693/ -# other than to add MIT license header (as specified on page, but not in code). -# Linked from Python documentation here: -# http://docs.python.org/2/library/collections.html#collections.OrderedDict -# -# This should be deleted once Py2.7 is available on all bots, see -# http://crbug.com/241769. -# -# Copyright (c) 2009 Raymond Hettinger. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -# Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 and pypy. -# Passes Python2.7's test suite and incorporates all the latest updates. - -try: - from thread import get_ident as _get_ident -except ImportError: - from dummy_thread import get_ident as _get_ident - -try: - from _abcoll import KeysView, ValuesView, ItemsView -except ImportError: - pass - - -class OrderedDict(dict): - 'Dictionary that remembers insertion order' - # An inherited dict maps keys to values. - # The inherited dict provides __getitem__, __len__, __contains__, and get. - # The remaining methods are order-aware. - # Big-O running times for all methods are the same as for regular dictionaries. - - # The internal self.__map dictionary maps keys to links in a doubly linked list. - # The circular doubly linked list starts and ends with a sentinel element. - # The sentinel element never gets deleted (this simplifies the algorithm). - # Each link is stored as a list of length three: [PREV, NEXT, KEY]. - - def __init__(self, *args, **kwds): - '''Initialize an ordered dictionary. Signature is the same as for - regular dictionaries, but keyword arguments are not recommended - because their insertion order is arbitrary. - - ''' - if len(args) > 1: - raise TypeError('expected at most 1 arguments, got %d' % len(args)) - try: - self.__root - except AttributeError: - self.__root = root = [] # sentinel node - root[:] = [root, root, None] - self.__map = {} - self.__update(*args, **kwds) - - def __setitem__(self, key, value, dict_setitem=dict.__setitem__): - 'od.__setitem__(i, y) <==> od[i]=y' - # Setting a new item creates a new link which goes at the end of the linked - # list, and the inherited dictionary is updated with the new key/value pair. - if key not in self: - root = self.__root - last = root[0] - last[1] = root[0] = self.__map[key] = [last, root, key] - dict_setitem(self, key, value) - - def __delitem__(self, key, dict_delitem=dict.__delitem__): - 'od.__delitem__(y) <==> del od[y]' - # Deleting an existing item uses self.__map to find the link which is - # then removed by updating the links in the predecessor and successor nodes. - dict_delitem(self, key) - link_prev, link_next, key = self.__map.pop(key) - link_prev[1] = link_next - link_next[0] = link_prev - - def __iter__(self): - 'od.__iter__() <==> iter(od)' - root = self.__root - curr = root[1] - while curr is not root: - yield curr[2] - curr = curr[1] - - def __reversed__(self): - 'od.__reversed__() <==> reversed(od)' - root = self.__root - curr = root[0] - while curr is not root: - yield curr[2] - curr = curr[0] - - def clear(self): - 'od.clear() -> None. Remove all items from od.' - try: - for node in self.__map.itervalues(): - del node[:] - root = self.__root - root[:] = [root, root, None] - self.__map.clear() - except AttributeError: - pass - dict.clear(self) - - def popitem(self, last=True): - '''od.popitem() -> (k, v), return and remove a (key, value) pair. - Pairs are returned in LIFO order if last is true or FIFO order if false. - - ''' - if not self: - raise KeyError('dictionary is empty') - root = self.__root - if last: - link = root[0] - link_prev = link[0] - link_prev[1] = root - root[0] = link_prev - else: - link = root[1] - link_next = link[1] - root[1] = link_next - link_next[0] = root - key = link[2] - del self.__map[key] - value = dict.pop(self, key) - return key, value - - # -- the following methods do not depend on the internal structure -- - - def keys(self): - 'od.keys() -> list of keys in od' - return list(self) - - def values(self): - 'od.values() -> list of values in od' - return [self[key] for key in self] - - def items(self): - 'od.items() -> list of (key, value) pairs in od' - return [(key, self[key]) for key in self] - - def iterkeys(self): - 'od.iterkeys() -> an iterator over the keys in od' - return iter(self) - - def itervalues(self): - 'od.itervalues -> an iterator over the values in od' - for k in self: - yield self[k] - - def items(self): - 'od.items -> an iterator over the (key, value) items in od' - for k in self: - yield (k, self[k]) - - # Suppress 'OrderedDict.update: Method has no argument': - # pylint: disable=E0211 - def update(*args, **kwds): - '''od.update(E, **F) -> None. Update od from dict/iterable E and F. - - If E is a dict instance, does: for k in E: od[k] = E[k] - If E has a .keys() method, does: for k in E.keys(): od[k] = E[k] - Or if E is an iterable of items, does: for k, v in E: od[k] = v - In either case, this is followed by: for k, v in F.items(): od[k] = v - - ''' - if len(args) > 2: - raise TypeError('update() takes at most 2 positional ' - 'arguments (%d given)' % (len(args),)) - elif not args: - raise TypeError('update() takes at least 1 argument (0 given)') - self = args[0] - # Make progressively weaker assumptions about "other" - other = () - if len(args) == 2: - other = args[1] - if isinstance(other, dict): - for key in other: - self[key] = other[key] - elif hasattr(other, 'keys'): - for key in other.keys(): - self[key] = other[key] - else: - for key, value in other: - self[key] = value - for key, value in kwds.items(): - self[key] = value - - __update = update # let subclasses override update without breaking __init__ - - __marker = object() - - def pop(self, key, default=__marker): - '''od.pop(k[,d]) -> v, remove specified key and return the corresponding value. - If key is not found, d is returned if given, otherwise KeyError is raised. - - ''' - if key in self: - result = self[key] - del self[key] - return result - if default is self.__marker: - raise KeyError(key) - return default - - def setdefault(self, key, default=None): - 'od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od' - if key in self: - return self[key] - self[key] = default - return default - - def __repr__(self, _repr_running={}): - 'od.__repr__() <==> repr(od)' - call_key = id(self), _get_ident() - if call_key in _repr_running: - return '...' - _repr_running[call_key] = 1 - try: - if not self: - return '%s()' % (self.__class__.__name__,) - return '%s(%r)' % (self.__class__.__name__, self.items()) - finally: - del _repr_running[call_key] - - def __reduce__(self): - 'Return state information for pickling' - items = [[k, self[k]] for k in self] - inst_dict = vars(self).copy() - for k in vars(OrderedDict()): - inst_dict.pop(k, None) - if inst_dict: - return (self.__class__, (items,), inst_dict) - return self.__class__, (items,) - - def copy(self): - 'od.copy() -> a shallow copy of od' - return self.__class__(self) - - @classmethod - def fromkeys(cls, iterable, value=None): - '''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S - and values equal to v (which defaults to None). - - ''' - d = cls() - for key in iterable: - d[key] = value - return d - - def __eq__(self, other): - '''od.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive - while comparison to a regular mapping is order-insensitive. - - ''' - if isinstance(other, OrderedDict): - return len(self)==len(other) and self.items() == other.items() - return dict.__eq__(self, other) - - def __ne__(self, other): - return not self == other - - # -- the following methods are only used in Python 2.7 -- - - def viewkeys(self): - "od.viewkeys() -> a set-like object providing a view on od's keys" - return KeysView(self) - - def viewvalues(self): - "od.viewvalues() -> an object providing a view on od's values" - return ValuesView(self) - - def viewitems(self): - "od.viewitems() -> a set-like object providing a view on od's items" - return ItemsView(self) - +from collections import OrderedDict diff --git a/gyp/pylib/gyp/simple_copy.py b/gyp/pylib/gyp/simple_copy.py index 463929386e..3eefc91fb9 100644 --- a/gyp/pylib/gyp/simple_copy.py +++ b/gyp/pylib/gyp/simple_copy.py @@ -7,7 +7,10 @@ because gyp copies so large structure that small copy overhead ends up taking seconds in a project the size of Chromium.""" -class Error(Exception): +from gyp.compat import simple_types + + +class CopyError(Exception): pass __all__ = ["Error", "deepcopy"] @@ -20,7 +23,7 @@ def deepcopy(x): try: return _deepcopy_dispatch[type(x)](x) except KeyError: - raise Error('Unsupported type %s for deepcopy. Use copy.deepcopy ' + + raise CopyError('Unsupported type %s for deepcopy. Use copy.deepcopy ' + 'or expand simple_copy support.' % type(x)) _deepcopy_dispatch = d = {} @@ -28,8 +31,7 @@ def deepcopy(x): def _deepcopy_atomic(x): return x -for x in (type(None), int, long, float, - bool, str, unicode, type): +for x in simple_types: d[x] = _deepcopy_atomic def _deepcopy_list(x): diff --git a/gyp/pylib/gyp/xcode_emulation.py b/gyp/pylib/gyp/xcode_emulation.py index 66f325932a..6e4119ed96 100644 --- a/gyp/pylib/gyp/xcode_emulation.py +++ b/gyp/pylib/gyp/xcode_emulation.py @@ -1636,7 +1636,7 @@ def _HasIOSTarget(targets): def _AddIOSDeviceConfigurations(targets): """Clone all targets and append -iphoneos to the name. Configure these targets to build for iOS devices and use correct architectures for those builds.""" - for target_dict in targets.itervalues(): + for target_dict in targets.values(): toolset = target_dict['toolset'] configs = target_dict['configurations'] for config_name, config_dict in dict(configs).items(): diff --git a/gyp/pylib/gyp/xcode_ninja.py b/gyp/pylib/gyp/xcode_ninja.py index 5acd82e004..39c4904310 100644 --- a/gyp/pylib/gyp/xcode_ninja.py +++ b/gyp/pylib/gyp/xcode_ninja.py @@ -85,7 +85,7 @@ def _TargetFromSpec(old_spec, params): "%s/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)" % ninja_toplevel if 'configurations' in old_spec: - for config in old_spec['configurations'].iterkeys(): + for config in old_spec['configurations'].keys(): old_xcode_settings = \ old_spec['configurations'][config].get('xcode_settings', {}) if 'IPHONEOS_DEPLOYMENT_TARGET' in old_xcode_settings: diff --git a/gyp/pylib/gyp/xcodeproj_file.py b/gyp/pylib/gyp/xcodeproj_file.py index 9bd582e477..7f9fbef135 100644 --- a/gyp/pylib/gyp/xcodeproj_file.py +++ b/gyp/pylib/gyp/xcodeproj_file.py @@ -138,6 +138,7 @@ """ import gyp.common +from gyp.compat import string_types, unicode_type, compat_cmp import posixpath import re import struct @@ -154,7 +155,6 @@ import sha _new_sha1 = sha.new - # See XCObject._EncodeString. This pattern is used to determine when a string # can be printed unquoted. Strings that match this pattern may be printed # unquoted. Strings that do not match must be quoted and may be further @@ -324,8 +324,7 @@ def Copy(self): that._properties[key] = new_value else: that._properties[key] = value - elif isinstance(value, str) or isinstance(value, unicode) or \ - isinstance(value, int): + elif isinstance(value, string_types) or isinstance(value, int): that._properties[key] = value elif isinstance(value, list): if is_strong: @@ -603,7 +602,7 @@ def _XCPrintableValue(self, tabs, value, flatten_list=False): comment = value.Comment() elif isinstance(value, str): printable += self._EncodeString(value) - elif isinstance(value, unicode): + elif isinstance(value, unicode_type): printable += self._EncodeString(value.encode('utf-8')) elif isinstance(value, int): printable += str(value) @@ -766,7 +765,7 @@ def UpdateProperties(self, properties, do_copy=False): ' must be list, not ' + value.__class__.__name__) for item in value: if not isinstance(item, property_type) and \ - not (item.__class__ == unicode and property_type == str): + not (item.__class__ == unicode_type and property_type == str): # Accept unicode where str is specified. str is treated as # UTF-8-encoded. raise TypeError( @@ -774,7 +773,7 @@ def UpdateProperties(self, properties, do_copy=False): ' must be ' + property_type.__name__ + ', not ' + \ item.__class__.__name__) elif not isinstance(value, property_type) and \ - not (value.__class__ == unicode and property_type == str): + not (value.__class__ == unicode_type and property_type == str): # Accept unicode where str is specified. str is treated as # UTF-8-encoded. raise TypeError( @@ -788,8 +787,7 @@ def UpdateProperties(self, properties, do_copy=False): self._properties[property] = value.Copy() else: self._properties[property] = value - elif isinstance(value, str) or isinstance(value, unicode) or \ - isinstance(value, int): + elif isinstance(value, string_types) or isinstance(value, int): self._properties[property] = value elif isinstance(value, list): if is_strong: @@ -1016,7 +1014,7 @@ def Compare(self, other): if self_type == other_type: # If the two objects are of the same sort rank, compare their names. - return cmp(self.Name(), other.Name()) + return compat_cmp(self.Name(), other.Name()) # Otherwise, sort groups before everything else. if self_type == 'group': @@ -2733,7 +2731,7 @@ def AddOrGetProjectReference(self, other_pbxproject): # Xcode seems to sort this list case-insensitively self._properties['projectReferences'] = \ sorted(self._properties['projectReferences'], cmp=lambda x,y: - cmp(x['ProjectRef'].Name().lower(), + compat_cmp(x['ProjectRef'].Name().lower(), y['ProjectRef'].Name().lower())) else: # The link already exists. Pull out the relevnt data. @@ -2842,7 +2840,7 @@ def CompareProducts(x, y, remote_products): # Use the order of each remote PBXFileReference in remote_products to # determine the sort order. - return cmp(x_index, y_index) + return compat_cmp(x_index, y_index) for other_pbxproject, ref_dict in self._other_pbxprojects.items(): # Build up a list of products in the remote project file, ordered the @@ -2890,7 +2888,7 @@ def Print(self, file=sys.stdout): else: self._XCPrint(file, 0, '{\n') for property, value in sorted(self._properties.items(), - cmp=lambda x, y: cmp(x, y)): + cmp=lambda x, y: compat_cmp(x, y)): if property == 'objects': self._PrintObjects(file) else: @@ -2917,7 +2915,7 @@ def _PrintObjects(self, file): self._XCPrint(file, 0, '\n') self._XCPrint(file, 0, '/* Begin ' + class_name + ' section */\n') for object in sorted(objects_by_class[class_name], - cmp=lambda x, y: cmp(x.id, y.id)): + cmp=lambda x, y: compat_cmp(x.id, y.id)): object.Print(file) self._XCPrint(file, 0, '/* End ' + class_name + ' section */\n') diff --git a/gyp/tools/pretty_vcproj.py b/gyp/tools/pretty_vcproj.py index 51cfc4e081..b8405ef3a1 100755 --- a/gyp/tools/pretty_vcproj.py +++ b/gyp/tools/pretty_vcproj.py @@ -17,6 +17,7 @@ import os import sys +from gyp.compat import compat_cmp from xml.dom.minidom import parse from xml.dom.minidom import Node @@ -28,7 +29,7 @@ class CmpTuple(object): """Compare function between 2 tuple.""" def __call__(self, x, y): - return cmp(x[0], y[0]) + return compat_cmp(x[0], y[0]) class CmpNode(object): @@ -56,7 +57,7 @@ def get_string(node): return node_string - return cmp(get_string(x), get_string(y)) + return compat_cmp(get_string(x), get_string(y)) def PrettyPrintNode(node, indent=0): diff --git a/lib/configure.js b/lib/configure.js index 33bb7e746a..72950fdf2e 100644 --- a/lib/configure.js +++ b/lib/configure.js @@ -421,7 +421,7 @@ PythonFinder.prototype = { var env = extend({}, this.env) env.TERM = 'dumb' - var launcherArgs = ['-2', '-c', 'import sys; print sys.executable'] + var launcherArgs = ['-2', '-c', 'import sys; print(sys.executable)'] this.execFile('py.exe', launcherArgs, { env: env }, function (err, stdout) { if (err) { this.guessPython() @@ -449,7 +449,9 @@ PythonFinder.prototype = { '`%s -c "' + args[1] + '"` returned: %j', this.python, stdout) var version = stdout.trim() - var range = semver.Range('>=2.5.0 <3.0.0') + // we don't support syntax of python less than 2.7 + // Probably, we need to be even more precise like 2.7.10 or even 2.7.15 + var range = semver.Range('>=2.7.0 <4.0.0') var valid = false try { valid = range.test(version) @@ -474,11 +476,13 @@ PythonFinder.prototype = { }, failPythonVersion: function failPythonVersion (badVersion) { + // we don't support syntax of python less than 2.7 + // Probably, we need to be even more precise like 2.7.10 or even 2.7.15 var errmsg = 'Python executable "' + this.python + '" is v' + badVersion + ', which is not supported by gyp.\n' + 'You can pass the --python switch to point to ' + - 'Python >= v2.5.0 & < 3.0.0.' + 'Python >= v2.7.0 & < 4.0.0.' this.callback(new Error(errmsg)) }, diff --git a/test/fixtures/test-charmap.py b/test/fixtures/test-charmap.py index b752f0bbbf..d39043a09c 100644 --- a/test/fixtures/test-charmap.py +++ b/test/fixtures/test-charmap.py @@ -1,7 +1,17 @@ from __future__ import print_function import sys +import importlib import locale + +if hasattr(importlib, 'reload'): + reload = importlib.reload + +if hasattr(sys, 'setdefaultencoding'): + setdefaultencoding = sys.setdefaultencoding +else: + def setdefaultencoding(*args, **kwargs): + pass reload(sys) def main(): @@ -9,7 +19,7 @@ def main(): if not encoding: return False - sys.setdefaultencoding(encoding) + setdefaultencoding(encoding) textmap = { 'cp936': u'\u4e2d\u6587', 'cp1252': u'Lat\u012Bna', diff --git a/test/test-addon.js b/test/test-addon.js index 900b0b049d..705b9a7d11 100644 --- a/test/test-addon.js +++ b/test/test-addon.js @@ -20,7 +20,7 @@ function runHello(hostProcess) { } function getEncoding() { - var code = 'import locale;print locale.getdefaultlocale()[1]' + var code = 'import locale;print(locale.getdefaultlocale()[1])' return execFileSync('python', ['-c', code]).toString().trim() } diff --git a/test/test-find-python.js b/test/test-find-python.js index 250e37f4fe..40a229340e 100644 --- a/test/test-find-python.js +++ b/test/test-find-python.js @@ -13,8 +13,8 @@ test('find python', function (t) { t.strictEqual(err, null) var proc = execFile(found, ['-V'], function (err, stdout, stderr) { t.strictEqual(err, null) - t.strictEqual(stdout, '') - t.ok(/Python 2/.test(stderr)) + t.strictEqual(stderr, '') + t.ok(/Python /.test(stdout)) }) proc.stdout.setEncoding('utf-8') proc.stderr.setEncoding('utf-8') @@ -104,7 +104,7 @@ test('find python - python too new', function (t) { f.execFile = function(program, args, opts, cb) { t.strictEqual(program, 'python') t.ok(/import sys/.test(args[1])) - cb(null, '3.0.0') + cb(null, '4.0.0') } f.checkPython() @@ -230,7 +230,7 @@ test('find python - python 3, use python launcher', function (t) { } t.strictEqual(program, 'python') t.ok(/import sys/.test(args[1])) - cb(null, '3.0.0') + cb(null, '4.0.0') } f.checkPython() @@ -267,7 +267,7 @@ test('find python - python 3, use python launcher, python 2 too old', } t.strictEqual(program, 'python') t.ok(/import sys/.test(args[1])) - cb(null, '3.0.0') + cb(null, '4.0.0') } f.checkPython() diff --git a/tools/gyp/pylib/gyp/generator/compile_commands_json.py b/tools/gyp/pylib/gyp/generator/compile_commands_json.py index 575db63c4e..1b8490451f 100644 --- a/tools/gyp/pylib/gyp/generator/compile_commands_json.py +++ b/tools/gyp/pylib/gyp/generator/compile_commands_json.py @@ -43,7 +43,7 @@ def CalculateVariables(default_variables, params): def AddCommandsForTarget(cwd, target, params, per_config_commands): output_dir = params['generator_flags']['output_dir'] - for configuration_name, configuration in target['configurations'].iteritems(): + for configuration_name, configuration in target['configurations'].items(): builddir_name = os.path.join(output_dir, configuration_name) if IsMac(params): @@ -92,7 +92,7 @@ def resolve(filename): def GenerateOutput(target_list, target_dicts, data, params): per_config_commands = {} - for qualified_target, target in target_dicts.iteritems(): + for qualified_target, target in target_dicts.items(): build_file, target_name, toolset = ( gyp.common.ParseQualifiedTarget(qualified_target)) if IsMac(params): @@ -102,7 +102,7 @@ def GenerateOutput(target_list, target_dicts, data, params): AddCommandsForTarget(cwd, target, params, per_config_commands) output_dir = params['generator_flags']['output_dir'] - for configuration_name, commands in per_config_commands.iteritems(): + for configuration_name, commands in per_config_commands.items(): filename = os.path.join(output_dir, configuration_name, 'compile_commands.json')