From 53185e474bd3b094ba5b6101e5b61a57b98e38f5 Mon Sep 17 00:00:00 2001 From: StefanStojanovic Date: Wed, 14 Jun 2023 16:33:29 +0200 Subject: [PATCH] lib: find python checks order changed on windows These changes favor py launcher over other checks excluding command line or npm configuration and environment variable checks. Also, updated supported python versions list. Fixes: https://github.com/nodejs/node-gyp/issues/2871 --- lib/find-python.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/find-python.js b/lib/find-python.js index a445e825b9..6362eaaac6 100644 --- a/lib/find-python.js +++ b/lib/find-python.js @@ -15,7 +15,7 @@ const programFiles = process.env.ProgramW6432 || process.env.ProgramFiles || `${ const programFilesX86 = process.env['ProgramFiles(x86)'] || `${programFiles} (x86)` const winDefaultLocationsArray = [] -for (const majorMinor of ['39', '38', '37', '36']) { +for (const majorMinor of ['311', '310', '39', '38']) { if (foundLocalAppData) { winDefaultLocationsArray.push( `${localAppData}\\Programs\\Python\\Python${majorMinor}\\python.exe`, @@ -114,7 +114,20 @@ PythonFinder.prototype = { }, check: this.checkCommand, arg: this.env.PYTHON - }, + } + ] + + if (this.win) { + checks.push({ + before: () => { + this.addLog( + 'checking if the py launcher can be used to find Python 3') + }, + check: this.checkPyLauncher + }) + } + + checks.push(...[ { before: () => { this.addLog('checking if "python3" can be used') }, check: this.checkCommand, @@ -125,7 +138,7 @@ PythonFinder.prototype = { check: this.checkCommand, arg: 'python' } - ] + ]) if (this.win) { for (var i = 0; i < this.winDefaultLocations.length; ++i) { @@ -139,13 +152,6 @@ PythonFinder.prototype = { arg: location }) } - checks.push({ - before: () => { - this.addLog( - 'checking if the py launcher can be used to find Python 3') - }, - check: this.checkPyLauncher - }) } return checks