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

Fix Travis runs with Python 3 #1843

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
17 changes: 11 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ matrix:
python: 2.7
- name: "Python 2.7 on macOS"
os: osx
osx_image: xcode10.2
osx_image: xcode11
language: shell # 'language: python' is not yet supported on macOS
env: NODE_GYP_FORCE_PYTHON=python2
before_install: HOMEBREW_NO_AUTO_UPDATE=1 brew install npm
Expand All @@ -28,6 +28,7 @@ matrix:
PATH=/c/Python27:/c/Python27/Scripts:$PATH
NODE_GYP_FORCE_PYTHON=/c/Python27/python.exe
before_install: choco install python2

- name: "Node.js 6 & Python 3.7 on Linux"
python: 3.7
env: NODE_GYP_FORCE_PYTHON=python3 EXPERIMENTAL_NODE_GYP_PYTHON3=1
Expand All @@ -44,6 +45,12 @@ matrix:
python: 3.7
env: NODE_GYP_FORCE_PYTHON=python3 EXPERIMENTAL_NODE_GYP_PYTHON3=1
before_install: nvm install 12
- name: "Python 3.7 on macOS"
os: osx
#osx_image: xcode11
language: shell # 'language: python' is not yet supported on macOS
env: NODE_GYP_FORCE_PYTHON=python3 EXPERIMENTAL_NODE_GYP_PYTHON3=1
before_install: HOMEBREW_NO_AUTO_UPDATE=1 brew install npm
- name: "Node.js 12 & Python 3.7 on Windows"
os: windows
language: node_js
Expand All @@ -53,12 +60,10 @@ matrix:
NODE_GYP_FORCE_PYTHON=/c/Python37/python.exe
EXPERIMENTAL_NODE_GYP_PYTHON3=1
before_install: choco install python

allow_failures:
- env: NODE_GYP_FORCE_PYTHON=python3 EXPERIMENTAL_NODE_GYP_PYTHON3=1
- env: >-
PATH=/c/Python37:/c/Python37/Scripts:$PATH
NODE_GYP_FORCE_PYTHON=/c/Python37/python.exe
EXPERIMENTAL_NODE_GYP_PYTHON3=1
- os: osx
env: NODE_GYP_FORCE_PYTHON=python3 EXPERIMENTAL_NODE_GYP_PYTHON3=1
install:
#- pip install -r requirements.txt
- pip install flake8 # pytest # add another testing frameworks later
Expand Down
2 changes: 1 addition & 1 deletion gyp/pylib/gyp/MSVSNew.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def MakeGuid(name, seed='msvs_new'):
not change when the project for a target is rebuilt.
"""
# Calculate a MD5 signature for the seed and name.
d = hashlib.md5(str(seed) + str(name)).hexdigest().upper()
d = hashlib.md5((str(seed) + str(name)).encode('utf-8')).hexdigest().upper()
# Convert most of the signature to GUID form (discard the rest)
guid = ('{' + d[:8] + '-' + d[8:12] + '-' + d[12:16] + '-' + d[16:20]
+ '-' + d[20:32] + '}')
Expand Down
3 changes: 3 additions & 0 deletions gyp/pylib/gyp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ def close(self):
os.unlink(self.tmp_path)
raise

def write(self, s):
self.tmp_file.write(s.encode('utf-8'))

return Writer()


Expand Down
4 changes: 2 additions & 2 deletions gyp/pylib/gyp/easy_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def WriteXmlIfChanged(content, path, encoding='utf-8', pretty=False,

default_encoding = locale.getdefaultlocale()[1]
if default_encoding.upper() != encoding.upper():
xml_string = xml_string.decode(default_encoding).encode(encoding)
xml_string = xml_string.encode(encoding)

# Get the old content
try:
Expand All @@ -132,7 +132,7 @@ def WriteXmlIfChanged(content, path, encoding='utf-8', pretty=False,

# It has changed, write it
if existing != xml_string:
f = open(path, 'w')
f = open(path, 'wb')
f.write(xml_string)
f.close()

Expand Down
8 changes: 4 additions & 4 deletions gyp/pylib/gyp/generator/msvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,8 +1753,8 @@ def _CollapseSingles(parent, node):
# such projects up one level.
if (type(node) == dict and
len(node) == 1 and
node.keys()[0] == parent + '.vcproj'):
return node[node.keys()[0]]
list(node)[0] == parent + '.vcproj'):
return node[list(node)[0]]
if type(node) != dict:
return node
for child in node:
Expand All @@ -1773,8 +1773,8 @@ def _GatherSolutionFolders(sln_projects, project_objects, flat):
# Walk down from the top until we hit a folder that has more than one entry.
# In practice, this strips the top-level "src/" dir from the hierarchy in
# the solution.
while len(root) == 1 and type(root[root.keys()[0]]) == dict:
root = root[root.keys()[0]]
while len(root) == 1 and type(root[list(root)[0]]) == dict:
root = root[list(root)[0]]
# Collapse singles.
root = _CollapseSingles('', root)
# Merge buckets until everything is a root entry.
Expand Down
15 changes: 10 additions & 5 deletions test/test-find-python.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use strict'

delete process.env.PYTHON

const test = require('tap').test
const findPython = require('../lib/find-python')
const execFile = require('child_process').execFile
const PythonFinder = findPython.test.PythonFinder

delete process.env.PYTHON
delete process.env.NODE_GYP_FORCE_PYTHON

require('npmlog').level = 'warn'

test('find python', function (t) {
Expand All @@ -17,8 +16,13 @@ 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))
if (/Python 2/.test(stderr)) {
t.strictEqual(stdout, '')
t.ok(/Python 2/.test(stderr))
} else {
t.ok(/Python 3/.test(stdout))
t.strictEqual(stderr, '')
}
})
proc.stdout.setEncoding('utf-8')
proc.stderr.setEncoding('utf-8')
Expand Down Expand Up @@ -51,6 +55,7 @@ TestPythonFinder.prototype.log = {
warn: () => {},
error: () => {}
}
delete TestPythonFinder.prototype.env.NODE_GYP_FORCE_PYTHON

test('find python - python', function (t) {
t.plan(6)
Expand Down