Machine Learning Services extension with package management feature (#8622)

* Machine Learning Services extension with package management feature
This commit is contained in:
Leila Lali
2019-12-17 09:55:42 -08:00
committed by GitHub
parent ef8c0e91e6
commit 0a6dc2720d
34 changed files with 3923 additions and 11 deletions

View File

@@ -0,0 +1,112 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as vscode from 'vscode';
import * as nbExtensionApis from '../typings/notebookServices';
import { PackageManager } from '../packageManagement/packageManager';
import * as constants from '../common/constants';
import { ApiWrapper } from '../common/apiWrapper';
import { QueryRunner } from '../common/queryRunner';
import { ProcessService } from '../common/processService';
import { Config } from '../common/config';
/**
* The main controller class that initializes the extension
*/
export default class MainController implements vscode.Disposable {
private _outputChannel: vscode.OutputChannel;
private _rootPath = this._context.extensionPath;
private _config: Config;
public constructor(
private _context: vscode.ExtensionContext,
private _apiWrapper: ApiWrapper,
private _queryRunner: QueryRunner,
private _processService: ProcessService,
private _packageManager?: PackageManager
) {
this._outputChannel = this._apiWrapper.createOutputChannel(constants.extensionOutputChannel);
this._rootPath = this._context.extensionPath;
this._config = new Config(this._rootPath);
}
/**
* Deactivates the extension
*/
public deactivate(): void {
}
/**
* Activates the extension
*/
public async activate(): Promise<boolean> {
await this.initialize();
return Promise.resolve(true);
}
/**
* Returns an instance of Server Installation from notebook extension
*/
private async getNotebookExtensionApis(): Promise<nbExtensionApis.IExtensionApi> {
let nbExtension = this._apiWrapper.getExtension(constants.notebookExtensionName);
if (nbExtension) {
await nbExtension.activate();
return (nbExtension.exports as nbExtensionApis.IExtensionApi);
} else {
throw new Error(constants.notebookExtensionNotLoaded);
}
}
private async initialize(): Promise<void> {
this._outputChannel.show(true);
let nbApis = await this.getNotebookExtensionApis();
await this._config.load();
let packageManager = this.getPackageManager(nbApis);
this._apiWrapper.registerCommand(constants.mlManagePackagesCommand, (async () => {
await packageManager.managePackages();
}));
try {
await packageManager.installDependencies();
} catch (err) {
this._outputChannel.appendLine(err);
}
}
/**
* Returns the package manager instance
*/
public getPackageManager(nbApis: nbExtensionApis.IExtensionApi): PackageManager {
if (!this._packageManager) {
this._packageManager = new PackageManager(nbApis, this._outputChannel, this._rootPath, this._apiWrapper, this._queryRunner, this._processService, this._config);
this._packageManager.init();
}
return this._packageManager;
}
/**
* Package manager instance
*/
public set packageManager(value: PackageManager) {
this._packageManager = value;
}
/**
* Config instance
*/
public get config(): Config {
return this._config;
}
/**
* Disposes the extension
*/
public dispose(): void {
this.deactivate();
}
}