From 9ed7423e809163c04cc1d61fe22f35e92b7a6b4f Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Thu, 3 Oct 2019 08:18:36 -0700 Subject: [PATCH 1/3] lib: try to find `python` after `python3` Unadorned `python` can be either Python 2 or Python 3, but it is likely to be Python 2 for quite a while. To find Python3, it is recommended to use the explicit name `python3`. See: - https://www.python.org/dev/peps/pep-0394/#for-python-runtime-distributors - https://github.com/nodejs/node-gyp/pull/1892#issuecomment-537637433 --- lib/find-python.js | 12 ++++++------ test/test-find-python.js | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/find-python.js b/lib/find-python.js index c12ccc3bb2..4ed513d86b 100644 --- a/lib/find-python.js +++ b/lib/find-python.js @@ -26,8 +26,8 @@ PythonFinder.prototype = { win: win, pyLauncher: 'py.exe', winDefaultLocations: [ - path.join(process.env.SystemDrive || 'C:', 'Python27', 'python.exe'), - path.join(process.env.SystemDrive || 'C:', 'Python37', 'python.exe') + path.join(process.env.SystemDrive || 'C:', 'Python37', 'python.exe'), + path.join(process.env.SystemDrive || 'C:', 'Python27', 'python.exe') ], // Logs a message at verbose level, but also saves it to be displayed later @@ -88,14 +88,14 @@ PythonFinder.prototype = { arg: this.env.PYTHON }, { - before: () => { this.addLog('checking if "python" can be used') }, + before: () => { this.addLog('checking if "python3" can be used') }, check: this.checkCommand, - arg: 'python' + arg: 'python3' }, { - before: () => { this.addLog('checking if "python3" can be used') }, + before: () => { this.addLog('checking if "python" can be used') }, check: this.checkCommand, - arg: 'python3' + arg: 'python' }, { before: () => { this.addLog('checking if "python2" can be used') }, diff --git a/test/test-find-python.js b/test/test-find-python.js index 1c86f45b73..582624e101 100644 --- a/test/test-find-python.js +++ b/test/test-find-python.js @@ -180,7 +180,7 @@ test('find python - no python, use python launcher', function (t) { test('find python - no python, no python launcher, good guess', function (t) { t.plan(4) - var re = /C:[\\/]Python27[\\/]python[.]exe/ + var re = /C:[\\/]Python37[\\/]python[.]exe/ var f = new TestPythonFinder(null, done) f.win = true From 2b3dad968dd22af2f38e36eb309d66489c72bfbc Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Thu, 3 Oct 2019 10:01:05 -0700 Subject: [PATCH 2/3] fixup! lib: try to find `python` after `python3` --- lib/find-python.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/find-python.js b/lib/find-python.js index 4ed513d86b..9d918a881b 100644 --- a/lib/find-python.js +++ b/lib/find-python.js @@ -105,13 +105,6 @@ PythonFinder.prototype = { ] if (this.win) { - checks.push({ - before: () => { - this.addLog( - 'checking if the py launcher can be used to find Python 2') - }, - check: this.checkPyLauncher - }) for (var i = 0; i < this.winDefaultLocations.length; ++i) { const location = this.winDefaultLocations[i] checks.push({ @@ -123,6 +116,13 @@ PythonFinder.prototype = { arg: location }) } + checks.push({ + before: () => { + this.addLog( + 'checking if the py launcher can be used to find Python 2') + }, + check: this.checkPyLauncher + }) } return checks From 2fb4fc49573933804e9c1551d61d89bf6c249a46 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Thu, 3 Oct 2019 11:04:59 -0700 Subject: [PATCH 3/3] fixup! fixup! lib: try to find `python` after `python3` --- test/test-find-python.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/test-find-python.js b/test/test-find-python.js index 582624e101..6ca522a04c 100644 --- a/test/test-find-python.js +++ b/test/test-find-python.js @@ -159,6 +159,8 @@ test('find python - no python, use python launcher', function (t) { } if (/sys\.executable/.test(args[args.length - 1])) { cb(new Error('not found')) + } else if (f.winDefaultLocations.includes(program)) { + cb(new Error('not found')) } else if (/sys\.version_info/.test(args[args.length - 1])) { if (program === 'Z:\\snake.exe') { cb(null, '2.7.14') @@ -178,7 +180,7 @@ test('find python - no python, use python launcher', function (t) { }) test('find python - no python, no python launcher, good guess', function (t) { - t.plan(4) + t.plan(2) var re = /C:[\\/]Python37[\\/]python[.]exe/ var f = new TestPythonFinder(null, done) @@ -186,16 +188,13 @@ test('find python - no python, no python launcher, good guess', function (t) { f.execFile = function (program, args, opts, cb) { if (program === 'py.exe') { - f.execFile = function (program, args, opts, cb) { - poison(f, 'execFile') - t.ok(re.test(program)) - t.ok(/sys\.version_info/.test(args[args.length - 1])) - cb(null, '2.7.14') - } return cb(new Error('not found')) } if (/sys\.executable/.test(args[args.length - 1])) { cb(new Error('not found')) + } else if (re.test(program) && + /sys\.version_info/.test(args[args.length - 1])) { + cb(null, '3.7.3') } else { t.fail() }