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

Ensure Pylint<2.0.0 on Python 2.x #2178

Merged
merged 7 commits into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
3 changes: 1 addition & 2 deletions src/client/common/installer/condaInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ export class CondaInstaller extends ModuleInstaller implements IModuleInstaller
args.push(moduleName);
return {
args,
execPath: condaFile,
moduleName: ''
execPath: condaFile
};
}
private async isCurrentEnvironmentACondaEnvironment(resource?: Uri): Promise<boolean> {
Expand Down
22 changes: 20 additions & 2 deletions src/client/common/installer/moduleInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ export abstract class ModuleInstaller {
const executionInfo = await this.getExecutionInfo(name, resource);
const terminalService = this.serviceContainer.get<ITerminalServiceFactory>(ITerminalServiceFactory).getTerminalService(resource);

const executionInfoArgs = await this.processInstallArgs(executionInfo.args, resource);
if (executionInfo.moduleName) {
const settings = PythonSettings.getInstance(resource);
const args = ['-m', 'pip'].concat(executionInfo.args);
const args = ['-m', executionInfo.moduleName].concat(executionInfoArgs);

const pythonPath = settings.pythonPath;

const interpreterService = this.serviceContainer.get<IInterpreterService>(IInterpreterService);
Expand All @@ -43,12 +45,28 @@ export abstract class ModuleInstaller {
await terminalService.sendCommand(pythonPath, args.concat(['--user']));
}
} else {
await terminalService.sendCommand(executionInfo.execPath!, executionInfo.args);
await terminalService.sendCommand(executionInfo.execPath!, executionInfoArgs);
}
}
public abstract isSupported(resource?: vscode.Uri): Promise<boolean>;
protected abstract getExecutionInfo(moduleName: string, resource?: vscode.Uri): Promise<ExecutionInfo>;
private async processInstallArgs(args: string[], resource?: vscode.Uri): Promise<string[]> {
const indexOfPylint = args.findIndex(arg => arg.toUpperCase() === 'PYLINT');
if (indexOfPylint === -1) {
return args;
}

// If installing pylint on python 2.x, then use pylint~=1.9.0
const interpreterService = this.serviceContainer.get<IInterpreterService>(IInterpreterService);
const currentInterpreter = await interpreterService.getActiveInterpreter(resource);
if (currentInterpreter && currentInterpreter.version_info && currentInterpreter.version_info[0] === 2) {
const newArgs = [...args];
// This command could be sent to the terminal, hence '<' needs to be escaped for Mac.
newArgs[indexOfPylint] = '"pylint<=2.0.0"';
Copy link
Member

Choose a reason for hiding this comment

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

pylint<2.0.0

Copy link
Author

Choose a reason for hiding this comment

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

Oops, thanks

Copy link
Author

Choose a reason for hiding this comment

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

Oops, thanks

return newArgs;
}
return args;
}
private async isPathWritableAsync(directoryPath: string): Promise<boolean> {
const filePath = `${directoryPath}${path.sep}___vscpTest___`;
return new Promise<boolean>(resolve => {
Expand Down
20 changes: 11 additions & 9 deletions src/client/common/installer/pipEnvInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { inject, injectable } from 'inversify';
import { Uri } from 'vscode';
import { IInterpreterLocatorService, PIPENV_SERVICE } from '../../interpreter/contracts';
import { IServiceContainer } from '../../ioc/types';
import { ITerminalServiceFactory } from '../terminal/types';
import { ExecutionInfo } from '../types';
import { ModuleInstaller } from './moduleInstaller';
import { IModuleInstaller } from './types';

const pipenvName = 'pipenv';

@injectable()
export class PipEnvInstaller implements IModuleInstaller {
export class PipEnvInstaller extends ModuleInstaller implements IModuleInstaller {
private readonly pipenv: IInterpreterLocatorService;

public get displayName() {
Expand All @@ -21,17 +22,18 @@ export class PipEnvInstaller implements IModuleInstaller {
return 10;
}

constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer) {
constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) {
super(serviceContainer);
this.pipenv = this.serviceContainer.get<IInterpreterLocatorService>(IInterpreterLocatorService, PIPENV_SERVICE);
}

public installModule(name: string, resource?: Uri): Promise<void> {
const terminalService = this.serviceContainer.get<ITerminalServiceFactory>(ITerminalServiceFactory).getTerminalService(resource);
return terminalService.sendCommand(pipenvName, ['install', name, '--dev']);
}

public async isSupported(resource?: Uri): Promise<boolean> {
const interpreters = await this.pipenv.getInterpreters(resource);
return interpreters && interpreters.length > 0;
}
protected async getExecutionInfo(moduleName: string, resource?: Uri): Promise<ExecutionInfo> {
return {
args: ['install', moduleName, '--dev'],
execPath: pipenvName
};
}
}
1 change: 0 additions & 1 deletion src/client/common/installer/pipInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export class PipInstaller extends ModuleInstaller implements IModuleInstaller {
}
return {
args: [...proxyArgs, 'install', '-U', moduleName],
execPath: '',
moduleName: 'pip'
};
}
Expand Down