From 226adb0c891865f88409d2e5a1274d51145b4c61 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Tue, 31 Oct 2023 10:31:26 +1100 Subject: [PATCH] Remove unused proposed API (#14621) * Remove API added for AzML * Remove unused import statement in jupyterSession.ts * Remove unnecessary test cases for Jupyter style names in session factory * Ignore test * misc --- src/api.proposed.mappedRemoteDirectory.d.ts | 34 -------- .../jupyterServerProviderRegistry.ts | 4 - src/kernels/jupyter/jupyterUtils.ts | 3 - .../jupyterKernelSessionFactory.unit.test.ts | 72 ---------------- src/kernels/jupyter/session/jupyterSession.ts | 45 +++++----- .../session/jupyterSession.unit.test.ts | 1 - src/kernels/types.ts | 5 -- ...ferredKernelConnectionService.unit.test.ts | 86 +++++++++---------- 8 files changed, 64 insertions(+), 186 deletions(-) delete mode 100644 src/api.proposed.mappedRemoteDirectory.d.ts diff --git a/src/api.proposed.mappedRemoteDirectory.d.ts b/src/api.proposed.mappedRemoteDirectory.d.ts deleted file mode 100644 index 3e20e3440ea..00000000000 --- a/src/api.proposed.mappedRemoteDirectory.d.ts +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -import type { Uri } from 'vscode'; - -declare module './api' { - /** - * Use of proposed API is not recommended. - * This could change anytime without any notice. - * Used only by synapse extension. - */ - export interface JupyterServer { - /** - * Note: Required for AzML, perhaps CodeSpaces and Pengs personal extension. - * - * The local directory that maps to the remote directory of the Jupyter Server. - * E.g. assume you start Jupyter Notebook on a remote machine with --notebook-dir=/foo/bar, - * and you have a file named /foo/bar/sample.ipynb, /foo/bar/sample2.ipynb and the like. - * Next assume you have local directory named /users/xyz/remoteServer with the files with the same names, sample.ipynb and sample2.ipynb - * - * - * Using this setting one can map the local directory to the remote directory. - * With the previous example in mind, the value of this property would be Uri.file('/users/xyz/remoteServer'). - * - * This results in Jupyter Session names being generated in a way thats is consistent with Jupyter Notebook/Lab. - * I.e. the session names map to the relative path of the notebook file. - * Taking the previous example into account, if one were to start a Remote Kernel for the local file `/users/xyz/remoteServer/sample2.ipynb`, - * then the name of the remote Jupyter Session would be `sample2.ipynb`. - * - * This is useful in the context where the remote Jupyter Server is running on the same machine as VS Code, but the files are mapped on different directories. - */ - readonly mappedRemoteDirectory?: Uri; - } -} diff --git a/src/kernels/jupyter/connection/jupyterServerProviderRegistry.ts b/src/kernels/jupyter/connection/jupyterServerProviderRegistry.ts index e7b25c2d5ba..817f090dcdd 100644 --- a/src/kernels/jupyter/connection/jupyterServerProviderRegistry.ts +++ b/src/kernels/jupyter/connection/jupyterServerProviderRegistry.ts @@ -240,8 +240,6 @@ class JupyterUriProviderAdaptor extends Disposables implements IJupyterUriProvid displayName: server.label, token: info.token || '', authorizationHeader: info.headers, - // eslint-disable-next-line local-rules/dont-use-fspath - mappedRemoteNotebookDir: server.mappedRemoteDirectory?.fsPath, webSocketProtocols: info.webSocketProtocols, fetch: info.fetch, WebSocket: info.WebSocket @@ -262,8 +260,6 @@ class JupyterUriProviderAdaptor extends Disposables implements IJupyterUriProvid displayName: server.label, token: info.token || '', authorizationHeader: info.headers, - // eslint-disable-next-line local-rules/dont-use-fspath - mappedRemoteNotebookDir: (result || server).mappedRemoteDirectory?.fsPath, webSocketProtocols: info.webSocketProtocols, fetch: info.fetch, WebSocket: info.WebSocket diff --git a/src/kernels/jupyter/jupyterUtils.ts b/src/kernels/jupyter/jupyterUtils.ts index 288e63c673b..b02e978ce34 100644 --- a/src/kernels/jupyter/jupyterUtils.ts +++ b/src/kernels/jupyter/jupyterUtils.ts @@ -170,9 +170,6 @@ export function createJupyterConnectionInfo( : getJupyterConnectionDisplayName(token, baseUrl), dispose: () => toDispose?.dispose(), rootDirectory, - // Temporarily support workingDirectory as a fallback for old extensions using that (to be removed in the next release). - // eslint-disable-next-line @typescript-eslint/no-explicit-any - mappedRemoteNotebookDir: serverUri?.mappedRemoteNotebookDir || (serverUri as any)?.workingDirectory, // For remote jupyter servers that are managed by us, we can provide the auth header. // Its crucial this is set to undefined, else password retrieval will not be attempted. getAuthHeader, diff --git a/src/kernels/jupyter/session/jupyterKernelSessionFactory.unit.test.ts b/src/kernels/jupyter/session/jupyterKernelSessionFactory.unit.test.ts index 34122f867bf..d00c6623ee5 100644 --- a/src/kernels/jupyter/session/jupyterKernelSessionFactory.unit.test.ts +++ b/src/kernels/jupyter/session/jupyterKernelSessionFactory.unit.test.ts @@ -154,7 +154,6 @@ suite('New Jupyter Kernel Session Factory', () => { when(connection.dispose()).thenReturn(); when(connection.getAuthHeader).thenReturn(); when(connection.getWebsocketProtocols).thenReturn(); - when(connection.mappedRemoteNotebookDir).thenReturn(); when(connection.providerId).thenReturn('_builtin.something'); when(connection.rootDirectory).thenReturn(Uri.file('someDir')); when(connection.token).thenReturn('1234'); @@ -438,43 +437,7 @@ suite('New Jupyter Kernel Session Factory', () => { when(kernel.status).thenReturn('busy'); assert.strictEqual(wrapperSession.status, 'busy'); }); - test('Create Session with Jupyter style names (notebook)', async () => { - when(connection.mappedRemoteNotebookDir).thenReturn('/foo/bar'); - const resource = Uri.file('/foo/bar/baz/abc.ipynb'); - const options: KernelSessionCreationOptions = { - kernelConnection: remoteKernelSpec, - creator: 'jupyterExtension', - resource, - token: token.token, - ui - }; - const { session, kernel } = createSession(); - when(sessionManager.startNew(anything(), anything())).thenResolve(resolvableInstance(session)); - - const wrapperSession = await factory.create(options); - - assert.ok(wrapperSession); - - verify(kernelService.ensureKernelIsUsable(anything(), anything(), anything(), anything(), false)).never(); - verify(jupyterNotebookProvider.getOrStartServer(anything())).never(); - verify(workspaceService.computeWorkingDirectory(anything())).never(); - verify(sessionManager.startNew(anything(), anything())).once(); - verify(jupyterConnection.createConnectionInfo(anything())).once(); - assert.strictEqual(capture(sessionManager.startNew).first()[0].type, 'notebook'); - - when(kernel.status).thenReturn('idle'); - assert.strictEqual(wrapperSession.status, 'idle'); - when(kernel.status).thenReturn('busy'); - assert.strictEqual(wrapperSession.status, 'busy'); - - const newSessionOptions = capture(sessionManager.startNew).first()[0]; - assert.strictEqual(newSessionOptions.name, 'abc.ipynb'); - assert.strictEqual(newSessionOptions.path, 'baz/abc.ipynb'); - assert.strictEqual(newSessionOptions.type, 'notebook'); - assert.deepStrictEqual(newSessionOptions.kernel, { name: 'python3' }); - }); test('Create Session with non-Jupyter style names (notebook)', async () => { - when(connection.mappedRemoteNotebookDir).thenReturn(); const resource = Uri.file('/foo/bar/baz/abc.ipynb'); const options: KernelSessionCreationOptions = { kernelConnection: remoteKernelSpec, @@ -523,39 +486,4 @@ suite('New Jupyter Kernel Session Factory', () => { assert.strictEqual(newSessionOptions.type, 'notebook'); assert.deepStrictEqual(newSessionOptions.kernel, { name: 'python3' }); }); - test('Create Session with Jupyter style names (interactive window with Python file)', async () => { - when(connection.mappedRemoteNotebookDir).thenReturn('/foo/bar'); - const resource = Uri.file('/foo/bar/baz/abc.py'); - const options: KernelSessionCreationOptions = { - kernelConnection: remoteKernelSpec, - creator: 'jupyterExtension', - resource, - token: token.token, - ui - }; - const { session, kernel } = createSession(); - when(sessionManager.startNew(anything(), anything())).thenResolve(resolvableInstance(session)); - - const wrapperSession = await factory.create(options); - - assert.ok(wrapperSession); - - verify(kernelService.ensureKernelIsUsable(anything(), anything(), anything(), anything(), false)).never(); - verify(jupyterNotebookProvider.getOrStartServer(anything())).never(); - verify(workspaceService.computeWorkingDirectory(anything())).never(); - verify(sessionManager.startNew(anything(), anything())).once(); - verify(jupyterConnection.createConnectionInfo(anything())).once(); - assert.strictEqual(capture(sessionManager.startNew).first()[0].type, 'console'); - - when(kernel.status).thenReturn('idle'); - assert.strictEqual(wrapperSession.status, 'idle'); - when(kernel.status).thenReturn('busy'); - assert.strictEqual(wrapperSession.status, 'busy'); - - const newSessionOptions = capture(sessionManager.startNew).first()[0]; - assert.strictEqual(newSessionOptions.name, 'abc.py'); - assert.strictEqual(newSessionOptions.path, 'baz/abc.py'); - assert.strictEqual(newSessionOptions.type, 'console'); - assert.deepStrictEqual(newSessionOptions.kernel, { name: 'python3' }); - }); }); diff --git a/src/kernels/jupyter/session/jupyterSession.ts b/src/kernels/jupyter/session/jupyterSession.ts index 01168c1f62c..6d0feaf7b96 100644 --- a/src/kernels/jupyter/session/jupyterSession.ts +++ b/src/kernels/jupyter/session/jupyterSession.ts @@ -18,7 +18,6 @@ import { import { DisplayOptions } from '../../displayOptions'; import { IJupyterKernelService } from '../types'; import { noop } from '../../../platform/common/utils/misc'; -import * as path from '../../../platform/vscode-path/resources'; import { getResourceType } from '../../../platform/common/utils'; import { waitForIdleOnSession } from '../../common/helpers'; import { BaseJupyterSessionConnection } from '../../common/baseJupyterSessionConnection'; @@ -196,27 +195,27 @@ export class JupyterSessionWrapper } export function getRemoteSessionOptions( - remoteConnection: IJupyterConnection, - resource?: Uri + _remoteConnection: IJupyterConnection, + _resource?: Uri ): Pick | undefined | void { - if (!resource || resource.scheme === 'untitled' || !remoteConnection.mappedRemoteNotebookDir) { - return; - } - // Get Uris of both, local and remote files. - // Convert Uris to strings to Uri again, as its possible the Uris are not always compatible. - // E.g. one could be dealing with custom file system providers. - const filePath = Uri.file(resource.path); - const mappedLocalPath = Uri.file(remoteConnection.mappedRemoteNotebookDir); - if (!path.isEqualOrParent(filePath, mappedLocalPath)) { - return; - } - const sessionPath = path.relativePath(mappedLocalPath, filePath); - // If we have mapped the local dir to the remote dir, then we need to use the name of the file. - const sessionName = path.basename(resource); - if (sessionName && sessionPath) { - return { - path: sessionPath, - name: sessionName - }; - } + // if (!resource || resource.scheme === 'untitled' || !remoteConnection.mappedRemoteNotebookDir) { + // return; + // } + // // Get Uris of both, local and remote files. + // // Convert Uris to strings to Uri again, as its possible the Uris are not always compatible. + // // E.g. one could be dealing with custom file system providers. + // const filePath = Uri.file(resource.path); + // const mappedLocalPath = Uri.file(remoteConnection.mappedRemoteNotebookDir); + // if (!path.isEqualOrParent(filePath, mappedLocalPath)) { + // return; + // } + // const sessionPath = path.relativePath(mappedLocalPath, filePath); + // // If we have mapped the local dir to the remote dir, then we need to use the name of the file. + // const sessionName = path.basename(resource); + // if (sessionName && sessionPath) { + // return { + // path: sessionPath, + // name: sessionName + // }; + // } } diff --git a/src/kernels/jupyter/session/jupyterSession.unit.test.ts b/src/kernels/jupyter/session/jupyterSession.unit.test.ts index 74b9cc236ee..6eb299d74a4 100644 --- a/src/kernels/jupyter/session/jupyterSession.unit.test.ts +++ b/src/kernels/jupyter/session/jupyterSession.unit.test.ts @@ -45,7 +45,6 @@ suite('JupyterSession', () => { let kernelService: JupyterKernelService; function createJupyterSession(resource: Resource = undefined, kernelConnectionMetadata: KernelConnectionMetadata) { connection = mock(); - when(connection.mappedRemoteNotebookDir).thenReturn(undefined); token = new CancellationTokenSource(); disposables.push(token); diff --git a/src/kernels/types.ts b/src/kernels/types.ts index 7a39ced8263..e8c5e0bdb03 100644 --- a/src/kernels/types.ts +++ b/src/kernels/types.ts @@ -558,11 +558,6 @@ export interface IJupyterConnection extends Disposable { * Returns the sub-protocols to be used. See details of `protocols` here https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket */ getWebsocketProtocols?(): string[]; - /** - * Maps to IJupyterServerUri.mappedRemoteNotebookDir - * @see IJupyterServerUri - */ - readonly mappedRemoteNotebookDir?: string; } export enum InterruptResult { diff --git a/src/notebooks/controllers/preferredKernelConnectionService.unit.test.ts b/src/notebooks/controllers/preferredKernelConnectionService.unit.test.ts index b121d485774..91df1572748 100644 --- a/src/notebooks/controllers/preferredKernelConnectionService.unit.test.ts +++ b/src/notebooks/controllers/preferredKernelConnectionService.unit.test.ts @@ -4,7 +4,7 @@ import { assert } from 'chai'; import * as sinon from 'sinon'; import { anything, instance, mock, when } from 'ts-mockito'; -import { CancellationTokenSource, NotebookDocument, Disposable, EventEmitter, Uri } from 'vscode'; +import { CancellationTokenSource, NotebookDocument, Disposable, EventEmitter } from 'vscode'; import { ContributedKernelFinderKind, IContributedKernelFinder } from '../../kernels/internalTypes'; import { PreferredRemoteKernelIdProvider } from '../../kernels/jupyter/connection/preferredRemoteKernelIdProvider'; import { @@ -71,26 +71,26 @@ suite('Preferred Kernel Connection', () => { kernelModel: instance(mock()), serverProviderHandle: serverProviderHandle2 }); - const remoteLiveJavaKernelConnection = LiveRemoteKernelConnectionMetadata.create({ - baseUrl: '', - id: 'liveRemoteJava', - kernelModel: { - lastActivityTime: new Date(), - model: { - id: 'xyz', - kernel: { - name: 'java', - id: 'xyz' - }, - path: 'baz/sample.ipynb', - name: 'sample.ipynb', - type: 'notebook' - }, - name: 'java', - numberOfConnections: 1 - }, - serverProviderHandle: serverProviderHandle2 - }); + // const remoteLiveJavaKernelConnection = LiveRemoteKernelConnectionMetadata.create({ + // baseUrl: '', + // id: 'liveRemoteJava', + // kernelModel: { + // lastActivityTime: new Date(), + // model: { + // id: 'xyz', + // kernel: { + // name: 'java', + // id: 'xyz' + // }, + // path: 'baz/sample.ipynb', + // name: 'sample.ipynb', + // type: 'notebook' + // }, + // name: 'java', + // numberOfConnections: 1 + // }, + // serverProviderHandle: serverProviderHandle2 + // }); const remoteJavaKernelSpec = RemoteKernelSpecConnectionMetadata.create({ baseUrl: '', id: 'remoteJavaKernelSpec', @@ -178,7 +178,6 @@ suite('Preferred Kernel Connection', () => { instance(localPythonEnvFinder) ]); (instance(connection) as any).then = undefined; - when(connection.mappedRemoteNotebookDir).thenReturn(undefined); when(jupyterConnection.createConnectionInfo(anything())).thenResolve(instance(connection)); preferredService = new PreferredKernelConnectionService(instance(jupyterConnection)); disposables.push(preferredService); @@ -217,31 +216,30 @@ suite('Preferred Kernel Connection', () => { assert.strictEqual(preferredKernel, remoteJavaKernelSpec); }); - test('Find existing session if there is an exact match for the notebook', async () => { - when(connection.mappedRemoteNotebookDir).thenReturn('/foo/bar/'); - notebook = new TestNotebookDocument(Uri.file('/foo/bar/baz/sample.ipynb'), 'jupyter-notebook', { - custom: { metadata: notebookMetadata } - }); + // test('Find existing session if there is an exact match for the notebook', async () => { + // notebook = new TestNotebookDocument(Uri.file('/foo/bar/baz/sample.ipynb'), 'jupyter-notebook', { + // custom: { metadata: notebookMetadata } + // }); - when(preferredRemoteKernelProvider.getPreferredRemoteKernelId(uriEquals(notebook.uri))).thenResolve( - undefined - ); - when(remoteKernelFinder.status).thenReturn('idle'); - when(remoteKernelFinder.kernels).thenReturn([ - remoteLiveKernelConnection1, - remoteLiveJavaKernelConnection, - remoteJavaKernelSpec - ]); - notebookMetadata.language_info!.name = remoteJavaKernelSpec.kernelSpec.language!; + // when(preferredRemoteKernelProvider.getPreferredRemoteKernelId(uriEquals(notebook.uri))).thenResolve( + // undefined + // ); + // when(remoteKernelFinder.status).thenReturn('idle'); + // when(remoteKernelFinder.kernels).thenReturn([ + // remoteLiveKernelConnection1, + // remoteLiveJavaKernelConnection, + // remoteJavaKernelSpec + // ]); + // notebookMetadata.language_info!.name = remoteJavaKernelSpec.kernelSpec.language!; - const preferredKernel = await preferredService.findPreferredRemoteKernelConnection( - notebook, - instance(remoteKernelFinder), - cancellation.token - ); + // const preferredKernel = await preferredService.findPreferredRemoteKernelConnection( + // notebook, + // instance(remoteKernelFinder), + // cancellation.token + // ); - assert.strictEqual(preferredKernel, remoteLiveJavaKernelConnection); - }); + // assert.strictEqual(preferredKernel, remoteLiveJavaKernelConnection); + // }); }); suite('Local Kernel Specs (preferred match)', () => { test('No match for notebook when there are no kernels', async () => {