Skip to content

Commit f55dfb7

Browse files
author
Kartik Raj
authored
Remove all uses of discovery experiment helpers (#17783)
* Remove all uses of discovery experiment helpers * Fix tests for virtualenvprompt.unit.test.ts * Fix tests for progressdisplay.unit.test.ts * Fix tests for helper.unit.test.ts * Fix tests for activation.conda.unit.test.ts * Fix tests for pythonExecutionFactory.unit.test.ts * Fix tests for poetryInstaller.unit.test.ts * Fix tests for pipenvInstaller.unit.test.ts * Fix tests for condaInstaller.unit.test.ts * Fix tensorBoardSession.test.ts
1 parent 1f9e8e7 commit f55dfb7

30 files changed

+157
-740
lines changed

src/client/common/experiments/helpers.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/client/common/installer/condaInstaller.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
// Licensed under the MIT License.
44

55
import { inject, injectable } from 'inversify';
6-
import { ICondaService, ICondaLocatorService, IComponentAdapter } from '../../interpreter/contracts';
6+
import { ICondaService, IComponentAdapter } from '../../interpreter/contracts';
77
import { IServiceContainer } from '../../ioc/types';
88
import { ModuleInstallerType } from '../../pythonEnvironments/info';
9-
import { inDiscoveryExperiment } from '../experiments/helpers';
10-
import { ExecutionInfo, IConfigurationService, IExperimentService, Product } from '../types';
9+
import { ExecutionInfo, IConfigurationService, Product } from '../types';
1110
import { isResource } from '../utils/misc';
1211
import { ModuleInstaller, translateProductToModule } from './moduleInstaller';
1312
import { InterpreterUri, ModuleInstallFlags } from './types';
@@ -77,10 +76,7 @@ export class CondaInstaller extends ModuleInstaller {
7776
const pythonPath = isResource(resource)
7877
? this.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(resource).pythonPath
7978
: resource.path;
80-
const experimentService = this.serviceContainer.get<IExperimentService>(IExperimentService);
81-
const condaLocatorService = (await inDiscoveryExperiment(experimentService))
82-
? this.serviceContainer.get<IComponentAdapter>(IComponentAdapter)
83-
: this.serviceContainer.get<ICondaLocatorService>(ICondaLocatorService);
79+
const condaLocatorService = this.serviceContainer.get<IComponentAdapter>(IComponentAdapter);
8480
const info = await condaLocatorService.getCondaEnvironment(pythonPath);
8581
const args = [flags & ModuleInstallFlags.upgrade ? 'update' : 'install'];
8682

@@ -128,10 +124,7 @@ export class CondaInstaller extends ModuleInstaller {
128124
* Is the provided interprter a conda environment
129125
*/
130126
private async isCurrentEnvironmentACondaEnvironment(resource?: InterpreterUri): Promise<boolean> {
131-
const experimentService = this.serviceContainer.get<IExperimentService>(IExperimentService);
132-
const condaService = (await inDiscoveryExperiment(experimentService))
133-
? this.serviceContainer.get<IComponentAdapter>(IComponentAdapter)
134-
: this.serviceContainer.get<ICondaLocatorService>(ICondaLocatorService);
127+
const condaService = this.serviceContainer.get<IComponentAdapter>(IComponentAdapter);
135128
const pythonPath = isResource(resource)
136129
? this.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(resource).pythonPath
137130
: resource.path;

src/client/common/installer/pipEnvInstaller.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
// Licensed under the MIT License.
33

44
import { inject, injectable } from 'inversify';
5-
import { IInterpreterLocatorService, IInterpreterService, PIPENV_SERVICE } from '../../interpreter/contracts';
5+
import { IInterpreterService } from '../../interpreter/contracts';
66
import { IServiceContainer } from '../../ioc/types';
77
import { isPipenvEnvironmentRelatedToFolder } from '../../pythonEnvironments/common/environmentManagers/pipenv';
88
import { EnvironmentType, ModuleInstallerType } from '../../pythonEnvironments/info';
99
import { IWorkspaceService } from '../application/types';
10-
import { inDiscoveryExperiment } from '../experiments/helpers';
11-
import { ExecutionInfo, IExperimentService } from '../types';
10+
import { ExecutionInfo } from '../types';
1211
import { isResource } from '../utils/misc';
1312
import { ModuleInstaller } from './moduleInstaller';
1413
import { InterpreterUri, ModuleInstallFlags } from './types';
@@ -37,27 +36,17 @@ export class PipEnvInstaller extends ModuleInstaller {
3736
}
3837
public async isSupported(resource?: InterpreterUri): Promise<boolean> {
3938
if (isResource(resource)) {
40-
const experimentService = this.serviceContainer.get<IExperimentService>(IExperimentService);
41-
if (await inDiscoveryExperiment(experimentService)) {
42-
const interpreter = await this.serviceContainer
43-
.get<IInterpreterService>(IInterpreterService)
44-
.getActiveInterpreter(resource);
45-
const workspaceFolder = resource
46-
? this.serviceContainer.get<IWorkspaceService>(IWorkspaceService).getWorkspaceFolder(resource)
47-
: undefined;
48-
if (!interpreter || !workspaceFolder || interpreter.envType !== EnvironmentType.Pipenv) {
49-
return false;
50-
}
51-
// Install using `pipenv install` only if the active environment is related to the current folder.
52-
return isPipenvEnvironmentRelatedToFolder(interpreter.path, workspaceFolder.uri.fsPath);
53-
} else {
54-
const pipenvs = this.serviceContainer.get<IInterpreterLocatorService>(
55-
IInterpreterLocatorService,
56-
PIPENV_SERVICE,
57-
);
58-
const interpreters = await pipenvs.getInterpreters(resource);
59-
return interpreters.length > 0;
39+
const interpreter = await this.serviceContainer
40+
.get<IInterpreterService>(IInterpreterService)
41+
.getActiveInterpreter(resource);
42+
const workspaceFolder = resource
43+
? this.serviceContainer.get<IWorkspaceService>(IWorkspaceService).getWorkspaceFolder(resource)
44+
: undefined;
45+
if (!interpreter || !workspaceFolder || interpreter.envType !== EnvironmentType.Pipenv) {
46+
return false;
6047
}
48+
// Install using `pipenv install` only if the active environment is related to the current folder.
49+
return isPipenvEnvironmentRelatedToFolder(interpreter.path, workspaceFolder.uri.fsPath);
6150
} else {
6251
return resource.envType === EnvironmentType.Pipenv;
6352
}

src/client/common/installer/poetryInstaller.ts

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,17 @@
44
'use strict';
55

66
import { inject, injectable } from 'inversify';
7-
import * as path from 'path';
8-
import { Uri } from 'vscode';
97
import { IInterpreterService } from '../../interpreter/contracts';
108
import { IServiceContainer } from '../../ioc/types';
119
import { isPoetryEnvironmentRelatedToFolder } from '../../pythonEnvironments/common/environmentManagers/poetry';
1210
import { EnvironmentType, ModuleInstallerType } from '../../pythonEnvironments/info';
1311
import { IWorkspaceService } from '../application/types';
14-
import { inDiscoveryExperiment } from '../experiments/helpers';
15-
import { traceError } from '../logger';
16-
import { IFileSystem } from '../platform/types';
17-
import { IProcessServiceFactory } from '../process/types';
18-
import { ExecutionInfo, IConfigurationService, IExperimentService } from '../types';
12+
import { ExecutionInfo, IConfigurationService } from '../types';
1913
import { isResource } from '../utils/misc';
2014
import { ModuleInstaller } from './moduleInstaller';
2115
import { InterpreterUri } from './types';
2216

2317
export const poetryName = 'poetry';
24-
const poetryFile = 'poetry.lock';
2518

2619
@injectable()
2720
export class PoetryInstaller extends ModuleInstaller {
@@ -49,8 +42,6 @@ export class PoetryInstaller extends ModuleInstaller {
4942
@inject(IServiceContainer) serviceContainer: IServiceContainer,
5043
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService,
5144
@inject(IConfigurationService) private readonly configurationService: IConfigurationService,
52-
@inject(IFileSystem) private readonly fs: IFileSystem,
53-
@inject(IProcessServiceFactory) private readonly processFactory: IProcessServiceFactory,
5445
) {
5546
super(serviceContainer);
5647
}
@@ -59,45 +50,22 @@ export class PoetryInstaller extends ModuleInstaller {
5950
if (!resource) {
6051
return false;
6152
}
62-
const experimentService = this.serviceContainer.get<IExperimentService>(IExperimentService);
63-
if (await inDiscoveryExperiment(experimentService)) {
64-
if (!isResource(resource)) {
65-
return false;
66-
}
67-
const interpreter = await this.serviceContainer
68-
.get<IInterpreterService>(IInterpreterService)
69-
.getActiveInterpreter(resource);
70-
const workspaceFolder = resource ? this.workspaceService.getWorkspaceFolder(resource) : undefined;
71-
if (!interpreter || !workspaceFolder || interpreter.envType !== EnvironmentType.Poetry) {
72-
return false;
73-
}
74-
// Install using poetry CLI only if the active poetry environment is related to the current folder.
75-
return isPoetryEnvironmentRelatedToFolder(
76-
interpreter.path,
77-
workspaceFolder.uri.fsPath,
78-
this.configurationService.getSettings(resource).poetryPath,
79-
);
80-
}
81-
const workspaceFolder = this.workspaceService.getWorkspaceFolder(isResource(resource) ? resource : undefined);
82-
if (!workspaceFolder) {
83-
return false;
84-
}
85-
if (!(await this.fs.fileExists(path.join(workspaceFolder.uri.fsPath, poetryFile)))) {
53+
if (!isResource(resource)) {
8654
return false;
8755
}
88-
return this.isPoetryAvailable(workspaceFolder.uri);
89-
}
90-
91-
protected async isPoetryAvailable(workfolder: Uri): Promise<boolean> {
92-
try {
93-
const processService = await this.processFactory.create(workfolder);
94-
const execPath = this.configurationService.getSettings(workfolder).poetryPath;
95-
const result = await processService.shellExec(`${execPath} env list`, { cwd: workfolder.fsPath });
96-
return result && (result.stderr || '').trim().length === 0;
97-
} catch (error) {
98-
traceError(`${poetryFile} exists but Poetry not found`, error);
56+
const interpreter = await this.serviceContainer
57+
.get<IInterpreterService>(IInterpreterService)
58+
.getActiveInterpreter(resource);
59+
const workspaceFolder = resource ? this.workspaceService.getWorkspaceFolder(resource) : undefined;
60+
if (!interpreter || !workspaceFolder || interpreter.envType !== EnvironmentType.Poetry) {
9961
return false;
10062
}
63+
// Install using poetry CLI only if the active poetry environment is related to the current folder.
64+
return isPoetryEnvironmentRelatedToFolder(
65+
interpreter.path,
66+
workspaceFolder.uri.fsPath,
67+
this.configurationService.getSettings(resource).poetryPath,
68+
);
10169
}
10270

10371
protected async getExecutionInfo(moduleName: string, resource?: InterpreterUri): Promise<ExecutionInfo> {

src/client/common/process/pythonExecutionFactory.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ import { gte } from 'semver';
55

66
import { Uri } from 'vscode';
77
import { IEnvironmentActivationService } from '../../interpreter/activation/types';
8-
import { IComponentAdapter, ICondaLocatorService, ICondaService } from '../../interpreter/contracts';
8+
import { IComponentAdapter, ICondaService } from '../../interpreter/contracts';
99
import { IServiceContainer } from '../../ioc/types';
1010
import { CondaEnvironmentInfo } from '../../pythonEnvironments/common/environmentManagers/conda';
11-
import { inDiscoveryExperiment } from '../experiments/helpers';
1211
import { sendTelemetryEvent } from '../../telemetry';
1312
import { EventName } from '../../telemetry/constants';
1413
import { IFileSystem } from '../platform/types';
15-
import { IConfigurationService, IDisposableRegistry, IExperimentService, IInterpreterPathProxyService } from '../types';
14+
import { IConfigurationService, IDisposableRegistry, IInterpreterPathProxyService } from '../types';
1615
import { ProcessService } from './proc';
1716
import { createCondaEnv, createPythonEnv, createWindowsStoreEnv } from './pythonEnvironment';
1817
import { createPythonProcessService } from './pythonProcess';
@@ -26,7 +25,6 @@ import {
2625
IPythonExecutionFactory,
2726
IPythonExecutionService,
2827
} from './types';
29-
import { isWindowsStoreInterpreter } from '../../pythonEnvironments/discovery/locators/services/windowsStoreInterpreter';
3028
import { IInterpreterAutoSelectionService } from '../../interpreter/autoSelection/types';
3129
import { sleep } from '../utils/async';
3230
import { traceError } from '../logger';
@@ -50,7 +48,6 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {
5048
@inject(ICondaService) private readonly condaService: ICondaService,
5149
@inject(IBufferDecoder) private readonly decoder: IBufferDecoder,
5250
@inject(IComponentAdapter) private readonly pyenvs: IComponentAdapter,
53-
@inject(IExperimentService) private readonly experimentService: IExperimentService,
5451
@inject(IInterpreterAutoSelectionService) private readonly autoSelection: IInterpreterAutoSelectionService,
5552
@inject(IInterpreterPathProxyService) private readonly interpreterPathExpHelper: IInterpreterPathProxyService,
5653
) {
@@ -86,10 +83,7 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {
8683
}
8784
const processService: IProcessService = await this.processServiceFactory.create(options.resource);
8885

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

9488
return createPythonService(
9589
pythonPath,
@@ -136,9 +130,7 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {
136130
const processServicePromise = processService
137131
? Promise.resolve(processService)
138132
: this.processServiceFactory.create(resource);
139-
const condaLocatorService = (await inDiscoveryExperiment(this.experimentService))
140-
? this.serviceContainer.get<IComponentAdapter>(IComponentAdapter)
141-
: this.serviceContainer.get<ICondaLocatorService>(ICondaLocatorService);
133+
const condaLocatorService = this.serviceContainer.get<IComponentAdapter>(IComponentAdapter);
142134
const [condaVersion, condaEnvironment, condaFile, procService] = await Promise.all([
143135
this.condaService.getCondaVersion(),
144136
condaLocatorService.getCondaEnvironment(pythonPath),

src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ import { inject, injectable } from 'inversify';
99
import * as path from 'path';
1010
import { Uri } from 'vscode';
1111

12-
import { IComponentAdapter, ICondaLocatorService, ICondaService } from '../../../interpreter/contracts';
12+
import { IComponentAdapter, ICondaService } from '../../../interpreter/contracts';
1313
import { IPlatformService } from '../../platform/types';
14-
import { IConfigurationService, IExperimentService } from '../../types';
14+
import { IConfigurationService } from '../../types';
1515
import { ITerminalActivationCommandProvider, TerminalShellType } from '../types';
16-
import { IServiceContainer } from '../../../ioc/types';
17-
import { inDiscoveryExperiment } from '../../experiments/helpers';
1816

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

@@ -62,10 +58,7 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman
6258
pythonPath: string,
6359
targetShell: TerminalShellType,
6460
): Promise<string[] | undefined> {
65-
const condaLocatorService = (await inDiscoveryExperiment(this.experimentService))
66-
? this.pyenvs
67-
: this.serviceContainer.get<ICondaLocatorService>(ICondaLocatorService);
68-
const envInfo = await condaLocatorService.getCondaEnvironment(pythonPath);
61+
const envInfo = await this.pyenvs.getCondaEnvironment(pythonPath);
6962
if (!envInfo) {
7063
return undefined;
7164
}

src/client/common/terminal/environmentActivationProviders/pipEnvActivationProvider.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import { IInterpreterService } from '../../../interpreter/contracts';
1010
import { isPipenvEnvironmentRelatedToFolder } from '../../../pythonEnvironments/common/environmentManagers/pipenv';
1111
import { EnvironmentType } from '../../../pythonEnvironments/info';
1212
import { IWorkspaceService } from '../../application/types';
13-
import { inDiscoveryExperiment } from '../../experiments/helpers';
14-
import { IFileSystem } from '../../platform/types';
15-
import { IExperimentService, IToolExecutionPath, ToolExecutionPath } from '../../types';
13+
import { IToolExecutionPath, ToolExecutionPath } from '../../types';
1614
import { ITerminalActivationCommandProvider } from '../types';
1715

1816
@injectable()
@@ -23,8 +21,6 @@ export class PipEnvActivationCommandProvider implements ITerminalActivationComma
2321
@named(ToolExecutionPath.pipenv)
2422
private readonly pipEnvExecution: IToolExecutionPath,
2523
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService,
26-
@inject(IFileSystem) private readonly fs: IFileSystem,
27-
@inject(IExperimentService) private readonly experimentService: IExperimentService,
2824
) {}
2925

3026
// eslint-disable-next-line class-methods-use-this
@@ -40,14 +36,7 @@ export class PipEnvActivationCommandProvider implements ITerminalActivationComma
4036
// Activate using `pipenv shell` only if the current folder relates pipenv environment.
4137
const workspaceFolder = resource ? this.workspaceService.getWorkspaceFolder(resource) : undefined;
4238
if (workspaceFolder) {
43-
if (await inDiscoveryExperiment(this.experimentService)) {
44-
if (!(await isPipenvEnvironmentRelatedToFolder(interpreter.path, workspaceFolder?.uri.fsPath))) {
45-
return undefined;
46-
}
47-
} else if (
48-
interpreter.pipEnvWorkspaceFolder &&
49-
!this.fs.arePathsSame(workspaceFolder.uri.fsPath, interpreter.pipEnvWorkspaceFolder)
50-
) {
39+
if (!(await isPipenvEnvironmentRelatedToFolder(interpreter.path, workspaceFolder?.uri.fsPath))) {
5140
return undefined;
5241
}
5342
}

0 commit comments

Comments
 (0)