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

lib: try to find python after python3 #1907

Closed
wants to merge 3 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
26 changes: 13 additions & 13 deletions lib/find-python.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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') },
Expand All @@ -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({
Expand All @@ -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
Expand Down
15 changes: 7 additions & 8 deletions test/test-find-python.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -178,24 +180,21 @@ 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:[\\/]Python27[\\/]python[.]exe/
var re = /C:[\\/]Python37[\\/]python[.]exe/
var f = new TestPythonFinder(null, done)
f.win = true

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