Skip to content

Commit

Permalink
More miscellaneous fixes for Python3 compatibility.
Browse files Browse the repository at this point in the history
This patch fixes a bunch of stuff flake8 revealed (thanks to
[email protected] for the tip!) and a few dangling print
statements (thanks to [email protected] for the tip!).

Bug: gyp:36
Change-Id: Ie24cdda2613c7d76bf06875f9de435e001a3e8b6
Reviewed-on: https://chromium-review.googlesource.com/c/1368752
Reviewed-by: Mark Mentovai <[email protected]>
Reviewed-by: Dirk Pranke <[email protected]>
  • Loading branch information
dpranke committed Dec 10, 2018
1 parent 703706c commit bd11dd1
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gyptest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def main(argv=None):
os.chdir(args.chdir)

if args.path:
extra_path = [os.path.abspath(p) for p in opts.path]
extra_path = [os.path.abspath(p) for p in args.path]
extra_path = os.pathsep.join(extra_path)
os.environ['PATH'] = extra_path + os.pathsep + os.environ['PATH']

Expand Down
7 changes: 7 additions & 0 deletions pylib/gyp/MSVSNew.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
_new_md5 = md5.new


try:
# cmp was removed in python3.
cmp
except NameError:
def cmp(a, b):
return (a > b) - (a < b)

# Initialize random number generator
random.seed()

Expand Down
2 changes: 1 addition & 1 deletion pylib/gyp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ def TopologicallySorted(graph, get_edges):
graph = {'a': '$(b) $(c)', 'b': 'hi', 'c': '$(b)'}
def GetEdges(node):
return re.findall(r'\$\(([^))]\)', graph[node])
print TopologicallySorted(graph.keys(), GetEdges)
print(TopologicallySorted(graph.keys(), GetEdges))
==>
['a', 'c', b']
"""
Expand Down
2 changes: 1 addition & 1 deletion pylib/gyp/generator/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
self.WriteDoCmd([self.output_binary], deps, 'touch', part_of_all,
postbuilds=postbuilds)
else:
print("WARNING: no output for", self.type, target)
print("WARNING: no output for", self.type, self.target)

# Add an alias for each target (if there are any outputs).
# Installable target aliases are created below.
Expand Down
8 changes: 3 additions & 5 deletions pylib/gyp/generator/msvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,8 @@ def _ConfigWindowsTargetPlatformVersion(config_data, version):
if names:
return names[0]
else:
print >> sys.stdout, (
'Warning: No include files found for '
'detected Windows SDK version %s' % (version)
)
print('Warning: No include files found for '
'detected Windows SDK version %s' % (version))


def _BuildCommandLineForRuleRaw(spec, cmd, cygwin_shell, has_input_path,
Expand Down Expand Up @@ -2065,7 +2063,7 @@ def GenerateOutput(target_list, target_dicts, data, params):
if generator_flags.get('msvs_error_on_missing_sources', False):
raise GypError(error_message)
else:
print("Warning: " + error_message, file=sys.stdout)
print("Warning: " + error_message)


def _GenerateMSBuildFiltersFile(filters_path, source_files,
Expand Down
2 changes: 1 addition & 1 deletion pylib/gyp/mac_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ def WriteHmap(output_name, filelist):
count = len(filelist)
capacity = NextGreaterPowerOf2(count)
strings_offset = 24 + (12 * capacity)
max_value_length = len(max(filelist.items(), key=lambda (k,v):len(v))[1])
max_value_length = len(max(filelist.items(), key=lambda t: len(t[1]))[1])

out = open(output_name, "wb")
out.write(struct.pack('<LHHLLLL', magic, version, _reserved, strings_offset,
Expand Down
7 changes: 7 additions & 0 deletions pylib/gyp/xcodeproj_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@
except NameError:
basestring = str

try:
# cmp was removed in python3.
cmp
except NameError:
def cmp(a, b):
return (a > b) - (a < b)

# 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
Expand Down
8 changes: 5 additions & 3 deletions samples/samples
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from __future__ import print_function

import os.path
import shutil
import sys
Expand Down Expand Up @@ -57,7 +59,7 @@ gyps = [

def Main(argv):
if len(argv) != 3 or argv[1] not in ['push', 'pull']:
print 'Usage: %s push/pull PATH_TO_CHROME' % argv[0]
print('Usage: %s push/pull PATH_TO_CHROME' % argv[0])
return 1

path_to_chrome = argv[2]
Expand All @@ -66,10 +68,10 @@ def Main(argv):
chrome_file = os.path.join(path_to_chrome, g)
local_file = os.path.join(os.path.dirname(argv[0]), os.path.split(g)[1])
if argv[1] == 'push':
print 'Copying %s to %s' % (local_file, chrome_file)
print('Copying %s to %s' % (local_file, chrome_file))
shutil.copyfile(local_file, chrome_file)
elif argv[1] == 'pull':
print 'Copying %s to %s' % (chrome_file, local_file)
print('Copying %s to %s' % (chrome_file, local_file))
shutil.copyfile(chrome_file, local_file)
else:
assert False
Expand Down
2 changes: 1 addition & 1 deletion test/actions/src/action_missing_name.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'action': [
'python',
'-c',
'print \'missing name\'',
'from __future__ import print_function; print(\'missing name\')',
],
},
],
Expand Down
2 changes: 0 additions & 2 deletions test/intermediate_dir/src/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
sys.argv[2], fourth = shlex.split(sys.argv[2].replace('\\', '\\\\'))
sys.argv.append(fourth)

#print >>sys.stderr, sys.argv

with open(sys.argv[2], 'w') as f:
f.write(sys.argv[1])

Expand Down
4 changes: 2 additions & 2 deletions test/lib/TestCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,13 +829,13 @@ def recv_some(p, t=.1, e=1, tr=5, stderr=0):
time.sleep(max((x-time.time())/tr, 0))
return ''.join(y)

# TODO(3.0: rewrite to use memoryview()
def send_all(p, data):
data = memoryview(data)
while len(data):
sent = p.send(data)
if sent is None:
raise Exception(disconnect_message)
data = buffer(data, sent)
data = data[sent:]



Expand Down
10 changes: 8 additions & 2 deletions tools/pretty_vcproj.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
from xml.dom.minidom import parse
from xml.dom.minidom import Node

try:
# cmp was removed in python3.
cmp
except NameError:
def cmp(a, b):
return (a > b) - (a < b)

REPLACEMENTS = dict()
ARGUMENTS = None

Expand Down Expand Up @@ -63,7 +70,7 @@ def get_string(node):
def PrettyPrintNode(node, indent=0):
if node.nodeType == Node.TEXT_NODE:
if node.data.strip():
print '%s%s' % (' '*indent, node.data.strip())
print('%s%s' % (' '*indent, node.data.strip()))
return

if node.childNodes:
Expand Down Expand Up @@ -322,7 +329,6 @@ def main(argv):

# Finally, we use the prett xml function to print the vcproj back to the
# user.
#print dom.toprettyxml(newl="\n")
PrettyPrintNode(dom.documentElement)
return 0

Expand Down

0 comments on commit bd11dd1

Please sign in to comment.