forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
804 + Improve 'no installers available' messaging (#823)
* Fix pylint search * Handle quote escapes in strings * Escapes in strings * CR feedback * Missing pip * Test * Tests * Tests * Mac python path * Tests * Tests * Test * "Go To Python object" doesn't work * Proper detection and type population in virtual env * Test fixes * Discover pylintrc better + tests * Undo change * CR feedback * Set interprereter before checking install
- Loading branch information
Mikhail Arkhipov
authored
Feb 20, 2018
1 parent
3fe37a2
commit d44386e
Showing
23 changed files
with
442 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { inject, injectable } from 'inversify'; | ||
import { QuickPickItem, Uri } from 'vscode'; | ||
import { IInterpreterService, InterpreterType } from '../../interpreter/contracts'; | ||
import { IServiceContainer } from '../../ioc/types'; | ||
import { IApplicationShell } from '../application/types'; | ||
import { IPlatformService } from '../platform/types'; | ||
import { Product } from '../types'; | ||
import { ProductNames } from './productNames'; | ||
import { IInstallationChannelManager, IModuleInstaller } from './types'; | ||
|
||
@injectable() | ||
export class InstallationChannelManager implements IInstallationChannelManager { | ||
constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer) { } | ||
|
||
public async getInstallationChannel(product: Product, resource?: Uri): Promise<IModuleInstaller | undefined> { | ||
const channels = await this.getInstallationChannels(resource); | ||
if (channels.length === 1) { | ||
return channels[0]; | ||
} | ||
|
||
const productName = ProductNames.get(product)!; | ||
const appShell = this.serviceContainer.get<IApplicationShell>(IApplicationShell); | ||
if (channels.length === 0) { | ||
await this.showNoInstallersMessage(resource); | ||
return; | ||
} | ||
|
||
const placeHolder = `Select an option to install ${productName}`; | ||
const options = channels.map(installer => { | ||
return { | ||
label: `Install using ${installer.displayName}`, | ||
description: '', | ||
installer | ||
} as QuickPickItem & { installer: IModuleInstaller }; | ||
}); | ||
const selection = await appShell.showQuickPick(options, { matchOnDescription: true, matchOnDetail: true, placeHolder }); | ||
return selection ? selection.installer : undefined; | ||
} | ||
|
||
public async getInstallationChannels(resource?: Uri): Promise<IModuleInstaller[]> { | ||
const installers = this.serviceContainer.getAll<IModuleInstaller>(IModuleInstaller); | ||
const supportedInstallers: IModuleInstaller[] = []; | ||
for (const mi of installers) { | ||
if (await mi.isSupported(resource)) { | ||
supportedInstallers.push(mi); | ||
} | ||
} | ||
return supportedInstallers; | ||
} | ||
|
||
public async showNoInstallersMessage(resource?: Uri): Promise<void> { | ||
const interpreters = this.serviceContainer.get<IInterpreterService>(IInterpreterService); | ||
const interpreter = await interpreters.getActiveInterpreter(resource); | ||
if (!interpreter) { | ||
return; // Handled in the Python installation check. | ||
} | ||
|
||
const appShell = this.serviceContainer.get<IApplicationShell>(IApplicationShell); | ||
const search = 'Search for help'; | ||
let result: string | undefined; | ||
if (interpreter.type === InterpreterType.Conda) { | ||
result = await appShell.showErrorMessage('There is no Conda or Pip installer available in the selected environment.', search); | ||
} else { | ||
result = await appShell.showErrorMessage('There is no Pip installer available in the selected environment.', search); | ||
} | ||
if (result === search) { | ||
const platform = this.serviceContainer.get<IPlatformService>(IPlatformService); | ||
const osName = platform.isWindows | ||
? 'Windows' | ||
: (platform.isMac ? 'MacOS' : 'Linux'); | ||
appShell.openUrl(`https://www.bing.com/search?q=Install Pip ${osName} ${(interpreter.type === InterpreterType.Conda) ? 'Conda' : ''}`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { Product } from '../types'; | ||
|
||
// tslint:disable-next-line:variable-name | ||
export const ProductNames = new Map<Product, string>(); | ||
ProductNames.set(Product.autopep8, 'autopep8'); | ||
ProductNames.set(Product.flake8, 'flake8'); | ||
ProductNames.set(Product.mypy, 'mypy'); | ||
ProductNames.set(Product.nosetest, 'nosetest'); | ||
ProductNames.set(Product.pep8, 'pep8'); | ||
ProductNames.set(Product.pylama, 'pylama'); | ||
ProductNames.set(Product.prospector, 'prospector'); | ||
ProductNames.set(Product.pydocstyle, 'pydocstyle'); | ||
ProductNames.set(Product.pylint, 'pylint'); | ||
ProductNames.set(Product.pytest, 'pytest'); | ||
ProductNames.set(Product.yapf, 'yapf'); | ||
ProductNames.set(Product.rope, 'rope'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.