Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize Python 2 code to get ready for Python 3 #2

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
Generate You Projects
===================================

Documentation is available at [gyp.gsrc.io](https://gyp.gsrc.io) (or at the `md-pages` branch).
Documentation is available at [http://gyp3.org/](http://gyp3.org/) (or at the [`gh-pages`](https://github.com/refack/GYP/blob/gh-pages/index.md) branch).
23 changes: 12 additions & 11 deletions buildbot/buildbot_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# found in the LICENSE file.

"""Argument-less script to select what to run on the buildbots."""
from __future__ import print_function

import os
import shutil
Expand All @@ -24,25 +25,25 @@ def CallSubProcess(*args, **kwargs):
with open(os.devnull) as devnull_fd:
retcode = subprocess.call(stdin=devnull_fd, *args, **kwargs)
if retcode != 0:
print '@@@STEP_EXCEPTION@@@'
print('@@@STEP_EXCEPTION@@@')
sys.exit(1)


def PrepareCmake():
"""Build CMake 2.8.8 since the version in Precise is 2.8.7."""
if os.environ['BUILDBOT_CLOBBER'] == '1':
print '@@@BUILD_STEP Clobber CMake checkout@@@'
print('@@@BUILD_STEP Clobber CMake checkout@@@')
shutil.rmtree(CMAKE_DIR)

# We always build CMake 2.8.8, so no need to do anything
# if the directory already exists.
if os.path.isdir(CMAKE_DIR):
return

print '@@@BUILD_STEP Initialize CMake checkout@@@'
print('@@@BUILD_STEP Initialize CMake checkout@@@')
os.mkdir(CMAKE_DIR)

print '@@@BUILD_STEP Sync CMake@@@'
print('@@@BUILD_STEP Sync CMake@@@')
CallSubProcess(
['git', 'clone',
'--depth', '1',
Expand All @@ -53,7 +54,7 @@ def PrepareCmake():
CMAKE_DIR],
cwd=CMAKE_DIR)

print '@@@BUILD_STEP Build CMake@@@'
print('@@@BUILD_STEP Build CMake@@@')
CallSubProcess(
['/bin/bash', 'bootstrap', '--prefix=%s' % CMAKE_DIR],
cwd=CMAKE_DIR)
Expand All @@ -74,7 +75,7 @@ def GypTestFormat(title, format=None, msvs_version=None, tests=[]):
if not format:
format = title

print '@@@BUILD_STEP ' + title + '@@@'
print('@@@BUILD_STEP ' + title + '@@@')
sys.stdout.flush()
env = os.environ.copy()
if msvs_version:
Expand All @@ -89,17 +90,17 @@ def GypTestFormat(title, format=None, msvs_version=None, tests=[]):
retcode = subprocess.call(command, cwd=ROOT_DIR, env=env, shell=True)
if retcode:
# Emit failure tag, and keep going.
print '@@@STEP_FAILURE@@@'
print('@@@STEP_FAILURE@@@')
return 1
return 0


def GypBuild():
# Dump out/ directory.
print '@@@BUILD_STEP cleanup@@@'
print 'Removing %s...' % OUT_DIR
print('@@@BUILD_STEP cleanup@@@')
print('Removing %s...' % OUT_DIR)
shutil.rmtree(OUT_DIR, ignore_errors=True)
print 'Done.'
print('Done.')

retcode = 0
if sys.platform.startswith('linux'):
Expand Down Expand Up @@ -128,7 +129,7 @@ def GypBuild():
# after the build proper that could be used for cumulative failures),
# use that instead of this. This isolates the final return value so
# that it isn't misattributed to the last stage.
print '@@@BUILD_STEP failures@@@'
print('@@@BUILD_STEP failures@@@')
sys.exit(retcode)


Expand Down
4 changes: 2 additions & 2 deletions pylib/gyp/MSVSSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def ConvertToMSBuildSettings(msvs_settings, stderr=sys.stderr):
# Invoke the translation function.
try:
msvs_tool[msvs_setting](msvs_value, msbuild_settings)
except ValueError, e:
except ValueError as e:
print >> stderr, ('Warning: while converting %s/%s to MSBuild, '
'%s' % (msvs_tool_name, msvs_setting, e))
else:
Expand Down Expand Up @@ -517,7 +517,7 @@ def _ValidateSettings(validators, settings, stderr):
if setting in tool_validators:
try:
tool_validators[setting](value)
except ValueError, e:
except ValueError as e:
print >> stderr, ('Warning: for %s/%s, %s' %
(tool_name, setting, e))
else:
Expand Down
2 changes: 1 addition & 1 deletion pylib/gyp/MSVSVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def _RegistryQuery(key, value=None):
text = None
try:
text = _RegistryQueryBase('Sysnative', key, value)
except OSError, e:
except OSError as e:
if e.errno == errno.ENOENT:
text = _RegistryQueryBase('System32', key, value)
else:
Expand Down
17 changes: 9 additions & 8 deletions pylib/gyp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# 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 copy
import gyp.input
import optparse
Expand Down Expand Up @@ -34,8 +35,8 @@ def DebugOutput(mode, message, *args):
pass
if args:
message %= args
print '%s:%s:%d:%s %s' % (mode.upper(), os.path.basename(ctx[0]),
ctx[1], ctx[2], message)
print('%s:%s:%d:%s %s' % (mode.upper(), os.path.basename(ctx[0]),
ctx[1], ctx[2], message))

def FindBuildFiles():
extension = '.gyp'
Expand Down Expand Up @@ -226,12 +227,12 @@ def Noop(value):
(action == 'store_false' and not value)):
flags.append(opt)
elif options.use_environment and env_name:
print >>sys.stderr, ('Warning: environment regeneration unimplemented '
print(('Warning: environment regeneration unimplemented '
'for %s flag %r env_name %r' % (action, opt,
env_name))
env_name)), file=sys.stderr)
else:
print >>sys.stderr, ('Warning: regeneration unimplemented for action %r '
'flag %r' % (action, opt))
print(('Warning: regeneration unimplemented for action %r '
'flag %r' % (action, opt)), file=sys.stderr)

