diff --git a/lib/configure.js b/lib/configure.js index 3034652934..54bb2ccb3a 100644 --- a/lib/configure.js +++ b/lib/configure.js @@ -343,6 +343,7 @@ function PythonFinder(python, callback) { } PythonFinder.prototype = { + checkPythonLauncherDepth: 0, env: process.env, execFile: cp.execFile, log: log, @@ -386,6 +387,8 @@ PythonFinder.prototype = { // executable for "execFile", we have to use the launcher to figure out // where the actual "python.exe" executable is located. checkPythonLauncher: function checkPythonLauncher () { + this.checkPythonLauncherDepth += 1 + this.log.verbose( 'could not find "' + this.python + '". checking python launcher') var env = extend({}, this.env) @@ -395,13 +398,14 @@ PythonFinder.prototype = { this.execFile('py.exe', launcherArgs, { env: env }, function (err, stdout) { if (err) { this.guessPython() - return + } else { + this.python = stdout.trim() + this.log.verbose('check python launcher', + 'python executable found: %j', + this.python) + this.checkPythonVersion() } - this.python = stdout.trim() - this.log.verbose('check python launcher', - 'python executable found: %j', - this.python) - this.checkPythonVersion() + this.checkPythonLauncherDepth -= 1 }.bind(this)) }, @@ -435,6 +439,8 @@ PythonFinder.prototype = { } if (valid) { this.callback(null, this.python) + } else if (this.win && this.checkPythonLauncherDepth === 0) { + this.checkPythonLauncher() } else { this.failPythonVersion(version) } diff --git a/test/test-find-python.js b/test/test-find-python.js index c9089be5e4..30ba6df78b 100644 --- a/test/test-find-python.js +++ b/test/test-find-python.js @@ -195,6 +195,77 @@ test('find python - no python, use python launcher', function (t) { } }) +test('find python - python 3, use python launcher', function (t) { + t.plan(10) + + var f = new TestPythonFinder('python', done) + f.env = {} + f.win = true + + f.which = function(program, cb) { + t.strictEqual(program, 'python') + cb(null, program) + } + f.execFile = function(program, args, opts, cb) { + f.execFile = function(program, args, opts, cb) { + f.execFile = function(program, args, opts, cb) { + t.strictEqual(program, 'Z:\\snake.exe') + t.ok(/import platform/.test(args[1])) + cb(null, '2.7.0') + } + t.strictEqual(program, 'py.exe') + t.notEqual(args.indexOf('-2'), -1) + t.notEqual(args.indexOf('-c'), -1) + cb(null, 'Z:\\snake.exe') + } + t.strictEqual(program, 'python') + t.ok(/import platform/.test(args[1])) + cb(null, '3.0.0') + } + f.checkPython() + + function done(err, python) { + t.strictEqual(err, null) + t.strictEqual(python, 'Z:\\snake.exe') + } +}) + +test('find python - python 3, use python launcher, python 2 too old', + function (t) { + t.plan(9) + + var f = new TestPythonFinder('python', done) + f.checkedPythonLauncher = false + f.env = {} + f.win = true + + f.which = function(program, cb) { + t.strictEqual(program, 'python') + cb(null, program) + } + f.execFile = function(program, args, opts, cb) { + f.execFile = function(program, args, opts, cb) { + f.execFile = function(program, args, opts, cb) { + t.strictEqual(program, 'Z:\\snake.exe') + t.ok(/import platform/.test(args[1])) + cb(null, '2.3.4') + } + t.strictEqual(program, 'py.exe') + t.notEqual(args.indexOf('-2'), -1) + t.notEqual(args.indexOf('-c'), -1) + cb(null, 'Z:\\snake.exe') + } + t.strictEqual(program, 'python') + t.ok(/import platform/.test(args[1])) + cb(null, '3.0.0') + } + f.checkPython() + + function done(err, python) { + t.ok(/is not supported by gyp/.test(err)) + } +}) + test('find python - no python, no python launcher, good guess', function (t) { t.plan(6)