Skip to content

Commit 8daf5f7

Browse files
Fix local nbextensions path resolution for kernels launched from local kernelspec (#16886)
* Initial plan * Fix: Add support for startUsingLocalKernelSpec in NbExtensionsPathProvider Co-authored-by: DonJayamanne <[email protected]> * Fix formatting: Remove trailing whitespace from comment Co-authored-by: DonJayamanne <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: DonJayamanne <[email protected]>
1 parent 620a8ba commit 8daf5f7

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/notebooks/controllers/ipywidgets/scriptSourceProvider/nbExtensionsPathProvider.node.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ export class NbExtensionsPathProvider implements INbExtensionsPathProvider {
2525
}
2626
return Uri.joinPath(Uri.file(sysPrefix), 'share', 'jupyter');
2727
}
28+
case 'startUsingLocalKernelSpec': {
29+
// If the local kernelspec has an associated Python interpreter,
30+
// use the same logic as startUsingPythonInterpreter
31+
if (kernel.kernelConnectionMetadata.interpreter) {
32+
const sysPrefix = await getSysPrefix(kernel.kernelConnectionMetadata.interpreter);
33+
if (!sysPrefix) {
34+
return;
35+
}
36+
return Uri.joinPath(Uri.file(sysPrefix), 'share', 'jupyter');
37+
}
38+
// If no interpreter, we haven't come across scenarios with non-python kernels that use widgets
39+
// & have custom widget sources. If we do, we can implement that as we come across them.
40+
return;
41+
}
2842
default: {
2943
// We haven't come across scenarios with non-python kernels that use widgets
3044
// & have custom widget sources. If we do, we can implement that as we come across them.

src/notebooks/controllers/ipywidgets/scriptSourceProvider/nbExtensionsPathProvider.unit.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ import { dispose } from '../../../../platform/common/utils/lifecycle';
3636
id: 'interpreterId'
3737
} as any
3838
});
39+
const localKernelSpecWithPythonInterpreter = LocalKernelSpecConnectionMetadata.create({
40+
id: 'localKernelSpecWithPythonInterpreter',
41+
kernelSpec: mock<IJupyterKernelSpec>(),
42+
interpreter: {
43+
id: 'interpreterId'
44+
} as any
45+
});
3946
const serverProviderHandle = { handle: 'handle', id: 'id', extensionId: '' };
4047
const remoteKernelSpec = RemoteKernelSpecConnectionMetadata.create({
4148
id: '',
@@ -82,6 +89,15 @@ import { dispose } from '../../../../platform/common/utils/lifecycle';
8289
assert.strictEqual(baseUrl?.toString(), Uri.file(path.join(__dirname, 'share', 'jupyter')).toString());
8390
}
8491
});
92+
test('Returns base url for local kernelspec with python interpreter', async () => {
93+
when(kernel.kernelConnectionMetadata).thenReturn(localKernelSpecWithPythonInterpreter);
94+
const baseUrl = await provider.getNbExtensionsParentPath(instance(kernel));
95+
if (isWeb) {
96+
assert.isUndefined(baseUrl);
97+
} else {
98+
assert.strictEqual(baseUrl?.toString(), Uri.file(path.join(__dirname, 'share', 'jupyter')).toString());
99+
}
100+
});
85101
test('Returns base url for remote kernelspec', async () => {
86102
when(kernel.kernelConnectionMetadata).thenReturn(remoteKernelSpec);
87103
const baseUrl = await provider.getNbExtensionsParentPath(instance(kernel));

0 commit comments

Comments
 (0)