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. diff --git a/src/client/pythonEnvironments/common/commonUtils.ts b/src/client/pythonEnvironments/common/commonUtils.ts index d8abedb8c89f..85462531e5e3 100644 --- a/src/client/pythonEnvironments/common/commonUtils.ts +++ b/src/client/pythonEnvironments/common/commonUtils.ts @@ -15,23 +15,19 @@ 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. if (await isFile(filePath)) { return true; } @@ -83,7 +79,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 +266,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 { /**