Skip to content
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

Improve interpreter selection on different platforms #517

Merged
merged 55 commits into from
Jan 4, 2018
Merged

Improve interpreter selection on different platforms #517

merged 55 commits into from
Jan 4, 2018

Conversation

MikhailArkhipov
Copy link

Preliminary , working on tests

  • Open Python installation page on Windows if Python is missing
  • Exclude default Apple Python on Mac
  • Install HomeBrew and Python on Mac if only system Python is present
  • Improve user messaging
  • Introduce abstracted app shell (showErrorMessage etc and file system for testability

await this.executeAndOutput('brew', ['install', 'python']);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if platform is Linux?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be like Windows then

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think linux too has a version of Python pre-installed. @brettcannon Do you think we should support the system python in linux?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can leave Linux alone and let users figure it out?

return this._isMac;
}
public get isLinux(): boolean {
return !(this.isWindows || this.isLinux);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the condition supposed to be return !(this.isWindows || this.isMac);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch...

@@ -13,7 +13,8 @@ const options: MochaSetupOptions & { retries: number } = {
ui: 'tdd',
useColors: true,
timeout: 25000,
retries: 3
retries: 3,
grep: 'Signatures'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Booboo

MikhailArkhipov added 2 commits January 2, 2018 15:17
@@ -96,7 +97,7 @@ export async function activate(context: vscode.ExtensionContext) {
const interpreterManager = new InterpreterManager(serviceContainer);

const pythonInstaller = new PythonInstaller(serviceContainer);
const passed = await pythonInstaller.checkPythonInstallation();
const passed = await pythonInstaller.checkPythonInstallation(PythonSettings.getInstance());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought this might not be the best approach.
Users will now get bombarded with messages every time they open a python file in a new workspace.

Previously we'd display a warning on the bottom status bar. This change causes the display of a message every time you open a new workspace.

E.g. people using VS Code for scripting purposes or the like would now see this message every time, and we'd end up with the same issue we had with the linter. The solution was to add an option to stop showing the message ever again.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion is to perform this check when installing a linter or something similar. I.e. at a point in time when the user has been presented with some UI (e.g. selecting an interperter, setting up tests, installing linter, etc from the extension)

@@ -14,7 +14,7 @@ const options: MochaSetupOptions & { retries: number } = {
useColors: true,
timeout: 25000,
retries: 3,
grep: 'Signatures'
grep: 'Installation'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this.

if (this.platform.isMac) {
if (await this.shell.showErrorMessage('Python that comes with Mac OS is not supported. Would you like to install regular Python now?', 'Yes', 'No') === 'Yes') {
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 Brew package manager');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about including instructions for the user to install Brew package manager. E.g.
Unable to install Brew package manager, please install Brew package manager and try again

if (failed) {
resolve(false);
}
if (isTestExecution()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to mock the process, without having to add conditional test code. Feels a little dirty and I'm afraid we'd end up writing a lot more of this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I tried that but mocking of events is pretty convoluted. Basically something needs to emit exit asynchronously while test is running.

constructor( @inject(IServiceContainer) private platformService: IPlatformService) { }

public get directorySeparatorChar(): string {
return this.platformService.isWindows ? '\\' : '/';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use path.sep instead

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

}

public existsAsync(filePath: string): Promise<boolean> {
return new Promise<boolean>(resolve => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use fs.pathExists (use import * as fs from 'fs-extra').
As a suggestion, wouldn't it be better to have fileExists and directoryExists.
I have a need for this (have already create similar methods in another PR, where I want to differentiate between files and directories)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can add dir/file separately. We can add more as we go. I didn't want to add all possible combos.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sure.

}

public createDirectoryAsync(directoryPath: string): Promise<boolean> {
return new Promise<boolean>(resolve => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use fs.mkdirp. I wouldn't swallow the exceptions, just use return fs.mkdirp(directoryPath)

await this.executeAndOutput('brew', ['install', 'python']);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think linux too has a version of Python pre-installed. @brettcannon Do you think we should support the system python in linux?


const persistentStateFactory = serviceManager.get<IPersistentStateFactory>(IPersistentStateFactory);
const pythonSettings = settings.PythonSettings.getInstance();
sendStartupTelemetry(activated, serviceContainer);

sortImports.activate(context, standardOutputChannel);
const interpreterManager = new InterpreterManager(serviceContainer);

const pythonInstaller = new PythonInstaller(serviceContainer);
const passed = await pythonInstaller.checkPythonInstallation(PythonSettings.getInstance());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a good idea. Every time a Mac user opens a workspace or a python file in a new workspace, they have the potential of being hammered with a message. This could end up being an annoying message we had with the linters, the solution to which was to hide the message permanently.

Currently we display a warning in the status bar if the instance of python is invalid (none selected). Personally i prefer that (having learnt the lesson from the linter message). We could display a message when the user tries to install a linter, or setup unit tests or similar.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say this is where @qubitron would have to get involved as this is sort of a UX thing and we've had problems in the past (annoying linter messages) which was conveyed in the survey.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Don't show this again?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd wait for @qubitron to comment on this.

@@ -13,7 +13,8 @@ const options: MochaSetupOptions & { retries: number } = {
ui: 'tdd',
useColors: true,
timeout: 25000,
retries: 3
retries: 3,
grep: 'Installation'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove

@MikhailArkhipov MikhailArkhipov merged commit 4372809 into microsoft:master Jan 4, 2018
@MikhailArkhipov MikhailArkhipov deleted the inst1 branch January 4, 2018 00:27
DonJayamanne added a commit that referenced this pull request Jan 9, 2018
* upstream/master:
  Improve interpreter selection on different platforms (#517)
  Yarn and code coverage (#475)
@lock lock bot locked as resolved and limited conversation to collaborators Jul 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants