Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 23 additions & 5 deletions src/client/common/installer/moduleInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import * as path from 'path';
import * as vscode from 'vscode';
import { IInterpreterService, InterpreterType } from '../../interpreter/contracts';
import { IServiceContainer } from '../../ioc/types';
import { PythonSettings } from '../configSettings';
import { STANDARD_OUTPUT_CHANNEL } from '../constants';
import { noop } from '../core.utils';
import { ITerminalServiceFactory } from '../terminal/types';
import { ExecutionInfo, IOutputChannel } from '../types';
import { ExecutionInfo, IConfigurationService, IOutputChannel } from '../types';

@injectable()
export abstract class ModuleInstaller {
Expand All @@ -23,9 +22,12 @@ 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 configService = this.serviceContainer.get<IConfigurationService>(IConfigurationService);
const settings = configService.getSettings(resource);
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 UNIX.
newArgs[indexOfPylint] = '"pylint<2.0.0"';
return newArgs;
}
return args;
}
private async isPathWritableAsync(directoryPath: string): Promise<boolean> {
const filePath = `${directoryPath}${path.sep}___vscpTest___`;
return new Promise<boolean>(resolve => {
Expand Down
22 changes: 12 additions & 10 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';
export 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
};
}
}
7 changes: 4 additions & 3 deletions src/client/common/installer/pipInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// Licensed under the MIT License.

import { inject, injectable } from 'inversify';
import { Uri, workspace } from 'vscode';
import { Uri } from 'vscode';
import { IServiceContainer } from '../../ioc/types';
import { IWorkspaceService } from '../application/types';
import { IPythonExecutionFactory } from '../process/types';
import { ExecutionInfo } from '../types';
import { ModuleInstaller } from './moduleInstaller';
Expand All @@ -25,14 +26,14 @@ export class PipInstaller extends ModuleInstaller implements IModuleInstaller {
}
protected async getExecutionInfo(moduleName: string, resource?: Uri): Promise<ExecutionInfo> {
const proxyArgs: string[] = [];
const proxy = workspace.getConfiguration('http').get('proxy', '');
const workspaceService = this.serviceContainer.get<IWorkspaceService>(IWorkspaceService);
const proxy = workspaceService.getConfiguration('http').get('proxy', '');
if (proxy.length > 0) {
proxyArgs.push('--proxy');
proxyArgs.push(proxy);
}
return {
args: [...proxyArgs, 'install', '-U', moduleName],
execPath: '',
moduleName: 'pip'
};
}
Expand Down
78 changes: 0 additions & 78 deletions src/test/common/installer/moduleInstaller.test.ts

This file was deleted.

Loading