From a34a72795b9767eb986092347714defaea4792a5 Mon Sep 17 00:00:00 2001 From: Chris LaFreniere <40371649+chlafreniere@users.noreply.github.com> Date: Fri, 14 Aug 2020 14:08:56 -0700 Subject: [PATCH] Notebook Code Cleanup + Utils Test (#11754) * Cleanup + Utils Test * Removing unnecessary util method --- extensions/notebook/src/book/githubRemoteBook.ts | 3 +-- .../notebook/src/book/remoteBookController.ts | 4 ++-- extensions/notebook/src/common/constants.ts | 1 + extensions/notebook/src/common/utils.ts | 13 ------------- extensions/notebook/src/extension.ts | 7 ------- .../notebook/src/jupyter/jupyterController.ts | 13 +------------ .../src/jupyter/jupyterServerInstallation.ts | 8 ++++---- extensions/notebook/src/test/common/utils.test.ts | 4 ---- 8 files changed, 9 insertions(+), 44 deletions(-) diff --git a/extensions/notebook/src/book/githubRemoteBook.ts b/extensions/notebook/src/book/githubRemoteBook.ts index 36cce3d6a7..9cb7b8725a 100644 --- a/extensions/notebook/src/book/githubRemoteBook.ts +++ b/extensions/notebook/src/book/githubRemoteBook.ts @@ -9,7 +9,6 @@ import * as vscode from 'vscode'; import * as path from 'path'; import * as zip from 'adm-zip'; import * as tar from 'tar'; -import * as utils from '../common/utils'; import { RemoteBook } from './remoteBook'; import { IAsset } from './remoteBookController'; import * as constants from '../common/constants'; @@ -76,7 +75,7 @@ export class GitHubRemoteBook extends RemoteBook { } public async extractFiles(remoteBookFullPath: vscode.Uri): Promise { try { - if (utils.getOSPlatform() === utils.Platform.Windows || utils.getOSPlatform() === utils.Platform.Mac) { + if (process.platform === constants.winPlatform || process.platform === constants.macPlatform) { let zippedFile = new zip(remoteBookFullPath.fsPath); zippedFile.extractAllTo(this._localPath.fsPath); } else { diff --git a/extensions/notebook/src/book/remoteBookController.ts b/extensions/notebook/src/book/remoteBookController.ts index bc2c427a26..dda8071320 100644 --- a/extensions/notebook/src/book/remoteBookController.ts +++ b/extensions/notebook/src/book/remoteBookController.ts @@ -5,11 +5,11 @@ import * as request from 'request'; import * as loc from '../common/localizedConstants'; -import * as utils from '../common/utils'; import * as vscode from 'vscode'; import { RemoteBookDialogModel } from '../dialog/remoteBookDialogModel'; import { GitHubRemoteBook } from '../book/githubRemoteBook'; import { SharedRemoteBook } from '../book/sharedRemoteBook'; +import { winPlatform, macPlatform } from '../common/constants'; const assetNameRE = /([a-zA-Z0-9]+)(?:-|_)([a-zA-Z0-9.]+)(?:-|_)([a-zA-Z0-9]+).(zip|tar.gz|tgz)/; @@ -73,7 +73,7 @@ export class RemoteBookController { public async getAssets(release?: IRelease): Promise { if (release) { let format: string[] = []; - if (utils.getOSPlatform() === utils.Platform.Windows || utils.getOSPlatform() === utils.Platform.Mac) { + if (process.platform === winPlatform || process.platform === macPlatform) { format = ['zip']; } else { format = ['tar.gz', 'tgz']; diff --git a/extensions/notebook/src/common/constants.ts b/extensions/notebook/src/common/constants.ts index f5c725b5a8..16d4114587 100644 --- a/extensions/notebook/src/common/constants.ts +++ b/extensions/notebook/src/common/constants.ts @@ -22,6 +22,7 @@ export const remoteBookDownloadTimeout = 'remoteBookDownloadTimeout'; export const collapseBookItems = 'collapseBookItems'; export const winPlatform = 'win32'; +export const macPlatform = 'darwin'; export const jupyterNotebookProviderId = 'jupyter'; export const jupyterConfigRootFolder = 'jupyter_config'; diff --git a/extensions/notebook/src/common/utils.ts b/extensions/notebook/src/common/utils.ts index 7c2353b283..d6b9828a7c 100644 --- a/extensions/notebook/src/common/utils.ts +++ b/extensions/notebook/src/common/utils.ts @@ -121,19 +121,6 @@ export interface IEndpoint { protocol: string; } -export function getOSPlatform(): Platform { - switch (process.platform) { - case 'win32': - return Platform.Windows; - case 'darwin': - return Platform.Mac; - case 'linux': - return Platform.Linux; - default: - return Platform.Others; - } -} - export function getOSPlatformId(): string { let platformId = undefined; switch (process.platform) { diff --git a/extensions/notebook/src/extension.ts b/extensions/notebook/src/extension.ts index ee185daaad..036d765f76 100644 --- a/extensions/notebook/src/extension.ts +++ b/extensions/notebook/src/extension.ts @@ -160,10 +160,3 @@ export async function activate(extensionContext: vscode.ExtensionContext): Promi } }; } - -// this method is called when your extension is deactivated -export function deactivate() { - if (controller) { - controller.deactivate(); - } -} diff --git a/extensions/notebook/src/jupyter/jupyterController.ts b/extensions/notebook/src/jupyter/jupyterController.ts index c0c3defd6f..7a6a9d8709 100644 --- a/extensions/notebook/src/jupyter/jupyterController.ts +++ b/extensions/notebook/src/jupyter/jupyterController.ts @@ -13,7 +13,6 @@ const localize = nls.loadMessageBundle(); import * as constants from '../common/constants'; import * as localizedConstants from '../common/localizedConstants'; import { JupyterServerInstallation } from './jupyterServerInstallation'; -import { IServerInstance } from './common'; import * as utils from '../common/utils'; import { IPrompter, IQuestion, confirm } from '../prompts/question'; @@ -33,9 +32,8 @@ import { IconPathHelper } from '../common/iconHelper'; let untitledCounter = 0; -export class JupyterController implements vscode.Disposable { +export class JupyterController { private _jupyterInstallation: JupyterServerInstallation; - private _notebookInstances: IServerInstance[] = []; private _serverInstanceFactory: ServerInstanceFactory = new ServerInstanceFactory(); private _packageManageProviders = new Map(); @@ -54,10 +52,6 @@ export class JupyterController implements vscode.Disposable { return this._notebookProvider; } - public dispose(): void { - this.deactivate(); - } - // PUBLIC METHODS ////////////////////////////////////////////////////// public async activate(): Promise { this._jupyterInstallation = new JupyterServerInstallation( @@ -112,11 +106,6 @@ export class JupyterController implements vscode.Disposable { return this.handleNewNotebookTask(oeContext, oeContext.connectionProfile); } - public deactivate(): void { - // Shutdown any open notebooks - this._notebookInstances.forEach(async (instance) => { await instance.stop(); }); - } - // EVENT HANDLERS ////////////////////////////////////////////////////// public async getDefaultConnection(): Promise { return await azdata.connection.getCurrentConnection(); diff --git a/extensions/notebook/src/jupyter/jupyterServerInstallation.ts b/extensions/notebook/src/jupyter/jupyterServerInstallation.ts index cf54ccc85a..4e7d9cdf2d 100644 --- a/extensions/notebook/src/jupyter/jupyterServerInstallation.ts +++ b/extensions/notebook/src/jupyter/jupyterServerInstallation.ts @@ -207,11 +207,11 @@ export class JupyterServerInstallation implements IJupyterServerInstallation { let extension = process.platform === constants.winPlatform ? 'zip' : 'tar.gz'; packageName = `python-${pythonVersion}-${platformId}-${bundleVersion}.${extension}`; - switch (utils.getOSPlatform()) { - case utils.Platform.Windows: + switch (process.platform) { + case constants.winPlatform: pythonDownloadUrl = constants.pythonWindowsInstallUrl; break; - case utils.Platform.Mac: + case constants.macPlatform: pythonDownloadUrl = constants.pythonMacInstallUrl; break; default: @@ -274,7 +274,7 @@ export class JupyterServerInstallation implements IJupyterServerInstallation { return reject(err); } } - if (utils.getOSPlatform() === utils.Platform.Windows) { + if (process.platform === constants.winPlatform) { try { let zippedFile = new zip(pythonPackagePathLocal); zippedFile.extractAllTo(installPath); diff --git a/extensions/notebook/src/test/common/utils.test.ts b/extensions/notebook/src/test/common/utils.test.ts index e7bf8f78f8..d929443722 100644 --- a/extensions/notebook/src/test/common/utils.test.ts +++ b/extensions/notebook/src/test/common/utils.test.ts @@ -45,10 +45,6 @@ describe('Utils Tests', function () { should(utils.getErrorMessage(errMsg)).equal(errMsg); }); - it('getOSPlatform', async () => { - should(utils.getOSPlatform()).not.throw(); - }); - it('getOSPlatformId', async () => { should(utils.getOSPlatformId()).not.throw(); });