Skip to content

Fixes support for python binaries not following the standard names #18860

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

Merged
merged 3 commits into from
Apr 4, 2022
Merged
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
1 change: 1 addition & 0 deletions news/2 Fixes/18835.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes regression with support for python binaries not following the standard names.
18 changes: 7 additions & 11 deletions src/client/pythonEnvironments/common/commonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
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;
}
Expand Down Expand Up @@ -83,7 +79,7 @@ export async function* iterPythonExecutablesInDir(
): AsyncIterableIterator<DirEntry> {
const readDirOpts = {
...opts,
filterFile: matchPythonBinFilename,
filterFile: matchStandardPythonBinFilename,
};
const entries = await readDirEntries(dirname, readDirOpts);
for (const entry of entries) {
Expand Down Expand Up @@ -270,7 +266,7 @@ async function checkPythonExecutable(
filterFile?: (f: string | DirEntry) => Promise<boolean>;
},
): Promise<boolean> {
const matchFilename = opts.matchFilename || matchPythonBinFilename;
const matchFilename = opts.matchFilename || matchStandardPythonBinFilename;
const filename = typeof executable === 'string' ? executable : executable.filename;

if (!matchFilename(filename)) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/pythonEnvironments/common/posixUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down