mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Remove unnecessary OutputChannel reference from PythonPathLookup class. (#13970)
This commit is contained in:
@@ -8,7 +8,6 @@ import * as azdata from 'azdata';
|
|||||||
import { BasePage } from './basePage';
|
import { BasePage } from './basePage';
|
||||||
import * as nls from 'vscode-nls';
|
import * as nls from 'vscode-nls';
|
||||||
import { JupyterServerInstallation } from '../../jupyter/jupyterServerInstallation';
|
import { JupyterServerInstallation } from '../../jupyter/jupyterServerInstallation';
|
||||||
import { PythonPathInfo } from '../pythonPathLookup';
|
|
||||||
import * as utils from '../../common/utils';
|
import * as utils from '../../common/utils';
|
||||||
|
|
||||||
const localize = nls.loadMessageBundle();
|
const localize = nls.loadMessageBundle();
|
||||||
@@ -160,10 +159,9 @@ export class ConfigurePathPage extends BasePage {
|
|||||||
this.instance.wizard.nextButton.enabled = false;
|
this.instance.wizard.nextButton.enabled = false;
|
||||||
this.pythonDropdownLoader.loading = true;
|
this.pythonDropdownLoader.loading = true;
|
||||||
try {
|
try {
|
||||||
let pythonPaths: PythonPathInfo[];
|
|
||||||
let dropdownValues: azdata.CategoryValue[];
|
let dropdownValues: azdata.CategoryValue[];
|
||||||
if (useExistingPython) {
|
if (useExistingPython) {
|
||||||
pythonPaths = await this.model.pythonPathsPromise;
|
let pythonPaths = await this.model.pythonPathLookup.getSuggestions();
|
||||||
if (pythonPaths && pythonPaths.length > 0) {
|
if (pythonPaths && pythonPaths.length > 0) {
|
||||||
dropdownValues = pythonPaths.map(path => {
|
dropdownValues = pythonPaths.map(path => {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
import * as nls from 'vscode-nls';
|
import * as nls from 'vscode-nls';
|
||||||
import * as azdata from 'azdata';
|
import * as azdata from 'azdata';
|
||||||
import * as vscode from 'vscode';
|
|
||||||
import { BasePage } from './basePage';
|
import { BasePage } from './basePage';
|
||||||
import { ConfigurePathPage } from './configurePathPage';
|
import { ConfigurePathPage } from './configurePathPage';
|
||||||
import { PickPackagesPage } from './pickPackagesPage';
|
import { PickPackagesPage } from './pickPackagesPage';
|
||||||
@@ -13,7 +12,7 @@ import { JupyterServerInstallation, PythonPkgDetails, PythonInstallSettings } fr
|
|||||||
import * as utils from '../../common/utils';
|
import * as utils from '../../common/utils';
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'fs';
|
||||||
import { Deferred } from '../../common/promise';
|
import { Deferred } from '../../common/promise';
|
||||||
import { PythonPathInfo, PythonPathLookup } from '../pythonPathLookup';
|
import { PythonPathLookup } from '../pythonPathLookup';
|
||||||
|
|
||||||
const localize = nls.loadMessageBundle();
|
const localize = nls.loadMessageBundle();
|
||||||
|
|
||||||
@@ -21,7 +20,7 @@ export interface ConfigurePythonModel {
|
|||||||
kernelName: string;
|
kernelName: string;
|
||||||
pythonLocation: string;
|
pythonLocation: string;
|
||||||
useExistingPython: boolean;
|
useExistingPython: boolean;
|
||||||
pythonPathsPromise: Promise<PythonPathInfo[]>;
|
pythonPathLookup: PythonPathLookup;
|
||||||
packagesToInstall: PythonPkgDetails[];
|
packagesToInstall: PythonPkgDetails[];
|
||||||
installation: JupyterServerInstallation;
|
installation: JupyterServerInstallation;
|
||||||
}
|
}
|
||||||
@@ -35,11 +34,9 @@ export class ConfigurePythonWizard {
|
|||||||
private model: ConfigurePythonModel;
|
private model: ConfigurePythonModel;
|
||||||
|
|
||||||
private _setupComplete: Deferred<void>;
|
private _setupComplete: Deferred<void>;
|
||||||
private pythonPathsPromise: Promise<PythonPathInfo[]>;
|
|
||||||
|
|
||||||
constructor(private jupyterInstallation: JupyterServerInstallation, private readonly _outputChannel: vscode.OutputChannel) {
|
constructor(private jupyterInstallation: JupyterServerInstallation) {
|
||||||
this._setupComplete = new Deferred<void>();
|
this._setupComplete = new Deferred<void>();
|
||||||
this.pythonPathsPromise = (new PythonPathLookup(this._outputChannel)).getSuggestions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public get wizard(): azdata.window.Wizard {
|
public get wizard(): azdata.window.Wizard {
|
||||||
@@ -53,7 +50,7 @@ export class ConfigurePythonWizard {
|
|||||||
public async start(kernelName?: string, rejectOnCancel?: boolean): Promise<void> {
|
public async start(kernelName?: string, rejectOnCancel?: boolean): Promise<void> {
|
||||||
this.model = <ConfigurePythonModel>{
|
this.model = <ConfigurePythonModel>{
|
||||||
kernelName: kernelName,
|
kernelName: kernelName,
|
||||||
pythonPathsPromise: this.pythonPathsPromise,
|
pythonPathLookup: new PythonPathLookup(),
|
||||||
installation: this.jupyterInstallation,
|
installation: this.jupyterInstallation,
|
||||||
pythonLocation: JupyterServerInstallation.getPythonPathSetting(),
|
pythonLocation: JupyterServerInstallation.getPythonPathSetting(),
|
||||||
useExistingPython: JupyterServerInstallation.getExistingPythonSetting()
|
useExistingPython: JupyterServerInstallation.getExistingPythonSetting()
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
import * as glob from 'glob';
|
import * as glob from 'glob';
|
||||||
import * as vscode from 'vscode';
|
|
||||||
|
|
||||||
import * as utils from '../common/utils';
|
import * as utils from '../common/utils';
|
||||||
import * as constants from '../common/constants';
|
import * as constants from '../common/constants';
|
||||||
@@ -16,7 +15,7 @@ export interface PythonPathInfo {
|
|||||||
|
|
||||||
export class PythonPathLookup {
|
export class PythonPathLookup {
|
||||||
private condaLocations: string[];
|
private condaLocations: string[];
|
||||||
constructor(private readonly _outputChannel: vscode.OutputChannel) {
|
constructor() {
|
||||||
if (process.platform !== constants.winPlatform) {
|
if (process.platform !== constants.winPlatform) {
|
||||||
let userFolder = process.env['HOME'];
|
let userFolder = process.env['HOME'];
|
||||||
this.condaLocations = [
|
this.condaLocations = [
|
||||||
@@ -57,7 +56,7 @@ export class PythonPathLookup {
|
|||||||
let condaFiles = condaResults.reduce((first, second) => first.concat(second));
|
let condaFiles = condaResults.reduce((first, second) => first.concat(second));
|
||||||
return condaFiles.filter(condaPath => condaPath && condaPath.length > 0);
|
return condaFiles.filter(condaPath => condaPath && condaPath.length > 0);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this._outputChannel.appendLine(`Problem encountered getting Conda installations: ${err}`);
|
console.log(`Problem encountered getting Conda installations: ${err}`);
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -86,7 +85,7 @@ export class PythonPathLookup {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getPythonPath(options: { command: string; args?: string[] }): Promise<string> {
|
private async getPythonPath(options: { command: string; args?: string[] }): Promise<string | undefined> {
|
||||||
try {
|
try {
|
||||||
let args = Array.isArray(options.args) ? options.args : [];
|
let args = Array.isArray(options.args) ? options.args : [];
|
||||||
args = args.concat(['-c', '"import sys;print(sys.executable)"']);
|
args = args.concat(['-c', '"import sys;print(sys.executable)"']);
|
||||||
@@ -97,7 +96,7 @@ export class PythonPathLookup {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this._outputChannel.appendLine(`Problem encountered getting Python path: ${err}`);
|
// Ignoring this error since it's probably from trying to run a non-existent python executable.
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -141,7 +140,7 @@ export class PythonPathLookup {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getInfoForPath(pythonPath: string): Promise<PythonPathInfo> {
|
private async getInfoForPath(pythonPath: string): Promise<PythonPathInfo | undefined> {
|
||||||
try {
|
try {
|
||||||
// "python --version" returns nothing from executeBufferedCommand with Python 2.X,
|
// "python --version" returns nothing from executeBufferedCommand with Python 2.X,
|
||||||
// so use sys.version_info here instead.
|
// so use sys.version_info here instead.
|
||||||
@@ -160,7 +159,7 @@ export class PythonPathLookup {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this._outputChannel.appendLine(`Problem encountered getting Python info for path: ${err}`);
|
console.log(`Problem encountered getting Python info for path: ${err}`);
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ export class JupyterController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public doConfigurePython(jupyterInstaller: JupyterServerInstallation): void {
|
public doConfigurePython(jupyterInstaller: JupyterServerInstallation): void {
|
||||||
let pythonWizard = new ConfigurePythonWizard(jupyterInstaller, this.appContext.outputChannel);
|
let pythonWizard = new ConfigurePythonWizard(jupyterInstaller);
|
||||||
pythonWizard.start().catch((err: any) => {
|
pythonWizard.start().catch((err: any) => {
|
||||||
vscode.window.showErrorMessage(utils.getErrorMessage(err));
|
vscode.window.showErrorMessage(utils.getErrorMessage(err));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -435,7 +435,7 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
|
|||||||
let isPythonInstalled = JupyterServerInstallation.isPythonInstalled();
|
let isPythonInstalled = JupyterServerInstallation.isPythonInstalled();
|
||||||
let areRequiredPackagesInstalled = await this.areRequiredPackagesInstalled(kernelDisplayName);
|
let areRequiredPackagesInstalled = await this.areRequiredPackagesInstalled(kernelDisplayName);
|
||||||
if (!isPythonInstalled || !areRequiredPackagesInstalled) {
|
if (!isPythonInstalled || !areRequiredPackagesInstalled) {
|
||||||
let pythonWizard = new ConfigurePythonWizard(this, this.outputChannel);
|
let pythonWizard = new ConfigurePythonWizard(this);
|
||||||
await pythonWizard.start(kernelDisplayName, true);
|
await pythonWizard.start(kernelDisplayName, true);
|
||||||
return pythonWizard.setupComplete.then(() => {
|
return pythonWizard.setupComplete.then(() => {
|
||||||
this._kernelSetupCache.set(kernelDisplayName, true);
|
this._kernelSetupCache.set(kernelDisplayName, true);
|
||||||
|
|||||||
@@ -13,16 +13,14 @@ import { PickPackagesPage } from '../../dialog/configurePython/pickPackagesPage'
|
|||||||
import { python3DisplayName, allKernelsName } from '../../common/constants';
|
import { python3DisplayName, allKernelsName } from '../../common/constants';
|
||||||
import { TestContext, createViewContext, TestButton } from '../common';
|
import { TestContext, createViewContext, TestButton } from '../common';
|
||||||
import { EventEmitter } from 'vscode';
|
import { EventEmitter } from 'vscode';
|
||||||
import { MockOutputChannel } from '../common/stubs';
|
import { PythonPathLookup } from '../../dialog/pythonPathLookup';
|
||||||
|
|
||||||
describe('Configure Python Wizard', function () {
|
describe('Configure Python Wizard', function () {
|
||||||
let testWizard: ConfigurePythonWizard;
|
let testWizard: ConfigurePythonWizard;
|
||||||
let viewContext: TestContext;
|
let viewContext: TestContext;
|
||||||
let testInstallation: JupyterServerInstallation;
|
let testInstallation: JupyterServerInstallation;
|
||||||
let mockOutputChannel: TypeMoq.IMock<MockOutputChannel>;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockOutputChannel = TypeMoq.Mock.ofType(MockOutputChannel);
|
|
||||||
let mockInstall = TypeMoq.Mock.ofType(JupyterServerInstallation);
|
let mockInstall = TypeMoq.Mock.ofType(JupyterServerInstallation);
|
||||||
mockInstall.setup(i => i.getInstalledPipPackages(TypeMoq.It.isAnyString())).returns(() => Promise.resolve([]));
|
mockInstall.setup(i => i.getInstalledPipPackages(TypeMoq.It.isAnyString())).returns(() => Promise.resolve([]));
|
||||||
mockInstall.setup(i => i.getRequiredPackagesForKernel(TypeMoq.It.isAnyString())).returns(() => [{ name: 'TestPkg', version: '1.0.0'}]);
|
mockInstall.setup(i => i.getRequiredPackagesForKernel(TypeMoq.It.isAnyString())).returns(() => [{ name: 'TestPkg', version: '1.0.0'}]);
|
||||||
@@ -44,21 +42,21 @@ describe('Configure Python Wizard', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Start wizard test', async () => {
|
it('Start wizard test', async () => {
|
||||||
let wizard = new ConfigurePythonWizard(testInstallation, mockOutputChannel.object);
|
let wizard = new ConfigurePythonWizard(testInstallation);
|
||||||
await wizard.start();
|
await wizard.start();
|
||||||
await wizard.close();
|
await wizard.close();
|
||||||
await should(wizard.setupComplete).be.resolved();
|
await should(wizard.setupComplete).be.resolved();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Reject setup on cancel test', async () => {
|
it('Reject setup on cancel test', async () => {
|
||||||
let wizard = new ConfigurePythonWizard(testInstallation, mockOutputChannel.object);
|
let wizard = new ConfigurePythonWizard(testInstallation);
|
||||||
await wizard.start(undefined, true);
|
await wizard.start(undefined, true);
|
||||||
await wizard.close();
|
await wizard.close();
|
||||||
await should(wizard.setupComplete).be.rejected();
|
await should(wizard.setupComplete).be.rejected();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Error message test', async () => {
|
it('Error message test', async () => {
|
||||||
let wizard = new ConfigurePythonWizard(testInstallation, mockOutputChannel.object);
|
let wizard = new ConfigurePythonWizard(testInstallation);
|
||||||
await wizard.start();
|
await wizard.start();
|
||||||
|
|
||||||
should(wizard.wizard.message).be.undefined();
|
should(wizard.wizard.message).be.undefined();
|
||||||
@@ -72,16 +70,21 @@ describe('Configure Python Wizard', function () {
|
|||||||
should(wizard.wizard.message).be.undefined();
|
should(wizard.wizard.message).be.undefined();
|
||||||
|
|
||||||
await wizard.close();
|
await wizard.close();
|
||||||
|
await should(wizard.setupComplete).be.resolved();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Configure Path Page test', async () => {
|
it('Configure Path Page test', async () => {
|
||||||
let testPythonLocation = '/not/a/real/path';
|
let testPythonLocation = '/not/a/real/path';
|
||||||
let model = <ConfigurePythonModel>{
|
let mockPathLookup = TypeMoq.Mock.ofType(PythonPathLookup);
|
||||||
useExistingPython: true,
|
mockPathLookup.setup(p => p.getSuggestions()).returns(() =>
|
||||||
pythonPathsPromise: Promise.resolve([{
|
Promise.resolve([{
|
||||||
installDir: testPythonLocation,
|
installDir: testPythonLocation,
|
||||||
version: '4000'
|
version: '4000'
|
||||||
}])
|
}])
|
||||||
|
);
|
||||||
|
let model = <ConfigurePythonModel>{
|
||||||
|
useExistingPython: true,
|
||||||
|
pythonPathLookup: mockPathLookup.object
|
||||||
};
|
};
|
||||||
|
|
||||||
let page = azdata.window.createWizardPage('Page 1');
|
let page = azdata.window.createWizardPage('Page 1');
|
||||||
|
|||||||
Reference in New Issue
Block a user