Skip to content

Use full path in argv to find interpreter matching a kernel #11478

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 1 commit into from
Apr 28, 2020
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
29 changes: 27 additions & 2 deletions src/client/datascience/jupyter/kernels/kernelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export class KernelService {
* @returns {(Promise<PythonInterpreter | undefined>)}
* @memberof KernelService
*/
// tslint:disable-next-line: cyclomatic-complexity
public async findMatchingInterpreter(
kernelSpec: IJupyterKernelSpec | LiveKernelModel,
cancelToken?: CancellationToken
Expand Down Expand Up @@ -159,11 +160,35 @@ export class KernelService {
`KernelSpec has interpreter information, however a matching interepter could not be found for ${kernelSpec.metadata?.interpreter?.path}`
);
}

// 2. Check if we have a fully qualified path in `argv`
const pathInArgv =
Array.isArray(kernelSpec.argv) && kernelSpec.argv.length > 0 ? kernelSpec.argv[0] : undefined;
if (pathInArgv && path.basename(pathInArgv) !== pathInArgv) {
const interpreter = await this.interpreterService.getInterpreterDetails(pathInArgv).catch((ex) => {
traceError(
`Failed to get interpreter information for python defined in kernel ${kernelSpec.name}, ${
kernelSpec.display_name
} with argv: ${(kernelSpec.argv || [])?.join(',')}`,
ex
);
return;
});
if (interpreter) {
traceInfo(
`Found matching interpreter based on metadata, for the kernel ${kernelSpec.name}, ${kernelSpec.display_name}`
);
return interpreter;
}
traceError(
`KernelSpec has interpreter information, however a matching interepter could not be found for ${kernelSpec.metadata?.interpreter?.path}`
);
}
if (Cancellation.isCanceled(cancelToken)) {
return;
}

// 2. Check if current interpreter has the same display name
// 3. Check if current interpreter has the same display name
const activeInterpreter = await activeInterpreterPromise;
// If the display name matches the active interpreter then use that.
if (kernelSpec.display_name === activeInterpreter?.displayName) {
Expand Down Expand Up @@ -200,7 +225,7 @@ export class KernelService {
);
return activeInterpreter;
} else {
// 4. Look for interpreter with same display name across all interpreters.
// 5. Look for interpreter with same display name across all interpreters.

// If the display name matches the active interpreter then use that.
// Look in all of our interpreters if we have somethign that matches this.
Expand Down