Skip to content

Remove all uses of discovery experiment helpers #17783

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 10 commits into from
Oct 19, 2021
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
22 changes: 0 additions & 22 deletions src/client/common/experiments/helpers.ts

This file was deleted.

15 changes: 4 additions & 11 deletions src/client/common/installer/condaInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
// Licensed under the MIT License.

import { inject, injectable } from 'inversify';
import { ICondaService, ICondaLocatorService, IComponentAdapter } from '../../interpreter/contracts';
import { ICondaService, IComponentAdapter } from '../../interpreter/contracts';
import { IServiceContainer } from '../../ioc/types';
import { ModuleInstallerType } from '../../pythonEnvironments/info';
import { inDiscoveryExperiment } from '../experiments/helpers';
import { ExecutionInfo, IConfigurationService, IExperimentService, Product } from '../types';
import { ExecutionInfo, IConfigurationService, Product } from '../types';
import { isResource } from '../utils/misc';
import { ModuleInstaller, translateProductToModule } from './moduleInstaller';
import { InterpreterUri, ModuleInstallFlags } from './types';
Expand Down Expand Up @@ -77,10 +76,7 @@ export class CondaInstaller extends ModuleInstaller {
const pythonPath = isResource(resource)
? this.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(resource).pythonPath
: resource.path;
const experimentService = this.serviceContainer.get<IExperimentService>(IExperimentService);
const condaLocatorService = (await inDiscoveryExperiment(experimentService))
? this.serviceContainer.get<IComponentAdapter>(IComponentAdapter)
: this.serviceContainer.get<ICondaLocatorService>(ICondaLocatorService);
const condaLocatorService = this.serviceContainer.get<IComponentAdapter>(IComponentAdapter);
const info = await condaLocatorService.getCondaEnvironment(pythonPath);
const args = [flags & ModuleInstallFlags.upgrade ? 'update' : 'install'];

Expand Down Expand Up @@ -128,10 +124,7 @@ export class CondaInstaller extends ModuleInstaller {
* Is the provided interprter a conda environment
*/
private async isCurrentEnvironmentACondaEnvironment(resource?: InterpreterUri): Promise<boolean> {
const experimentService = this.serviceContainer.get<IExperimentService>(IExperimentService);
const condaService = (await inDiscoveryExperiment(experimentService))
? this.serviceContainer.get<IComponentAdapter>(IComponentAdapter)
: this.serviceContainer.get<ICondaLocatorService>(ICondaLocatorService);
const condaService = this.serviceContainer.get<IComponentAdapter>(IComponentAdapter);
const pythonPath = isResource(resource)
? this.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(resource).pythonPath
: resource.path;
Expand Down
35 changes: 12 additions & 23 deletions src/client/common/installer/pipEnvInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
// Licensed under the MIT License.

import { inject, injectable } from 'inversify';
import { IInterpreterLocatorService, IInterpreterService, PIPENV_SERVICE } from '../../interpreter/contracts';
import { IInterpreterService } from '../../interpreter/contracts';
import { IServiceContainer } from '../../ioc/types';
import { isPipenvEnvironmentRelatedToFolder } from '../../pythonEnvironments/common/environmentManagers/pipenv';
import { EnvironmentType, ModuleInstallerType } from '../../pythonEnvironments/info';
import { IWorkspaceService } from '../application/types';
import { inDiscoveryExperiment } from '../experiments/helpers';
import { ExecutionInfo, IExperimentService } from '../types';
import { ExecutionInfo } from '../types';
import { isResource } from '../utils/misc';
import { ModuleInstaller } from './moduleInstaller';
import { InterpreterUri, ModuleInstallFlags } from './types';
Expand Down Expand Up @@ -37,27 +36,17 @@ export class PipEnvInstaller extends ModuleInstaller {
}
public async isSupported(resource?: InterpreterUri): Promise<boolean> {
if (isResource(resource)) {
const experimentService = this.serviceContainer.get<IExperimentService>(IExperimentService);
if (await inDiscoveryExperiment(experimentService)) {
const interpreter = await this.serviceContainer
.get<IInterpreterService>(IInterpreterService)
.getActiveInterpreter(resource);
const workspaceFolder = resource
? this.serviceContainer.get<IWorkspaceService>(IWorkspaceService).getWorkspaceFolder(resource)
: undefined;
if (!interpreter || !workspaceFolder || interpreter.envType !== EnvironmentType.Pipenv) {
return false;
}
// Install using `pipenv install` only if the active environment is related to the current folder.
return isPipenvEnvironmentRelatedToFolder(interpreter.path, workspaceFolder.uri.fsPath);
} else {
const pipenvs = this.serviceContainer.get<IInterpreterLocatorService>(
IInterpreterLocatorService,
PIPENV_SERVICE,
);
const interpreters = await pipenvs.getInterpreters(resource);
return interpreters.length > 0;
const interpreter = await this.serviceContainer
.get<IInterpreterService>(IInterpreterService)
.getActiveInterpreter(resource);
const workspaceFolder = resource
? this.serviceContainer.get<IWorkspaceService>(IWorkspaceService).getWorkspaceFolder(resource)
: undefined;
if (!interpreter || !workspaceFolder || interpreter.envType !== EnvironmentType.Pipenv) {
return false;
}
// Install using `pipenv install` only if the active environment is related to the current folder.
return isPipenvEnvironmentRelatedToFolder(interpreter.path, workspaceFolder.uri.fsPath);
} else {
return resource.envType === EnvironmentType.Pipenv;
}
Expand Down
58 changes: 13 additions & 45 deletions src/client/common/installer/poetryInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,17 @@
'use strict';

import { inject, injectable } from 'inversify';
import * as path from 'path';
import { Uri } from 'vscode';
import { IInterpreterService } from '../../interpreter/contracts';
import { IServiceContainer } from '../../ioc/types';
import { isPoetryEnvironmentRelatedToFolder } from '../../pythonEnvironments/common/environmentManagers/poetry';
import { EnvironmentType, ModuleInstallerType } from '../../pythonEnvironments/info';
import { IWorkspaceService } from '../application/types';
import { inDiscoveryExperiment } from '../experiments/helpers';
import { traceError } from '../logger';
import { IFileSystem } from '../platform/types';
import { IProcessServiceFactory } from '../process/types';
import { ExecutionInfo, IConfigurationService, IExperimentService } from '../types';
import { ExecutionInfo, IConfigurationService } from '../types';
import { isResource } from '../utils/misc';
import { ModuleInstaller } from './moduleInstaller';
import { InterpreterUri } from './types';

export const poetryName = 'poetry';
const poetryFile = 'poetry.lock';

@injectable()
export class PoetryInstaller extends ModuleInstaller {
Expand Down Expand Up @@ -49,8 +42,6 @@ export class PoetryInstaller extends ModuleInstaller {
@inject(IServiceContainer) serviceContainer: IServiceContainer,
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService,
@inject(IConfigurationService) private readonly configurationService: IConfigurationService,
@inject(IFileSystem) private readonly fs: IFileSystem,
@inject(IProcessServiceFactory) private readonly processFactory: IProcessServiceFactory,
) {
super(serviceContainer);
}
Expand All @@ -59,45 +50,22 @@ export class PoetryInstaller extends ModuleInstaller {
if (!resource) {
return false;
}
const experimentService = this.serviceContainer.get<IExperimentService>(IExperimentService);
if (await inDiscoveryExperiment(experimentService)) {
if (!isResource(resource)) {
return false;
}
const interpreter = await this.serviceContainer
.get<IInterpreterService>(IInterpreterService)
.getActiveInterpreter(resource);
const workspaceFolder = resource ? this.workspaceService.getWorkspaceFolder(resource) : undefined;
if (!interpreter || !workspaceFolder || interpreter.envType !== EnvironmentType.Poetry) {
return false;
}
// Install using poetry CLI only if the active poetry environment is related to the current folder.
return isPoetryEnvironmentRelatedToFolder(
interpreter.path,
workspaceFolder.uri.fsPath,
this.configurationService.getSettings(resource).poetryPath,
);
}
const workspaceFolder = this.workspaceService.getWorkspaceFolder(isResource(resource) ? resource : undefined);
if (!workspaceFolder) {
return false;
}
if (!(await this.fs.fileExists(path.join(workspaceFolder.uri.fsPath, poetryFile)))) {
if (!isResource(resource)) {
return false;
}
return this.isPoetryAvailable(workspaceFolder.uri);
}

protected async isPoetryAvailable(workfolder: Uri): Promise<boolean> {
try {
const processService = await this.processFactory.create(workfolder);
const execPath = this.configurationService.getSettings(workfolder).poetryPath;
const result = await processService.shellExec(`${execPath} env list`, { cwd: workfolder.fsPath });
return result && (result.stderr || '').trim().length === 0;
} catch (error) {
traceError(`${poetryFile} exists but Poetry not found`, error);
const interpreter = await this.serviceContainer
.get<IInterpreterService>(IInterpreterService)
.getActiveInterpreter(resource);
const workspaceFolder = resource ? this.workspaceService.getWorkspaceFolder(resource) : undefined;
if (!interpreter || !workspaceFolder || interpreter.envType !== EnvironmentType.Poetry) {
return false;
}
// Install using poetry CLI only if the active poetry environment is related to the current folder.
return isPoetryEnvironmentRelatedToFolder(
interpreter.path,
workspaceFolder.uri.fsPath,
this.configurationService.getSettings(resource).poetryPath,
);
}

protected async getExecutionInfo(moduleName: string, resource?: InterpreterUri): Promise<ExecutionInfo> {
Expand Down
16 changes: 4 additions & 12 deletions src/client/common/process/pythonExecutionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import { gte } from 'semver';

import { Uri } from 'vscode';
import { IEnvironmentActivationService } from '../../interpreter/activation/types';
import { IComponentAdapter, ICondaLocatorService, ICondaService } from '../../interpreter/contracts';
import { IComponentAdapter, ICondaService } from '../../interpreter/contracts';
import { IServiceContainer } from '../../ioc/types';
import { CondaEnvironmentInfo } from '../../pythonEnvironments/common/environmentManagers/conda';
import { inDiscoveryExperiment } from '../experiments/helpers';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
import { IFileSystem } from '../platform/types';
import { IConfigurationService, IDisposableRegistry, IExperimentService, IInterpreterPathProxyService } from '../types';
import { IConfigurationService, IDisposableRegistry, IInterpreterPathProxyService } from '../types';
import { ProcessService } from './proc';
import { createCondaEnv, createPythonEnv, createWindowsStoreEnv } from './pythonEnvironment';
import { createPythonProcessService } from './pythonProcess';
Expand All @@ -26,7 +25,6 @@ import {
IPythonExecutionFactory,
IPythonExecutionService,
} from './types';
import { isWindowsStoreInterpreter } from '../../pythonEnvironments/discovery/locators/services/windowsStoreInterpreter';
import { IInterpreterAutoSelectionService } from '../../interpreter/autoSelection/types';
import { sleep } from '../utils/async';
import { traceError } from '../logger';
Expand All @@ -50,7 +48,6 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {
@inject(ICondaService) private readonly condaService: ICondaService,
@inject(IBufferDecoder) private readonly decoder: IBufferDecoder,
@inject(IComponentAdapter) private readonly pyenvs: IComponentAdapter,
@inject(IExperimentService) private readonly experimentService: IExperimentService,
@inject(IInterpreterAutoSelectionService) private readonly autoSelection: IInterpreterAutoSelectionService,
@inject(IInterpreterPathProxyService) private readonly interpreterPathExpHelper: IInterpreterPathProxyService,
) {
Expand Down Expand Up @@ -86,10 +83,7 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {
}
const processService: IProcessService = await this.processServiceFactory.create(options.resource);

const windowsStoreInterpreterCheck = (await inDiscoveryExperiment(this.experimentService))
? // Class methods may depend on other properties which belong to the class, so bind the correct context.
this.pyenvs.isWindowsStoreInterpreter.bind(this.pyenvs)
: isWindowsStoreInterpreter;
const windowsStoreInterpreterCheck = this.pyenvs.isWindowsStoreInterpreter.bind(this.pyenvs);

return createPythonService(
pythonPath,
Expand Down Expand Up @@ -136,9 +130,7 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {
const processServicePromise = processService
? Promise.resolve(processService)
: this.processServiceFactory.create(resource);
const condaLocatorService = (await inDiscoveryExperiment(this.experimentService))
? this.serviceContainer.get<IComponentAdapter>(IComponentAdapter)
: this.serviceContainer.get<ICondaLocatorService>(ICondaLocatorService);
const condaLocatorService = this.serviceContainer.get<IComponentAdapter>(IComponentAdapter);
const [condaVersion, condaEnvironment, condaFile, procService] = await Promise.all([
this.condaService.getCondaVersion(),
condaLocatorService.getCondaEnvironment(pythonPath),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import { inject, injectable } from 'inversify';
import * as path from 'path';
import { Uri } from 'vscode';

import { IComponentAdapter, ICondaLocatorService, ICondaService } from '../../../interpreter/contracts';
import { IComponentAdapter, ICondaService } from '../../../interpreter/contracts';
import { IPlatformService } from '../../platform/types';
import { IConfigurationService, IExperimentService } from '../../types';
import { IConfigurationService } from '../../types';
import { ITerminalActivationCommandProvider, TerminalShellType } from '../types';
import { IServiceContainer } from '../../../ioc/types';
import { inDiscoveryExperiment } from '../../experiments/helpers';

// Version number of conda that requires we call activate with 'conda activate' instead of just 'activate'
const CondaRequiredMajor = 4;
Expand All @@ -30,8 +28,6 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman
@inject(ICondaService) private readonly condaService: ICondaService,
@inject(IPlatformService) private platform: IPlatformService,
@inject(IConfigurationService) private configService: IConfigurationService,
@inject(IServiceContainer) private serviceContainer: IServiceContainer,
@inject(IExperimentService) private experimentService: IExperimentService,
@inject(IComponentAdapter) private pyenvs: IComponentAdapter,
) {}

Expand Down Expand Up @@ -62,10 +58,7 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman
pythonPath: string,
targetShell: TerminalShellType,
): Promise<string[] | undefined> {
const condaLocatorService = (await inDiscoveryExperiment(this.experimentService))
? this.pyenvs
: this.serviceContainer.get<ICondaLocatorService>(ICondaLocatorService);
const envInfo = await condaLocatorService.getCondaEnvironment(pythonPath);
const envInfo = await this.pyenvs.getCondaEnvironment(pythonPath);
if (!envInfo) {
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import { IInterpreterService } from '../../../interpreter/contracts';
import { isPipenvEnvironmentRelatedToFolder } from '../../../pythonEnvironments/common/environmentManagers/pipenv';
import { EnvironmentType } from '../../../pythonEnvironments/info';
import { IWorkspaceService } from '../../application/types';
import { inDiscoveryExperiment } from '../../experiments/helpers';
import { IFileSystem } from '../../platform/types';
import { IExperimentService, IToolExecutionPath, ToolExecutionPath } from '../../types';
import { IToolExecutionPath, ToolExecutionPath } from '../../types';
import { ITerminalActivationCommandProvider } from '../types';

@injectable()
Expand All @@ -23,8 +21,6 @@ export class PipEnvActivationCommandProvider implements ITerminalActivationComma
@named(ToolExecutionPath.pipenv)
private readonly pipEnvExecution: IToolExecutionPath,
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService,
@inject(IFileSystem) private readonly fs: IFileSystem,
@inject(IExperimentService) private readonly experimentService: IExperimentService,
) {}

// eslint-disable-next-line class-methods-use-this
Expand All @@ -40,14 +36,7 @@ export class PipEnvActivationCommandProvider implements ITerminalActivationComma
// Activate using `pipenv shell` only if the current folder relates pipenv environment.
const workspaceFolder = resource ? this.workspaceService.getWorkspaceFolder(resource) : undefined;
if (workspaceFolder) {
if (await inDiscoveryExperiment(this.experimentService)) {
if (!(await isPipenvEnvironmentRelatedToFolder(interpreter.path, workspaceFolder?.uri.fsPath))) {
return undefined;
}
} else if (
interpreter.pipEnvWorkspaceFolder &&
!this.fs.arePathsSame(workspaceFolder.uri.fsPath, interpreter.pipEnvWorkspaceFolder)
) {
if (!(await isPipenvEnvironmentRelatedToFolder(interpreter.path, workspaceFolder?.uri.fsPath))) {
return undefined;
}
}
Expand Down
Loading