Skip to content

Commit 7c7f320

Browse files
author
Kartik Raj
authored
Factor old conda locator out of conda service (microsoft#15276)
* Separate deprecated conda service from the original * Move isCondaEnvironment from CondaService to CondaServiceDeprecated * Rename * Use getEnvironment from CondaLocatorService instead * Delete things which are no longer needed * Move isCondaAvailable from old locator to service * Remove getCondaVersion from old locator * Delete stale unit tests * Register CondaLocatorService if in experiment, for now
1 parent 35f3aaf commit 7c7f320

21 files changed

Lines changed: 1655 additions & 1324 deletions

src/client/common/installer/condaInstaller.ts

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

44
import { inject, injectable } from 'inversify';
5-
import { ICondaService } from '../../interpreter/contracts';
5+
import { ICondaService, ICondaLocatorService } from '../../interpreter/contracts';
66
import { IServiceContainer } from '../../ioc/types';
77
import { ExecutionInfo, IConfigurationService } from '../types';
88
import { isResource } from '../utils/misc';
@@ -67,7 +67,8 @@ export class CondaInstaller extends ModuleInstaller {
6767
const pythonPath = isResource(resource)
6868
? this.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(resource).pythonPath
6969
: resource.path;
70-
const info = await condaService.getCondaEnvironment(pythonPath);
70+
const condaLocatorService = this.serviceContainer.get<ICondaLocatorService>(ICondaLocatorService);
71+
const info = await condaLocatorService.getCondaEnvironment(pythonPath);
7172
const args = [isUpgrade ? 'update' : 'install'];
7273

7374
// Temporarily ensure tensorboard is installed from the conda-forge
@@ -96,7 +97,7 @@ export class CondaInstaller extends ModuleInstaller {
9697
* Is the provided interprter a conda environment
9798
*/
9899
private async isCurrentEnvironmentACondaEnvironment(resource?: InterpreterUri): Promise<boolean> {
99-
const condaService = this.serviceContainer.get<ICondaService>(ICondaService);
100+
const condaService = this.serviceContainer.get<ICondaLocatorService>(ICondaLocatorService);
100101
const pythonPath = isResource(resource)
101102
? this.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(resource).pythonPath
102103
: resource.path;

src/client/common/process/pythonExecutionFactory.ts

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

66
import { Uri } from 'vscode';
77
import { IEnvironmentActivationService } from '../../interpreter/activation/types';
8-
import { IComponentAdapter, ICondaService } from '../../interpreter/contracts';
8+
import { IComponentAdapter, ICondaLocatorService, ICondaService } from '../../interpreter/contracts';
99
import { IServiceContainer } from '../../ioc/types';
1010
import { CondaEnvironmentInfo } from '../../pythonEnvironments/discovery/locators/services/conda';
1111
import { inDiscoveryExperiment } from '../experiments/helpers';
@@ -114,7 +114,7 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {
114114
: this.processServiceFactory.create(resource);
115115
const [condaVersion, condaEnvironment, condaFile, procService] = await Promise.all([
116116
this.condaService.getCondaVersion(),
117-
this.condaService.getCondaEnvironment(pythonPath),
117+
this.serviceContainer.get<ICondaLocatorService>(ICondaLocatorService).getCondaEnvironment(pythonPath),
118118
this.condaService.getCondaFile(),
119119
processServicePromise,
120120
]);

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import { inject, injectable } from 'inversify';
77
import * as path from 'path';
88
import { Uri } from 'vscode';
99

10-
import { ICondaService } from '../../../interpreter/contracts';
10+
import { ICondaLocatorService, ICondaService } from '../../../interpreter/contracts';
1111
import { IPlatformService } from '../../platform/types';
1212
import { IConfigurationService } from '../../types';
1313
import { ITerminalActivationCommandProvider, TerminalShellType } from '../types';
14+
import { IServiceContainer } from '../../../ioc/types';
1415

1516
// Version number of conda that requires we call activate with 'conda activate' instead of just 'activate'
1617
const CondaRequiredMajor = 4;
@@ -26,6 +27,7 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman
2627
@inject(ICondaService) private readonly condaService: ICondaService,
2728
@inject(IPlatformService) private platform: IPlatformService,
2829
@inject(IConfigurationService) private configService: IConfigurationService,
30+
@inject(IServiceContainer) private serviceContainer: IServiceContainer,
2931
) {}
3032

3133
/**
@@ -54,7 +56,8 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman
5456
pythonPath: string,
5557
targetShell: TerminalShellType,
5658
): Promise<string[] | undefined> {
57-
const envInfo = await this.condaService.getCondaEnvironment(pythonPath);
59+
const condaLocatorService = this.serviceContainer.get<ICondaLocatorService>(ICondaLocatorService);
60+
const envInfo = await condaLocatorService.getCondaEnvironment(pythonPath);
5861
if (!envInfo) {
5962
return;
6063
}

src/client/common/terminal/helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { inject, injectable, multiInject, named } from 'inversify';
55
import { Terminal, Uri } from 'vscode';
6-
import { ICondaService, IInterpreterService } from '../../interpreter/contracts';
6+
import { ICondaLocatorService, IInterpreterService } from '../../interpreter/contracts';
77
import { EnvironmentType, PythonEnvironment } from '../../pythonEnvironments/info';
88
import { sendTelemetryEvent } from '../../telemetry';
99
import { EventName } from '../../telemetry/constants';
@@ -28,7 +28,7 @@ export class TerminalHelper implements ITerminalHelper {
2828
constructor(
2929
@inject(IPlatformService) private readonly platform: IPlatformService,
3030
@inject(ITerminalManager) private readonly terminalManager: ITerminalManager,
31-
@inject(ICondaService) private readonly condaService: ICondaService,
31+
@inject(ICondaLocatorService) private readonly condaService: ICondaLocatorService,
3232
@inject(IInterpreterService) readonly interpreterService: IInterpreterService,
3333
@inject(IConfigurationService) private readonly configurationService: IConfigurationService,
3434
@inject(ITerminalActivationCommandProvider)

src/client/interpreter/contracts.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,26 @@ export interface IInterpreterLocatorService extends Disposable {
7777
}
7878

7979
export const ICondaService = Symbol('ICondaService');
80-
80+
/**
81+
* Interface carries the properties which are not available via the discovery component interface.
82+
*/
8183
export interface ICondaService {
82-
readonly condaEnvironmentsFile: string | undefined;
8384
getCondaFile(): Promise<string>;
8485
isCondaAvailable(): Promise<boolean>;
8586
getCondaVersion(): Promise<SemVer | undefined>;
87+
getCondaFileFromInterpreter(interpreterPath?: string, envName?: string): Promise<string | undefined>;
88+
}
89+
90+
export const ICondaLocatorService = Symbol('ICondaLocatorService');
91+
/**
92+
* @deprecated Use the new discovery component when in experiment, use this otherwise.
93+
*/
94+
export interface ICondaLocatorService {
95+
readonly condaEnvironmentsFile: string | undefined;
96+
getCondaFile(): Promise<string>;
8697
getCondaInfo(): Promise<CondaInfo | undefined>;
8798
getCondaEnvironments(ignoreCache: boolean): Promise<CondaEnvironmentInfo[] | undefined>;
8899
getInterpreterPath(condaEnvironmentPath: string): string;
89-
getCondaFileFromInterpreter(interpreterPath?: string, envName?: string): Promise<string | undefined>;
90100
isCondaEnvironment(interpreterPath: string): Promise<boolean>;
91101
getCondaEnvironment(interpreterPath: string): Promise<CondaEnvironmentInfo | undefined>;
92102
}

src/client/pythonEnvironments/discovery/locators/services/condaEnvFileService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as path from 'path';
1313
import { Uri } from 'vscode';
1414
import { traceError } from '../../../../common/logger';
1515
import { IFileSystem } from '../../../../common/platform/types';
16-
import { ICondaService, IInterpreterHelper } from '../../../../interpreter/contracts';
16+
import { ICondaLocatorService, IInterpreterHelper } from '../../../../interpreter/contracts';
1717
import { IServiceContainer } from '../../../../ioc/types';
1818
import { EnvironmentType, PythonEnvironment } from '../../../info';
1919
import { CacheableLocatorService } from './cacheableLocatorService';
@@ -26,7 +26,7 @@ import { AnacondaCompanyName } from './conda';
2626
export class CondaEnvFileService extends CacheableLocatorService {
2727
constructor(
2828
@inject(IInterpreterHelper) private helperService: IInterpreterHelper,
29-
@inject(ICondaService) private condaService: ICondaService,
29+
@inject(ICondaLocatorService) private condaService: ICondaLocatorService,
3030
@inject(IFileSystem) private fileSystem: IFileSystem,
3131
@inject(IServiceContainer) serviceContainer: IServiceContainer,
3232
) {

src/client/pythonEnvironments/discovery/locators/services/condaEnvService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { inject, injectable } from 'inversify';
55
import { Uri } from 'vscode';
66
import { traceError } from '../../../../common/logger';
77
import { IFileSystem } from '../../../../common/platform/types';
8-
import { ICondaService, IInterpreterHelper } from '../../../../interpreter/contracts';
8+
import { ICondaLocatorService, IInterpreterHelper } from '../../../../interpreter/contracts';
99
import { IServiceContainer } from '../../../../ioc/types';
1010
import { PythonEnvironment } from '../../../info';
1111
import { CacheableLocatorService } from './cacheableLocatorService';
@@ -17,7 +17,7 @@ import { parseCondaInfo } from './conda';
1717
@injectable()
1818
export class CondaEnvService extends CacheableLocatorService {
1919
constructor(
20-
@inject(ICondaService) private condaService: ICondaService,
20+
@inject(ICondaLocatorService) private condaService: ICondaLocatorService,
2121
@inject(IInterpreterHelper) private helper: IInterpreterHelper,
2222
@inject(IServiceContainer) serviceContainer: IServiceContainer,
2323
@inject(IFileSystem) private fileSystem: IFileSystem,

0 commit comments

Comments
 (0)