Skip to content

Commit 2682113

Browse files
committed
refactor: Update kernel selection logic and environment management
- Changed return type of `ensureKernelSelected` method to Promise<boolean> for better handling of kernel selection status. - Refactored imports in `deepnoteEnvironmentManager.node.ts` to remove unused dependencies and improve clarity. - Updated environment selection logic in `deepnoteKernelAutoSelector` to include user prompts for environment creation. - Removed deprecated UI handling code from `deepnoteEnvironmentUi.ts`. - Cleaned up test files by removing unnecessary tests and assertions related to server management. This commit enhances the overall structure and functionality of the Deepnote kernel management system. Signed-off-by: Tomas Kislan <[email protected]>
1 parent bee8e79 commit 2682113

File tree

8 files changed

+102
-560
lines changed

8 files changed

+102
-560
lines changed

src/kernels/deepnote/environments/deepnoteEnvironmentManager.node.ts

Lines changed: 3 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
import { injectable, inject, named, optional } from 'inversify';
1+
import { injectable, inject, named } from 'inversify';
22
import { EventEmitter, Uri, CancellationToken, l10n } from 'vscode';
33
import { generateUuid as uuid } from '../../../platform/common/uuid';
4-
import { IConfigurationService, IExtensionContext, IOutputChannel } from '../../../platform/common/types';
4+
import { IExtensionContext, IOutputChannel } from '../../../platform/common/types';
55
import { IExtensionSyncActivationService } from '../../../platform/activation/types';
66
import { logger } from '../../../platform/logging';
77
import { DeepnoteEnvironmentStorage } from './deepnoteEnvironmentStorage.node';
88
import { CreateDeepnoteEnvironmentOptions, DeepnoteEnvironment } from './deepnoteEnvironment';
9-
import {
10-
IDeepnoteEnvironmentManager,
11-
IDeepnoteServerProvider,
12-
IDeepnoteServerStarter,
13-
IDeepnoteToolkitInstaller
14-
} from '../types';
9+
import { IDeepnoteEnvironmentManager, IDeepnoteServerStarter } from '../types';
1510
import { Cancellation } from '../../../platform/common/cancellation';
1611
import { STANDARD_OUTPUT_CHANNEL } from '../../../platform/common/constants';
17-
import { IJupyterRequestAgentCreator, IJupyterRequestCreator } from '../../jupyter/types';
1812