return flags

Expand Down Expand Up @@ -475,7 +476,7 @@ def gyp_main(args):
if home_dot_gyp != None:
default_include = os.path.join(home_dot_gyp, 'include.gypi')
if os.path.exists(default_include):
print 'Using overrides found in ' + default_include
print('Using overrides found in ' + default_include)
includes.append(default_include)

# Command-line --include files come after the default include.
Expand Down Expand Up @@ -536,7 +537,7 @@ def gyp_main(args):
def main(args):
try:
return gyp_main(args)
except GypError, e:
except GypError as e:
sys.stderr.write("gyp: %s\n" % e)
return 1

Expand Down
8 changes: 4 additions & 4 deletions pylib/gyp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def close(self):
same = False
try:
same = filecmp.cmp(self.tmp_path, filename, False)
except OSError, e:
except OSError as e:
if e.errno != errno.ENOENT:
raise

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

# Make file executable.
os.chmod(tool_path, 0755)
os.chmod(tool_path, 0o755)


# From Alex Martelli,
Expand Down
1 change: 1 addition & 0 deletions pylib/gyp/easy_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import os
import locale
from functools import reduce


def XmlToString(content, encoding='utf-8', pretty=False):
Expand Down
2 changes: 1 addition & 1 deletion pylib/gyp/flock_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def ExecFlock(self, lockfile, *cmd_list):
# where fcntl.flock(fd, LOCK_EX) always fails
# with EBADF, that's why we use this F_SETLK
# hack instead.
fd = os.open(lockfile, os.O_WRONLY|os.O_NOCTTY|os.O_CREAT, 0666)
fd = os.open(lockfile, os.O_WRONLY|os.O_NOCTTY|os.O_CREAT, 0o666)
if sys.platform.startswith('aix'):
# Python on AIX is compiled with LARGEFILE support, which changes the
# struct size.
Expand Down
Loading