From 8a80547d832bc63c1cf6b3095c102868153688d4 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Mon, 4 Apr 2022 16:42:32 -0700 Subject: [PATCH 1/3] Fixes support for python binaries not following the standard names --- .../pythonEnvironments/common/commonUtils.ts | 17 +++++++---------- .../pythonEnvironments/common/posixUtils.ts | 4 ++-- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/client/pythonEnvironments/common/commonUtils.ts b/src/client/pythonEnvironments/common/commonUtils.ts index d8abedb8c89f..24d2b415cb9a 100644 --- a/src/client/pythonEnvironments/common/commonUtils.ts +++ b/src/client/pythonEnvironments/common/commonUtils.ts @@ -15,20 +15,17 @@ import { isFile, normCasePath } from './externalDependencies'; import * as posix from './posixUtils'; import * as windows from './windowsUtils'; -const matchPythonBinFilename = +const matchStandardPythonBinFilename = getOSType() === OSType.Windows ? windows.matchPythonBinFilename : posix.matchPythonBinFilename; type FileFilterFunc = (filename: string) => boolean; /** - * Returns `true` if path provided is likely a python executable. + * Returns `true` if path provided is likely a python executable than a folder path. */ export async function isPythonExecutable(filePath: string): Promise { - const isMatch = matchPythonBinFilename(filePath); - if (!isMatch) { - return false; - } - // On Windows it's fair to assume a path ending with `.exe` denotes a file. - if (getOSType() === OSType.Windows) { + const isMatch = matchStandardPythonBinFilename(filePath); + if (isMatch && getOSType() === OSType.Windows) { + // On Windows it's fair to assume a path ending with `.exe` denotes a file. return true; } // For other operating systems verify if it's a file. @@ -83,7 +80,7 @@ export async function* iterPythonExecutablesInDir( ): AsyncIterableIterator { const readDirOpts = { ...opts, - filterFile: matchPythonBinFilename, + filterFile: matchStandardPythonBinFilename, }; const entries = await readDirEntries(dirname, readDirOpts); for (const entry of entries) { @@ -270,7 +267,7 @@ async function checkPythonExecutable( filterFile?: (f: string | DirEntry) => Promise; }, ): Promise { - const matchFilename = opts.matchFilename || matchPythonBinFilename; + const matchFilename = opts.matchFilename || matchStandardPythonBinFilename; const filename = typeof executable === 'string' ? executable : executable.filename; if (!matchFilename(filename)) { diff --git a/src/client/pythonEnvironments/common/posixUtils.ts b/src/client/pythonEnvironments/common/posixUtils.ts index cba484ecfe48..cd8f62bf9a08 100644 --- a/src/client/pythonEnvironments/common/posixUtils.ts +++ b/src/client/pythonEnvironments/common/posixUtils.ts @@ -17,9 +17,9 @@ export function matchBasicPythonBinFilename(filename: string): boolean { } /** - * Checks if a given path ends with python*.exe + * Checks if a given path matches pattern for standard non-windows python binary. * @param {string} interpreterPath : Path to python interpreter. - * @returns {boolean} : Returns true if the path matches pattern for windows python executable. + * @returns {boolean} : Returns true if the path matches pattern for non-windows python binary. */ export function matchPythonBinFilename(filename: string): boolean { /** From 7326fc031ce23291f832b0235977b672d910de8a Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Mon, 4 Apr 2022 16:44:41 -0700 Subject: [PATCH 2/3] news --- news/2 Fixes/18835.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/2 Fixes/18835.md diff --git a/news/2 Fixes/18835.md b/news/2 Fixes/18835.md new file mode 100644 index 000000000000..881380ff7fa8 --- /dev/null +++ b/news/2 Fixes/18835.md @@ -0,0 +1 @@ +Fixes regression with support for python binaries not following the standard names. From d999d4141e20ff53a16ba6581b3f4c23ef0c323e Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Mon, 4 Apr 2022 16:47:09 -0700 Subject: [PATCH 3/3] Remove comment --- src/client/pythonEnvironments/common/commonUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client/pythonEnvironments/common/commonUtils.ts b/src/client/pythonEnvironments/common/commonUtils.ts index 24d2b415cb9a..85462531e5e3 100644 --- a/src/client/pythonEnvironments/common/commonUtils.ts +++ b/src/client/pythonEnvironments/common/commonUtils.ts @@ -28,7 +28,6 @@ export async function isPythonExecutable(filePath: string): Promise { // On Windows it's fair to assume a path ending with `.exe` denotes a file. return true; } - // For other operating systems verify if it's a file. if (await isFile(filePath)) { return true; }