1913
/**
2014
* Manager for Deepnote kernel environments.
@@ -27,23 +21,14 @@ export class DeepnoteEnvironmentManager implements IExtensionSyncActivationServi
2721

2822
private environments: Map<string, DeepnoteEnvironment> = new Map();
2923
private environmentServers: Map<string, Uri[]> = new Map();
30-
// private serversByFile: Map<string, DeepnoteServerInfo> = new Map();
31-
private tmpStartingServers: Map<string, boolean> = new Map();
3224
private readonly _onDidChangeEnvironments = new EventEmitter<void>();
3325
public readonly onDidChangeEnvironments = this._onDidChangeEnvironments.event;
3426
private initializationPromise: Promise<void> | undefined;
3527

3628
constructor(
3729
@inject(IExtensionContext) private readonly context: IExtensionContext,
3830
@inject(DeepnoteEnvironmentStorage) private readonly storage: DeepnoteEnvironmentStorage,
39-
@inject(IDeepnoteToolkitInstaller) private readonly toolkitInstaller: IDeepnoteToolkitInstaller,
4031
@inject(IDeepnoteServerStarter) private readonly serverStarter: IDeepnoteServerStarter,
41-
@inject(IDeepnoteServerProvider) private readonly serverProvider: IDeepnoteServerProvider,
42-
@inject(IJupyterRequestCreator) private readonly requestCreator: IJupyterRequestCreator,
43-
@inject(IJupyterRequestAgentCreator)
44-
@optional()
45-
private readonly requestAgentCreator: IJupyterRequestAgentCreator | undefined,
46-
@inject(IConfigurationService) private readonly configService: IConfigurationService,
4732
@inject(IOutputChannel) @named(STANDARD_OUTPUT_CHANNEL) private readonly outputChannel: IOutputChannel
4833
) {}
4934

@@ -193,106 +178,6 @@ export class DeepnoteEnvironmentManager implements IExtensionSyncActivationServi
193178
logger.info(`Deleted environment: ${config.name} (${id})`);
194179
}
195180

196-
// /**
197-
// * Start the Jupyter server for an environment
198-
// */
199-
// // public async startServer(id: string, token?: CancellationToken): Promise<void> {
200-
// public async startServer(id: string, deepnoteFileUri: Uri, token?: CancellationToken): Promise<void> {
201-
// const config = this.environments.get(id);
202-
// if (!config) {
203-
// throw new Error(`Environment not found: ${id}`);
204-
// }
205-
206-
// this.tmpStartingServers.set(id, true);
207-
// this._onDidChangeEnvironments.fire();
208-
209-
// try {
210-
// logger.info(`Ensuring server is running for environment: ${config.name} (${id})`);
211-
212-
// // First ensure venv is created and toolkit is installed
213-
// const { pythonInterpreter, toolkitVersion } = await this.toolkitInstaller.ensureVenvAndToolkit(
214-
// config.pythonInterpreter,
215-
// config.venvPath,
216-
// token
217-
// );
218-
219-
// // Install additional packages if specified
220-
// if (config.packages && config.packages.length > 0) {
221-
// await this.toolkitInstaller.installAdditionalPackages(config.venvPath, config.packages, token);
222-
// }
223-
224-
// // Start the Jupyter server (serverStarter is idempotent - returns existing if running)
225-
// // IMPORTANT: Always call this to ensure we get the current server info
226-
// // Don't return early based on config.serverInfo - it may be stale!
227-
// const serverInfo = await this.serverStarter.startServer(
228-
// pythonInterpreter,
229-
// config.venvPath,
230-
// id,
231-
// deepnoteFileUri,
232-
// token
233-
// );
234-
235-
// config.pythonInterpreter = pythonInterpreter;
236-
// config.toolkitVersion = toolkitVersion;
237-
// config.serverInfo = serverInfo;
238-
// config.lastUsedAt = new Date();
239-
240-
// await this.persistEnvironments();
241-
// this._onDidChangeEnvironments.fire();
242-
243-
// logger.info(`Server running for environment: ${config.name} (${id}) at ${serverInfo.url}`);
244-
// } catch (error) {
245-
// logger.error(`Failed to start server for environment: ${config.name} (${id})`, error);
246-
// throw error;
247-
// } finally {
248-
// this.tmpStartingServers.delete(id);
249-
// }
250-
// }
251-
252-
// /**
253-
// * Stop the Jupyter server for an environment
254-
// */
255-
// // public async stopServer(id: string, token?: CancellationToken): Promise<void> {
256-
// public async stopServer(deepnoteFileUri: Uri, token?: CancellationToken): Promise<void> {
257-
// // const config = this.environments.get(id);
258-
// // if (!config) {
259-
// // throw new Error(`Environment not found: ${id}`);
260-
// // }
261-
262-
// // if (!config.serverInfo) {
263-
// // logger.info(`No server running for environment: ${config.name} (${id})`);
264-
// // return;
265-
// // }
266-
267-
// try {
268-
// logger.info(`Stopping server for environment: ${deepnoteFileUri.fsPath}`);
269-
270-
// await this.serverStarter.stopServer(deepnoteFileUri, token);
271-
272-
// // config.serverInfo = undefined;
273-
274-
// // await this.persistEnvironments();
275-
// // this._onDidChangeEnvironments.fire();
276-
277-
// logger.info(`Server stopped successfully for environment: ${deepnoteFileUri.fsPath}`);
278-
// } catch (error) {
279-
// logger.error(`Failed to stop server for environment: ${deepnoteFileUri.fsPath}`, error);
280-
// throw error;
281-
// }
282-
// }
283-
284-
// /**
285-
// * Restart the Jupyter server for an environment
286-
// */
287-
// // public async restartServer(id: string, token?: CancellationToken): Promise<void> {
288-
// public async restartServer(deepnoteFileUri: Uri, token?: CancellationToken): Promise<void> {
289-
// logger.info(`Restarting server for environment: ${deepnoteFileUri.fsPath}`);
290-
// await this.stopServer(deepnoteFileUri, token);
291-
// Cancellation.throwIfCanceled(token);
292-
// await this.startServer(deepnoteFileUri, token);
293-
// logger.info(`Server restarted successfully for environment: ${deepnoteFileUri.fsPath}`);
294-
// }
295-
296181
/**
297182
* Update the last used timestamp for an environment
298183
*/

0 commit comments

Comments
 (0)