Skip to content

Remove Homebrew installation #537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 65 commits into from
Jan 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
7675901
Basic tokenizer
Dec 1, 2017
eb42669
Fixed property names
Dec 1, 2017
2756974
Tests, round I
Dec 1, 2017
c2c1ced
Tests, round II
Dec 2, 2017
a108c96
merge master
Dec 3, 2017
14864a5
tokenizer test
Dec 4, 2017
0ed51d6
Remove temorary change
Dec 4, 2017
51b544c
Fix merge issue
Dec 4, 2017
3cd11e6
Merge conflict
Dec 4, 2017
82e0ad1
Merge conflict
Dec 4, 2017
9295c1a
Completion test
Dec 4, 2017
06eb1a5
Fix last line
Dec 4, 2017
e9db8e0
Fix javascript math
Dec 4, 2017
d12ca03
Merge master
Dec 5, 2017
d8ab041
Make test await for results
Dec 5, 2017
db75cd0
Add license headers
Dec 5, 2017
9ab2c47
Rename definitions to types
Dec 5, 2017
d587485
License headers
Dec 5, 2017
1da5e0a
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Dec 5, 2017
7668cee
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Dec 11, 2017
1ac4932
Fix typo in completion details (typo)
Dec 11, 2017
2aa5a6c
Fix hover test
Dec 12, 2017
5db31bd
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Dec 12, 2017
560d2af
Russian translations
Dec 13, 2017
c71024d
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Dec 13, 2017
31aa087
Update to better translation
Dec 13, 2017
593ae05
Fix typo
Dec 13, 2017
e6d69bb
#70 How to get all parameter info when filling in a function param list
Dec 13, 2017
b5a23d3
Fix #70 How to get all parameter info when filling in a function para…
Dec 14, 2017
cd200f7
Clean up
Dec 14, 2017
7c33228
Clean imports
Dec 14, 2017
c4a6b90
CR feedback
Dec 14, 2017
f85b848
Trim whitespace for test stability
Dec 14, 2017
37c210b
More tests
Dec 15, 2017
61a5650
Better handle no-parameters documentation
Dec 15, 2017
a10305e
Better handle ellipsis and Python3
Dec 15, 2017
bfcae78
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Dec 15, 2017
42a5f79
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Dec 18, 2017
699c434
Basic services
Dec 20, 2017
dd9ba0a
Install check
Dec 21, 2017
443ad65
Output installer messages
Dec 21, 2017
fdde6b8
Warn default Mac OS interpreter
Dec 23, 2017
e8ea50a
Merge branch 'master' of https://github.com/Microsoft/vscode-python i…
Jan 2, 2018
8b7c920
Remove test change
Jan 2, 2018
253df9e
Add tests
Jan 2, 2018
97ed0a8
PR feedback
Jan 2, 2018
dcfc939
CR feedback
Jan 3, 2018
34790bb
Mock process instead
Jan 3, 2018
b6caacc
Fix Brew detection
Jan 3, 2018
bb648d7
Update test
Jan 3, 2018
a7bca77
Elevated module install
Jan 3, 2018
b1f7fba
Fix path check
Jan 3, 2018
d223410
Add check suppression option & suppress vor VE by default
Jan 3, 2018
6a92e60
Merge branch 'master' of https://github.com/Microsoft/vscode-python i…
Jan 3, 2018
6873309
Fix most linter tests
Jan 3, 2018
9bd8948
Merge conflict
Jan 3, 2018
11c3272
Merge branch 'master' of https://github.com/Microsoft/vscode-python i…
Jan 3, 2018
e0833f7
Merge branch 'inst1' into elev
Jan 4, 2018
29fadba
Per-user install
Jan 4, 2018
2162288
Merge master
Jan 4, 2018
542c1fc
Handle VE/Conda
Jan 4, 2018
0c87c20
Fix tests
Jan 4, 2018
af3cdfa
Remove Homebrew
Jan 4, 2018
d7f5873
Merge branch 'master' of https://github.com/Microsoft/vscode-python i…
Jan 5, 2018
08a495e
Fix OS name
Jan 5, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 10 additions & 88 deletions src/client/common/installer/pythonInstallation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,116 +2,38 @@
// Licensed under the MIT License.
'use strict';

