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

Travis CI: Fix the remaining Python 3 issues #1793

Closed
wants to merge 2 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
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ cache: pip
python:
- 2.7
- 3.7
matrix:
allow_failures:
- python: 3.7
install:
#- pip install -r requirements.txt
- pip install flake8 # pytest # add another testing frameworks later
Expand Down
5 changes: 5 additions & 0 deletions gyp/pylib/gyp/MSVSNew.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

import gyp.common

try:
cmp
except NameError:
def cmp(x, y):
return (x > y) - (x < y)

# Initialize random number generator
random.seed()
Expand Down
8 changes: 6 additions & 2 deletions gyp/pylib/gyp/simple_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ def deepcopy(x):
def _deepcopy_atomic(x):
return x

for x in (type(None), int, long, float,
bool, str, unicode, type):
try:
types = bool, float, int, str, type, type(None), long, unicode
except NameError: # Python 3
types = bool, float, int, str, type, type(None)

for x in types:
d[x] = _deepcopy_atomic

def _deepcopy_list(x):
Expand Down
23 changes: 9 additions & 14 deletions gyp/pylib/gyp/xcodeproj_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,18 @@
"""

import gyp.common
import hashlib
import posixpath
import re
import struct
import sys

# hashlib is supplied as of Python 2.5 as the replacement interface for sha
# and other secure hashes. In 2.6, sha is deprecated. Import hashlib if
# available, avoiding a deprecation warning under 2.6. Import sha otherwise,
# preserving 2.4 compatibility.
try:
import hashlib
_new_sha1 = hashlib.sha1
except ImportError:
import sha
_new_sha1 = sha.new
basestring, cmp, unicode
except NameError: # Python 3
basestring = unicode = str
def cmp(x, y):
return (x > y) - (x < y)


# See XCObject._EncodeString. This pattern is used to determine when a string
Expand Down Expand Up @@ -324,8 +321,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, (basestring, int)):
that._properties[key] = value
elif isinstance(value, list):
if is_strong:
Expand Down Expand Up @@ -422,7 +418,7 @@ def _HashUpdate(hash, data):
hash.update(data)

if seed_hash is None:
seed_hash = _new_sha1()
seed_hash = hashlib.sha1()

hash = seed_hash.copy()

Expand Down Expand Up @@ -788,8 +784,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, (basestring, int)):
self._properties[property] = value
elif isinstance(value, list):
if is_strong:
Expand Down
6 changes: 6 additions & 0 deletions gyp/tools/pretty_vcproj.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@

__author__ = 'nsylvain (Nicolas Sylvain)'

try:
cmp
except NameError:
def cmp(x, y):
return (x > y) - (x < y)

REPLACEMENTS = dict()
ARGUMENTS = None

Expand Down
11 changes: 9 additions & 2 deletions test/fixtures/test-charmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
import sys
import locale

reload(sys)
try:
reload(sys)
except NameError: # Python 3
pass

def main():
encoding = locale.getdefaultlocale()[1]
if not encoding:
return False

sys.setdefaultencoding(encoding)
try:
sys.setdefaultencoding(encoding)
except AttributeError: # Python 3
pass

textmap = {
'cp936': u'\u4e2d\u6587',
'cp1252': u'Lat\u012Bna',
Expand Down
2 changes: 1 addition & 1 deletion test/test-addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function runDuplicateBindings() {
}

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()
}

Expand Down