Machine Learning Services Settings (#8968)

* Added two config to Machine Learning Services extension to enable and disable python and r
This commit is contained in:
Leila Lali
2020-02-03 09:25:36 -08:00
committed by GitHub
parent c6689700f6
commit 56a6f70c0d
11 changed files with 68 additions and 8 deletions

View File

@@ -30,6 +30,8 @@ export const mlsDependenciesCommand = 'mls.command.dependencies';
//
export const mlsConfigKey = 'machineLearningServices';
export const pythonPathConfigKey = 'pythonPath';
export const pythonEnabledConfigKey = 'enablePython';
export const rEnabledConfigKey = 'enableR';
export const rPathConfigKey = 'rPath';
// Localized texts

View File

@@ -1,13 +0,0 @@
{
"requiredPythonPackages": [
{ "name": "pymssql", "version": "2.1.4" },
{ "name": "sqlmlutils", "version": ""}
],
"requiredRPackages": [
{ "name": "RODBCext", "repository": "https://cran.microsoft.com" },
{ "name": "sqlmlutils", "fileName": "sqlmlutils_0.7.1.zip", "downloadUrl": "https://github.com/microsoft/sqlmlutils/blob/master/R/dist/sqlmlutils_0.7.1.zip?raw=true"}
],
"rPackagesRepository": "https://cran.r-project.org"
}

View File

@@ -21,7 +21,6 @@ const defaultRExecutable = 'r';
export class Config {
private _configValues: any;
private _mlsConfig: vscode.WorkspaceConfiguration | undefined;
constructor(private _root: string, private _apiWrapper: ApiWrapper) {
}
@@ -30,7 +29,7 @@ export class Config {
* Loads the config values
*/
public async load(): Promise<void> {
const rawConfig = await fs.readFile(path.join(this._root, 'out', 'configurations', configFileName));
const rawConfig = await fs.readFile(path.join(this._root, configFileName));
this._configValues = JSON.parse(rawConfig.toString());
}
@@ -62,6 +61,20 @@ export class Config {
return this.config.get(constants.pythonPathConfigKey) || defaultPythonExecutable;
}
/**
* Returns true if python package management is enabled
*/
public get pythonEnabled(): boolean {
return this.config.get(constants.pythonEnabledConfigKey) || false;
}
/**
* Returns true if r package management is enabled
*/
public get rEnabled(): boolean {
return this.config.get(constants.rEnabledConfigKey) || false;
}
/**
* Returns r path from user settings
*/
@@ -70,9 +83,6 @@ export class Config {
}
private get config(): vscode.WorkspaceConfiguration {
if (!this._mlsConfig) {
this._mlsConfig = this._apiWrapper.getConfiguration(constants.mlsConfigKey);
}
return this._mlsConfig;
return this._apiWrapper.getConfiguration(constants.mlsConfigKey);
}
}

View File

@@ -132,6 +132,9 @@ export class PackageManager {
}
private async installRequiredRPackages(startBackgroundOperation: azdata.BackgroundOperation): Promise<void> {
if (!this._config.rEnabled) {
return;
}
if (!this._rExecutable) {
throw new Error(constants.rConfigError);
}
@@ -143,6 +146,9 @@ export class PackageManager {
* Installs required python packages
*/
private async installRequiredPythonPackages(): Promise<void> {
if (!this._config.pythonEnabled) {
return;
}
if (!this._pythonExecutable) {
throw new Error(constants.pythonConfigError);
}

View File

@@ -93,6 +93,9 @@ export class SqlPythonPackageManageProvider extends SqlPackageManageProviderBase
* Returns true if the provider can be used
*/
async canUseProvider(): Promise<boolean> {
if (!this._config.pythonEnabled) {
return false;
}
let connection = await this.getCurrentConnection();
if (connection && await this._queryRunner.isPythonInstalled(connection)) {
return true;

View File

@@ -92,6 +92,9 @@ export class SqlRPackageManageProvider extends SqlPackageManageProviderBase impl
* Returns true if the provider can be used
*/
async canUseProvider(): Promise<boolean> {
if (!this._config.rEnabled) {
return false;
}
let connection = await this.getCurrentConnection();
if (connection && await this._queryRunner.isRInstalled(connection)) {
return true;

View File

@@ -192,6 +192,8 @@ describe('Package Manager', () => {
testContext.httpClient.setup(x => x.download(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve());
testContext.config.setup(x => x.pythonExecutable).returns(() => 'python');
testContext.config.setup(x => x.rExecutable).returns(() => 'r');
testContext.config.setup(x => x.rEnabled).returns(() => true);
testContext.config.setup(x => x.pythonEnabled).returns(() => true);
let packageManager = new PackageManager(
testContext.outputChannel,
'',

View File

@@ -319,6 +319,16 @@ describe('SQL Python Package Manager', () => {
should.deepEqual(actual, true);
});
it('canUseProvider Should return false if python is disabled in setting', async function (): Promise<void> {
let testContext = createContext();
let provider = createProvider(testContext);
testContext.config.setup(x => x.pythonEnabled).returns(() => false);
let actual = await provider.canUseProvider();
should.deepEqual(actual, false);
});
it('getPackageOverview Should return package info using python packages provider', async function (): Promise<void> {
let testContext = createContext();
let packagePreview = {
@@ -376,6 +386,7 @@ describe('SQL Python Package Manager', () => {
function createProvider(testContext: TestContext): SqlPythonPackageManageProvider {
testContext.config.setup(x => x.pythonExecutable).returns(() => 'python');
testContext.config.setup(x => x.pythonEnabled).returns(() => true);
return new SqlPythonPackageManageProvider(
testContext.outputChannel,
testContext.apiWrapper.object,

View File

@@ -243,6 +243,16 @@ describe('SQL R Package Manager', () => {
should.deepEqual(actual, true);
});
it('canUseProvider Should return false if r is disabled in setting', async function (): Promise<void> {
let testContext = createContext();
let provider = createProvider(testContext);
testContext.config.setup(x => x.rEnabled).returns(() => false);
let actual = await provider.canUseProvider();
should.deepEqual(actual, false);
});
it('getPackageOverview Should return package info successfully', async function (): Promise<void> {
let testContext = createContext();
let packagePreview = {
@@ -301,6 +311,7 @@ describe('SQL R Package Manager', () => {
function createProvider(testContext: TestContext): SqlRPackageManageProvider {
testContext.config.setup(x => x.rExecutable).returns(() => 'r');
testContext.config.setup(x => x.rEnabled).returns(() => true);
testContext.config.setup(x => x.rPackagesRepository).returns(() => 'http://cran.r-project.org');
return new SqlRPackageManageProvider(
testContext.outputChannel,