import { OutputChannel } from 'vscode';
import { IInterpreterLocatorService, INTERPRETER_LOCATOR_SERVICE, InterpreterType } from '../../interpreter/contracts';
import { IServiceContainer } from '../../ioc/types';
import { IApplicationShell } from '../application/types';
import { IPythonSettings } from '../configSettings';
import { STANDARD_OUTPUT_CHANNEL } from '../constants';
import { IFileSystem, IPlatformService } from '../platform/types';
import { IProcessService } from '../process/types';
import { IOutputChannel } from '../types';
import { IPlatformService } from '../platform/types';

export class PythonInstaller {
private locator: IInterpreterLocatorService;
private process: IProcessService;
private fs: IFileSystem;
private outputChannel: OutputChannel;
private _platform: IPlatformService;
private _shell: IApplicationShell;
private shell: IApplicationShell;

constructor(private serviceContainer: IServiceContainer) {
this.locator = serviceContainer.get<IInterpreterLocatorService>(IInterpreterLocatorService, INTERPRETER_LOCATOR_SERVICE);
this.shell = serviceContainer.get<IApplicationShell>(IApplicationShell);
}

public async checkPythonInstallation(settings: IPythonSettings): Promise<boolean> {
if (settings.disableInstallationChecks === true) {
return true;
}
let interpreters = await this.locator.getInterpreters();
const interpreters = await this.locator.getInterpreters();
if (interpreters.length > 0) {
if (this.platform.isMac &&
const platform = this.serviceContainer.get<IPlatformService>(IPlatformService);
if (platform.isMac &&
settings.pythonPath === 'python' &&
interpreters[0].type === InterpreterType.Unknown) {
await this.shell.showWarningMessage('Selected interpreter is MacOS system Python which is not recommended. Please select different interpreter');
await this.shell.showWarningMessage('Selected interpreter is macOS system Python which is not recommended. Please select different interpreter');
}
return true;
}

if (!this.platform.isMac) {
// Windows or Linux
await this.shell.showErrorMessage('Python is not installed. Please download and install Python before using the extension.');
this.shell.openUrl('https://www.python.org/downloads');
return false;
}

this.process = this.serviceContainer.get<IProcessService>(IProcessService);
this.fs = this.serviceContainer.get<IFileSystem>(IFileSystem);
this.outputChannel = this.serviceContainer.get<OutputChannel>(IOutputChannel, STANDARD_OUTPUT_CHANNEL);

if (this.platform.isMac) {
if (await this.shell.showErrorMessage('Python that comes with MacOS is not supported. Would you like to install regular Python now?', 'Yes', 'No') === 'Yes') {
const brewInstalled = await this.ensureBrew();
if (!brewInstalled) {
await this.shell.showErrorMessage('Unable to install Homebrew package manager. Try installing it manually.');
this.shell.openUrl('https://brew.sh');
return false;
}
await this.executeAndOutput('brew', ['install', 'python']);
}
}

interpreters = await this.locator.getInterpreters();
return interpreters.length > 0;
}

private isBrewInstalled(): Promise<boolean> {
return this.fs.fileExistsAsync('/usr/local/bin/brew');
}

private async ensureBrew(): Promise<boolean> {
if (await this.isBrewInstalled()) {
return true;
}
const result = await this.executeAndOutput(
'/usr/bin/ruby',
['-e', '"$(curl -fsSL https://github.com/raw/Homebrew/install/master/install)"']);
return result && await this.isBrewInstalled();
}

private executeAndOutput(command: string, args: string[]): Promise<boolean> {
let failed = false;
this.outputChannel.show();

const result = this.process.execObservable(command, args, { mergeStdOutErr: true, throwOnStdErr: false });
result.out.subscribe(output => {
this.outputChannel.append(output.out);
}, error => {
failed = true;
this.shell.showErrorMessage(`Unable to execute '${command}', error: ${error}`);
});

return new Promise<boolean>((resolve, reject) => {
if (failed) {
resolve(false);
}
result.proc.on('exit', (code, signal) => {
resolve(!signal);
});
});
}

private get shell(): IApplicationShell {
if (!this._shell) {
this._shell = this.serviceContainer.get<IApplicationShell>(IApplicationShell);
}
return this._shell;
}

private get platform(): IPlatformService {
if (!this._platform) {
this._platform = this.serviceContainer.get<IPlatformService>(IPlatformService);
}
return this._platform;
await this.shell.showErrorMessage('Python is not installed. Please download and install Python before using the extension.');
this.shell.openUrl('https://www.python.org/downloads');
return false;
}
}
102 changes: 3 additions & 99 deletions src/test/install/pythonInstallation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import { IApplicationShell } from '../../client/common/application/types';
import { IPythonSettings } from '../../client/common/configSettings';
import { STANDARD_OUTPUT_CHANNEL } from '../../client/common/constants';
import { PythonInstaller } from '../../client/common/installer/pythonInstallation';
import { IFileSystem, IPlatformService } from '../../client/common/platform/types';
import { IProcessService, ObservableExecutionResult, Output } from '../../client/common/process/types';
import { IOutputChannel } from '../../client/common/types';
import { IPlatformService } from '../../client/common/platform/types';
import { IInterpreterLocatorService } from '../../client/interpreter/contracts';
import { InterpreterType, PythonInterpreter } from '../../client/interpreter/contracts';
import { ServiceContainer } from '../../client/ioc/container';
Expand All @@ -26,12 +24,9 @@ class TestContext {
public serviceManager: ServiceManager;
public serviceContainer: IServiceContainer;
public platform: TypeMoq.IMock<IPlatformService>;
public fileSystem: TypeMoq.IMock<IFileSystem>;
public appShell: TypeMoq.IMock<IApplicationShell>;
public locator: TypeMoq.IMock<IInterpreterLocatorService>;
public settings: TypeMoq.IMock<IPythonSettings>;
public process: TypeMoq.IMock<IProcessService>;
public output: TypeMoq.IMock<vscode.OutputChannel>;
public pythonInstaller: PythonInstaller;

constructor(isMac: boolean) {
Expand All @@ -40,19 +35,13 @@ class TestContext {
this.serviceContainer = new ServiceContainer(cont);

this.platform = TypeMoq.Mock.ofType<IPlatformService>();
this.fileSystem = TypeMoq.Mock.ofType<IFileSystem>();
this.appShell = TypeMoq.Mock.ofType<IApplicationShell>();
this.locator = TypeMoq.Mock.ofType<IInterpreterLocatorService>();
this.settings = TypeMoq.Mock.ofType<IPythonSettings>();
this.process = TypeMoq.Mock.ofType<IProcessService>();
this.output = TypeMoq.Mock.ofType<vscode.OutputChannel>();

this.serviceManager.addSingletonInstance<IPlatformService>(IPlatformService, this.platform.object);
this.serviceManager.addSingletonInstance<IFileSystem>(IFileSystem, this.fileSystem.object);
this.serviceManager.addSingletonInstance<IApplicationShell>(IApplicationShell, this.appShell.object);
this.serviceManager.addSingletonInstance<IInterpreterLocatorService>(IInterpreterLocatorService, this.locator.object);
this.serviceManager.addSingletonInstance<IProcessService>(IProcessService, this.process.object);
this.serviceManager.addSingletonInstance<vscode.OutputChannel>(IOutputChannel, this.output.object, STANDARD_OUTPUT_CHANNEL);
this.pythonInstaller = new PythonInstaller(this.serviceContainer);

this.platform.setup(x => x.isMac).returns(() => isMac);
Expand Down Expand Up @@ -80,7 +69,7 @@ suite('Installation', () => {
assert.equal(showErrorMessageCalled, false, 'Disabling checks has no effect');
});

test('Windows: Python missing', async () => {
test('Python missing', async () => {
const c = new TestContext(false);
let showErrorMessageCalled = false;
let openUrlCalled = false;
Expand All @@ -100,7 +89,7 @@ suite('Installation', () => {
assert.equal(url, 'https://www.python.org/downloads', 'Python download page is incorrect');
});

test('Mac: Python missing', async () => {
test('Mac: Default Python warning', async () => {
const c = new TestContext(true);
let called = false;
c.appShell.setup(x => x.showWarningMessage(TypeMoq.It.isAnyString())).callback(() => called = true);
Expand All @@ -115,89 +104,4 @@ suite('Installation', () => {
assert.equal(passed, true, 'Default MacOS Python not accepted');
assert.equal(called, true, 'Warning not shown');
});

test('Mac: Default Python, user refused install', async () => {
const c = new TestContext(true);
let errorMessage = '';

c.appShell
.setup(x => x.showErrorMessage(TypeMoq.It.isAnyString(), TypeMoq.It.isAnyString(), TypeMoq.It.isAnyString()))
.callback((m: string, a1: string, a2: string) => errorMessage = m)
.returns(() => Promise.resolve('No'));
c.locator.setup(x => x.getInterpreters()).returns(() => Promise.resolve([]));

const passed = await c.pythonInstaller.checkPythonInstallation(c.settings.object);
assert.equal(passed, false, 'Default MacOS Python accepted');
assert.equal(errorMessage.startsWith('Python that comes with MacOS is not supported'), true, 'Error message that MacOS Python not supported not shown');
});

test('Mac: Default Python, Brew installation', async () => {
const c = new TestContext(true);
let errorMessage = '';
let processName = '';
let args;
let brewPath;
let outputShown = false;

c.appShell
.setup(x => x.showErrorMessage(TypeMoq.It.isAnyString(), TypeMoq.It.isAnyString(), TypeMoq.It.isAnyString()))
.returns(() => Promise.resolve('Yes'));
c.appShell
.setup(x => x.showErrorMessage(TypeMoq.It.isAnyString()))
.callback((m: string) => errorMessage = m);
c.locator.setup(x => x.getInterpreters()).returns(() => Promise.resolve([]));
c.fileSystem
.setup(x => x.fileExistsAsync(TypeMoq.It.isAnyString()))
.returns((p: string) => {
brewPath = p;
return Promise.resolve(false);
});

const childProcess = TypeMoq.Mock.ofType<ChildProcess>();
childProcess
.setup(p => p.on('exit', TypeMoq.It.isAny()))
.callback((e: string, listener: (code, signal) => void) => {
listener.call(0, undefined);
});
const processOutput: Output<string> = {
source: 'stdout',
out: 'started'
};
const observable = new Rx.Observable<Output<string>>(subscriber => subscriber.next(processOutput));
const brewInstallProcess: ObservableExecutionResult<string> = {
proc: childProcess.object,
out: observable
};

c.output.setup(x => x.show()).callback(() => outputShown = true);
c.process
.setup(x => x.execObservable(TypeMoq.It.isAnyString(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.callback((p: string, a: string[], o: SpawnOptions) => {
processName = p;
args = a;
})
.returns(() => brewInstallProcess);

await c.pythonInstaller.checkPythonInstallation(c.settings.object);

assert.notEqual(brewPath, undefined, 'Brew installer location not checked');
assert.equal(brewPath, '/usr/local/bin/brew', 'Brew installer location is incorrect');
assert.notEqual(processName, undefined, 'Brew installer not invoked');
assert.equal(processName, '/usr/bin/ruby', 'Brew installer name is incorrect');
assert.equal(args[0], '-e', 'Brew installer argument is incorrect');
assert.equal(args[1], '"$(curl -fsSL https://github.com/raw/Homebrew/install/master/install)"', 'Homebrew installer argument is incorrect');
assert.equal(outputShown, true, 'Output panel not shown');
assert.equal(errorMessage.startsWith('Unable to install Homebrew'), true, 'Homebrew install failed message no shown');

c.fileSystem
.setup(x => x.fileExistsAsync(TypeMoq.It.isAnyString()))
.returns(() => Promise.resolve(true));
errorMessage = '';

await c.pythonInstaller.checkPythonInstallation(c.settings.object);
assert.equal(errorMessage, '', `Unexpected error message ${errorMessage}`);
assert.equal(processName, 'brew', 'Brew installer name is incorrect');
assert.equal(args[0], 'install', 'Brew "install" argument is incorrect');
assert.equal(args[1], 'python', 'Brew "python" argument is incorrect');
});
});