Skip to content
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

Improve identification of pure Python Kernelspecs #14005

Merged
merged 1 commit into from
Aug 1, 2023
Merged
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
37 changes: 25 additions & 12 deletions src/kernels/raw/finder/interpreterKernelSpecFinderHelper.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,7 @@ export class GlobalPythonKernelSpecFinder implements IDisposable {

// We could be dealing with a powershell kernel where kernelspec looks like
// { "argv": ["python", "-m", "powershell_kernel", "-f", "{connection_file}" ], "display_name": "PowerShell", "language": "powershell" }
if (
!isCreatedByUs &&
pathInArgv &&
kernelSpec.specFile &&
(path.basename(pathInArgv).toLocaleLowerCase() === 'python' ||
path.basename(pathInArgv).toLocaleLowerCase() === 'python3' ||
path.basename(pathInArgv).toLocaleLowerCase() === 'python.exe' ||
path.basename(pathInArgv).toLocaleLowerCase() === 'python3.exe')
) {
if (!isCreatedByUs && pathInArgv && kernelSpec.specFile && isLikelyAPythonExecutable(pathInArgv)) {
sendTelemetryEvent(Telemetry.AmbiguousGlobalKernelSpec, undefined, {
kernelSpecHash,
kernelConnectionType,
Expand Down Expand Up @@ -480,7 +472,11 @@ export class GlobalPythonKernelSpecFinder implements IDisposable {
traceWarning(
`Kernel Spec for '${kernelSpec.display_name}' (${getDisplayPath(
kernelSpec.specFile
)}) hidden, as we cannot find a matching interpreter argv = '${kernelSpec.argv[0]}'`
)}) hidden, as we cannot find a matching interpreter argv = '${
kernelSpec.argv[0]
}'. To resolve this, please change '${
kernelSpec.argv[0]
}' to point to the fully qualified Python executable.`
);
}
private async listKernelSpecsImpl() {
Expand Down Expand Up @@ -555,8 +551,15 @@ export class GlobalPythonKernelSpecFinder implements IDisposable {
'startUsingLocalKernelSpec'
);
if (!matchingInterpreter) {
this.warnAboutPythonKernelSpecWithInvalidPythonExec(item.kernelSpec);
return;
// If we cannot find a matching interpreter, then we cannot start this kernelspec.
// However users can have kernelspecs that have `/bin/bash` as the first argument in argv.
// These are situations where users are in full control of the kernel, hence we can ignore these.
// Thus we should not warn about these.
const executable = item.kernelSpec.argv.length ? item.kernelSpec.argv[0].toLowerCase() : '';
if (isLikelyAPythonExecutable(executable)) {
this.warnAboutPythonKernelSpecWithInvalidPythonExec(item.kernelSpec);
return;
}
}
const kernelSpec = LocalKernelSpecConnectionMetadata.create({
kernelSpec: item.kernelSpec,
Expand Down Expand Up @@ -739,3 +742,13 @@ export class GlobalPythonKernelSpecFinder implements IDisposable {
return Array.from(distinctKernelMetadata.values());
}
}

function isLikelyAPythonExecutable(executable: string) {
executable = path.basename(executable).trim().toLowerCase();
return (
executable === 'python' ||
executable === 'python3' ||
executable === 'python.exe' ||
executable === 'python3.exe'
);
}