Skip to content

Commit ca530a4

Browse files
author
Kartik Raj
authored
Fixes support for python binaries not following the standard names (#18860)
* Fixes support for python binaries not following the standard names * news * Remove comment
1 parent 0affe01 commit ca530a4

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

news/2 Fixes/18835.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes regression with support for python binaries not following the standard names.

src/client/pythonEnvironments/common/commonUtils.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,19 @@ import { isFile, normCasePath } from './externalDependencies';
1515
import * as posix from './posixUtils';
1616
import * as windows from './windowsUtils';
1717

18-
const matchPythonBinFilename =
18+
const matchStandardPythonBinFilename =
1919
getOSType() === OSType.Windows ? windows.matchPythonBinFilename : posix.matchPythonBinFilename;
2020
type FileFilterFunc = (filename: string) => boolean;
2121

2222
/**
23-
* Returns `true` if path provided is likely a python executable.
23+
* Returns `true` if path provided is likely a python executable than a folder path.
2424
*/
2525
export async function isPythonExecutable(filePath: string): Promise<boolean> {
26-
const isMatch = matchPythonBinFilename(filePath);
27-
if (!isMatch) {
28-
return false;
29-
}
30-
// On Windows it's fair to assume a path ending with `.exe` denotes a file.
31-
if (getOSType() === OSType.Windows) {
26+
const isMatch = matchStandardPythonBinFilename(filePath);
27+
if (isMatch && getOSType() === OSType.Windows) {
28+
// On Windows it's fair to assume a path ending with `.exe` denotes a file.
3229
return true;
3330
}
34-
// For other operating systems verify if it's a file.
3531
if (await isFile(filePath)) {
3632
return true;
3733
}
@@ -83,7 +79,7 @@ export async function* iterPythonExecutablesInDir(
8379
): AsyncIterableIterator<DirEntry> {
8480
const readDirOpts = {
8581
...opts,
86-
filterFile: matchPythonBinFilename,
82+
filterFile: matchStandardPythonBinFilename,
8783
};
8884
const entries = await readDirEntries(dirname, readDirOpts);
8985
for (const entry of entries) {
@@ -270,7 +266,7 @@ async function checkPythonExecutable(
270266
filterFile?: (f: string | DirEntry) => Promise<boolean>;
271267
},
272268
): Promise<boolean> {
273-
const matchFilename = opts.matchFilename || matchPythonBinFilename;
269+
const matchFilename = opts.matchFilename || matchStandardPythonBinFilename;
274270
const filename = typeof executable === 'string' ? executable : executable.filename;
275271

276272
if (!matchFilename(filename)) {

src/client/pythonEnvironments/common/posixUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export function matchBasicPythonBinFilename(filename: string): boolean {
1717
}
1818

1919
/**
20-
* Checks if a given path ends with python*.exe
20+
* Checks if a given path matches pattern for standard non-windows python binary.
2121
* @param {string} interpreterPath : Path to python interpreter.
22-
* @returns {boolean} : Returns true if the path matches pattern for windows python executable.
22+
* @returns {boolean} : Returns true if the path matches pattern for non-windows python binary.
2323
*/
2424
export function matchPythonBinFilename(filename: string): boolean {
2525
/**

0 commit comments

Comments
 (0)