From 49ab79d2213d62613aa4494bb516fd3a2897e0b0 Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Sat, 19 Aug 2017 23:18:01 -0400 Subject: [PATCH] python: more informative error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node-gyp/pull/1269 Refs: https://github.com/nodejs/node-gyp/pull/1582 Reviewed-By: Rod Vagg Reviewed-By: João Reis --- .eslintrc.yaml | 1 + .jshintrc | 2 +- bin/node-gyp.js | 8 ++++++-- lib/configure.js | 35 ++++++++++++++++++++++++----------- test/test-find-python.js | 21 ++++++++++++--------- 5 files changed, 44 insertions(+), 23 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 659dce8810..f808ce2d9a 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -1,5 +1,6 @@ --- env: node: true + es6: true rules: no-unused-vars: error diff --git a/.jshintrc b/.jshintrc index 52475ba2e6..4b8521dac0 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,7 +1,7 @@ { "asi": true, "laxcomma": true, - "es5": true, + "esversion": 6, "node": true, "strict": false } diff --git a/bin/node-gyp.js b/bin/node-gyp.js index 8c9b6169bb..55ff48e908 100755 --- a/bin/node-gyp.js +++ b/bin/node-gyp.js @@ -79,8 +79,12 @@ function run () { prog.commands[command.name](command.args, function (err) { if (err) { log.error(command.name + ' error') - log.error('stack', err.stack) - errorMessage() + if (err.noPython) { + log.error(err.message) + } else { + log.error('stack', err.stack) + errorMessage() + } log.error('not ok') return process.exit(1) } diff --git a/lib/configure.js b/lib/configure.js index 33bb7e746a..0a7d5ab53d 100644 --- a/lib/configure.js +++ b/lib/configure.js @@ -449,7 +449,7 @@ PythonFinder.prototype = { '`%s -c "' + args[1] + '"` returned: %j', this.python, stdout) var version = stdout.trim() - var range = semver.Range('>=2.5.0 <3.0.0') + var range = semver.Range('>=2.6.0 <3.0.0') var valid = false try { valid = range.test(version) @@ -467,19 +467,32 @@ PythonFinder.prototype = { }, failNoPython: function failNoPython () { - var errmsg = - 'Can\'t find Python executable "' + this.python + - '", you can set the PYTHON env variable.' - this.callback(new Error(errmsg)) + const err = new Error( + '\n******************************************************************\n' + + `node-gyp can't use "${this.python}",\n` + + 'It is recommended that you install python 2.7, set the PYTHON env,\n' + + 'or use the --python switch to point to a Python >= v2.6.0 & < 3.0.0.\n' + + 'For more information consult the documentation at:\n' + + 'https://github.com/nodejs/node-gyp#installation\n' + + '***********************************************************************' + ); + err.noPython = true; + this.callback(err) }, failPythonVersion: function failPythonVersion (badVersion) { - var errmsg = - 'Python executable "' + this.python + - '" is v' + badVersion + ', which is not supported by gyp.\n' + - 'You can pass the --python switch to point to ' + - 'Python >= v2.5.0 & < 3.0.0.' - this.callback(new Error(errmsg)) + const err = new Error( + '\n******************************************************************\n' + + `Python executable "${this.python}" is v${badVersion}\n` + + 'this version is not supported by GYP and hence by node-gyp.\n' + + 'It is recommended that you install python 2.7, set the PYTHON env,\n' + + 'or use the --python switch to point to a Python >= v2.6.0 & < 3.0.0.\n' + + 'For more information consult the documentation at:\n' + + 'https://github.com/nodejs/node-gyp#installation\n' + + '***********************************************************************' + ); + err.noPython = true; + this.callback(err) }, // Called on Windows when "python" isn't available in the current $PATH. diff --git a/test/test-find-python.js b/test/test-find-python.js index 250e37f4fe..c3209e13e6 100644 --- a/test/test-find-python.js +++ b/test/test-find-python.js @@ -74,7 +74,7 @@ test('find python - python', function (t) { }) test('find python - python too old', function (t) { - t.plan(4) + t.plan(5) var f = new TestPythonFinder('python', done) f.which = function(program, cb) { @@ -89,12 +89,13 @@ test('find python - python too old', function (t) { f.checkPython() function done(err) { - t.ok(/is not supported by gyp/.test(err)) + t.ok(/this version is not supported by GYP/.test(err)) + t.ok(/For more information consult the documentation/.test(err)) } }) test('find python - python too new', function (t) { - t.plan(4) + t.plan(5) var f = new TestPythonFinder('python', done) f.which = function(program, cb) { @@ -109,7 +110,8 @@ test('find python - python too new', function (t) { f.checkPython() function done(err) { - t.ok(/is not supported by gyp/.test(err)) + t.ok(/this version is not supported by GYP/.test(err)) + t.ok(/For more information consult the documentation/.test(err)) } }) @@ -124,7 +126,7 @@ test('find python - no python', function (t) { f.checkPython() function done(err) { - t.ok(/Can't find Python executable/.test(err)) + t.ok(/For more information consult the documentation/.test(err)) } }) @@ -171,7 +173,7 @@ test('find python - no python2, no python, unix', function (t) { f.checkPython() function done(err) { - t.ok(/Can't find Python executable/.test(err)) + t.ok(/For more information consult the documentation/.test(err)) } }) @@ -242,7 +244,7 @@ test('find python - python 3, use python launcher', function (t) { test('find python - python 3, use python launcher, python 2 too old', function (t) { - t.plan(9) + t.plan(10) var f = new TestPythonFinder('python', done) f.checkedPythonLauncher = false @@ -272,7 +274,8 @@ test('find python - python 3, use python launcher, python 2 too old', f.checkPython() function done(err) { - t.ok(/is not supported by gyp/.test(err)) + t.ok(/this version is not supported by GYP/.test(err)) + t.ok(/For more information consult the documentation/.test(err)) } }) @@ -334,6 +337,6 @@ test('find python - no python, no python launcher, bad guess', function (t) { f.checkPython() function done(err) { - t.ok(/Can't find Python executable/.test(err)) + t.ok(/For more information consult the documentation/.test(err)) } })