Skip to content

Commit 223fd77

Browse files
authored
Use full path in argv to find interpreter matching a kernel (#11478)
1 parent 29e9695 commit 223fd77

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/client/datascience/jupyter/kernels/kernelService.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export class KernelService {
128128
* @returns {(Promise<PythonInterpreter | undefined>)}
129129
* @memberof KernelService
130130
*/
131+
// tslint:disable-next-line: cyclomatic-complexity
131132
public async findMatchingInterpreter(
132133
kernelSpec: IJupyterKernelSpec | LiveKernelModel,
133134
cancelToken?: CancellationToken
@@ -159,11 +160,35 @@ export class KernelService {
159160
`KernelSpec has interpreter information, however a matching interepter could not be found for ${kernelSpec.metadata?.interpreter?.path}`
160161
);
161162
}
163+
164+
// 2. Check if we have a fully qualified path in `argv`
165+
const pathInArgv =
166+
Array.isArray(kernelSpec.argv) && kernelSpec.argv.length > 0 ? kernelSpec.argv[0] : undefined;
167+
if (pathInArgv && path.basename(pathInArgv) !== pathInArgv) {
168+
const interpreter = await this.interpreterService.getInterpreterDetails(pathInArgv).catch((ex) => {
169+
traceError(
170+
`Failed to get interpreter information for python defined in kernel ${kernelSpec.name}, ${
171+
kernelSpec.display_name
172+
} with argv: ${(kernelSpec.argv || [])?.join(',')}`,
173+
ex
174+
);
175+
return;
176+
});
177+
if (interpreter) {
178+
traceInfo(
179+
`Found matching interpreter based on metadata, for the kernel ${kernelSpec.name}, ${kernelSpec.display_name}`
180+
);
181+
return interpreter;
182+
}
183+
traceError(
184+
`KernelSpec has interpreter information, however a matching interepter could not be found for ${kernelSpec.metadata?.interpreter?.path}`
185+
);
186+
}
162187
if (Cancellation.isCanceled(cancelToken)) {
163188
return;
164189
}
165190

166-
// 2. Check if current interpreter has the same display name
191+
// 3. Check if current interpreter has the same display name
167192
const activeInterpreter = await activeInterpreterPromise;
168193
// If the display name matches the active interpreter then use that.
169194
if (kernelSpec.display_name === activeInterpreter?.displayName) {
@@ -200,7 +225,7 @@ export class KernelService {
200225
);
201226
return activeInterpreter;
202227
} else {
203-
// 4. Look for interpreter with same display name across all interpreters.
228+
// 5. Look for interpreter with same display name across all interpreters.
204229

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

0 commit comments

Comments
 (0)