Skip to content

Fix local nbextensions path resolution for kernels launched from local kernelspecs #16876

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

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ export class NbExtensionsPathProvider implements INbExtensionsPathProvider {
}
return Uri.joinPath(Uri.file(sysPrefix), 'share', 'jupyter');
}
case 'startUsingLocalKernelSpec': {
// If this local kernelspec has an associated Python interpreter, use its sysPrefix
if (kernel.kernelConnectionMetadata.interpreter) {
const sysPrefix = await getSysPrefix(kernel.kernelConnectionMetadata.interpreter);
if (!sysPrefix) {
return;
}
return Uri.joinPath(Uri.file(sysPrefix), 'share', 'jupyter');
}
// If no interpreter is associated, we can't determine the nbextensions path
return;
}
default: {
// We haven't come across scenarios with non-python kernels that use widgets
// & have custom widget sources. If we do, we can implement that as we come across them.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ import { dispose } from '../../../../platform/common/utils/lifecycle';
id: 'interpreterId'
} as any
});
const localKernelSpecWithInterpreter = LocalKernelSpecConnectionMetadata.create({
id: 'localKernelSpecWithInterpreter',
kernelSpec: mock<IJupyterKernelSpec>(),
interpreter: {
id: 'interpreterIdForKernelSpec'
} as any
});
const localKernelSpecWithoutInterpreter = LocalKernelSpecConnectionMetadata.create({
id: 'localKernelSpecWithoutInterpreter',
kernelSpec: mock<IJupyterKernelSpec>()
});
const serverProviderHandle = { handle: 'handle', id: 'id', extensionId: '' };
const remoteKernelSpec = RemoteKernelSpecConnectionMetadata.create({
id: '',
Expand Down Expand Up @@ -64,6 +75,9 @@ import { dispose } from '../../../../platform/common/utils/lifecycle';
when(environments.resolveEnvironment(localPythonKernelSpec.interpreter.id)).thenResolve({
executable: { sysPrefix: __dirname }
} as any);
when(environments.resolveEnvironment(localKernelSpecWithInterpreter.interpreter!.id)).thenResolve({
executable: { sysPrefix: __dirname }
} as any);
});
teardown(() => {
disposables = dispose(disposables);
Expand Down Expand Up @@ -92,5 +106,19 @@ import { dispose } from '../../../../platform/common/utils/lifecycle';
const baseUrl = await provider.getNbExtensionsParentPath(instance(kernel));
assert.strictEqual(baseUrl?.toString(), Uri.parse(remoteLiveKernel.baseUrl).toString());
});
test('Returns base url for local kernelspec with interpreter', async () => {
when(kernel.kernelConnectionMetadata).thenReturn(localKernelSpecWithInterpreter);
const baseUrl = await provider.getNbExtensionsParentPath(instance(kernel));
if (isWeb) {
assert.isUndefined(baseUrl);
} else {
assert.strictEqual(baseUrl?.toString(), Uri.file(path.join(__dirname, 'share', 'jupyter')).toString());
}
});
test('Returns undefined for local kernelspec without interpreter', async () => {
when(kernel.kernelConnectionMetadata).thenReturn(localKernelSpecWithoutInterpreter);
const baseUrl = await provider.getNbExtensionsParentPath(instance(kernel));
assert.isUndefined(baseUrl);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ export class NbExtensionsPathProvider implements INbExtensionsPathProvider {
case 'startUsingRemoteKernelSpec': {
return Uri.parse(kernel.kernelConnectionMetadata.baseUrl);
}
case 'startUsingPythonInterpreter':
case 'startUsingLocalKernelSpec':
default: {
// Not possible a possible code path in web.
// In web environment, only remote kernels are supported.
return;
}
}
Expand Down
Loading