Skip to content

Commit

Permalink
Conda service is no longer legacy IOC
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj committed Oct 20, 2021
1 parent 5007d03 commit ea3bb7e
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { IWorkspaceService } from '../../../../common/application/types';
import { traceDecorators, traceWarning } from '../../../../common/logger';
import { IFileSystem, IPlatformService } from '../../../../common/platform/types';
import { IProcessServiceFactory } from '../../../../common/process/types';
import { IConfigurationService, IDisposableRegistry } from '../../../../common/types';
import { IDisposableRegistry } from '../../../../common/types';
import { cache } from '../../../../common/utils/decorators';
import { ICondaService } from '../../../../interpreter/contracts';
import { Conda, CondaInfo } from '../../../common/environmentManagers/conda';

/**
* A wrapper around a conda installation.
* Injectable version of Conda utility.
*/
@injectable()
export class CondaService implements ICondaService {
Expand All @@ -24,7 +24,6 @@ export class CondaService implements ICondaService {
@inject(IProcessServiceFactory) private processServiceFactory: IProcessServiceFactory,
@inject(IPlatformService) private platform: IPlatformService,
@inject(IFileSystem) private fileSystem: IFileSystem,
@inject(IConfigurationService) private readonly configService: IConfigurationService,
@inject(IDisposableRegistry) private disposableRegistry: IDisposableRegistry,
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService,
) {
Expand All @@ -36,7 +35,7 @@ export class CondaService implements ICondaService {
*/
public async getCondaFile(): Promise<string> {
if (!this.condaFile) {
this.condaFile = this.getCondaFileImpl();
this.condaFile = Conda.getConda().then((conda) => conda?.command ?? 'conda');
}
return this.condaFile;
}
Expand Down Expand Up @@ -147,19 +146,6 @@ export class CondaService implements ICondaService {
return conda?.getInfo();
}

/**
* Return the path to the "conda file", if there is one (in known locations).
*/
private async getCondaFileImpl(): Promise<string> {
const settings = this.configService.getSettings();
const setting = settings.condaPath;
if (setting && setting !== '') {
return setting;
}
const conda = await Conda.getConda();
return conda?.command ?? 'conda';
}

private addCondaPathChangedHandler() {
const disposable = this.workspaceService.onDidChangeConfiguration(this.onDidChangeConfiguration.bind(this));
this.disposableRegistry.push(disposable);
Expand Down
4 changes: 1 addition & 3 deletions src/client/pythonEnvironments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { PyenvLocator } from './base/locators/lowLevel/pyenvLocator';
import { WindowsRegistryLocator } from './base/locators/lowLevel/windowsRegistryLocator';
import { WindowsStoreLocator } from './base/locators/lowLevel/windowsStoreLocator';
import { getEnvironmentInfoService } from './base/info/environmentInfoService';
import { registerLegacyDiscoveryForIOC, registerNewDiscoveryForIOC } from './legacyIOC';
import { registerNewDiscoveryForIOC } from './legacyIOC';
import { PoetryLocator } from './base/locators/lowLevel/poetryLocator';
import { createPythonEnvironments } from './api';
import {
Expand All @@ -45,8 +45,6 @@ export async function initialize(ext: ExtensionState): Promise<IDiscoveryAPI> {
ext.legacyIOC.serviceManager,
api,
);
// Deal with legacy IOC.
await registerLegacyDiscoveryForIOC(ext.legacyIOC.serviceManager);

return api;
}
Expand Down
5 changes: 1 addition & 4 deletions src/client/pythonEnvironments/legacyIOC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,7 @@ class ComponentAdapter implements IComponentAdapter {
}
}

export async function registerLegacyDiscoveryForIOC(serviceManager: IServiceManager): Promise<void> {
serviceManager.addSingleton<ICondaService>(ICondaService, CondaService);
}

export function registerNewDiscoveryForIOC(serviceManager: IServiceManager, api: IDiscoveryAPI): void {
serviceManager.addSingleton<ICondaService>(ICondaService, CondaService);
serviceManager.addSingletonInstance<IComponentAdapter>(IComponentAdapter, new ComponentAdapter(api));
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,27 @@ import { IWorkspaceService } from '../../../../client/common/application/types';
import { FileSystemPaths, FileSystemPathUtils } from '../../../../client/common/platform/fs-paths';
import { IFileSystem, IPlatformService } from '../../../../client/common/platform/types';
import { IProcessService, IProcessServiceFactory } from '../../../../client/common/process/types';
import { IConfigurationService, IPythonSettings } from '../../../../client/common/types';
import { CondaService } from '../../../../client/pythonEnvironments/discovery/locators/services/condaService';

suite('Interpreters Conda Service', () => {
let processService: TypeMoq.IMock<IProcessService>;
let platformService: TypeMoq.IMock<IPlatformService>;
let condaService: CondaService;
let fileSystem: TypeMoq.IMock<IFileSystem>;
let config: TypeMoq.IMock<IConfigurationService>;
let settings: TypeMoq.IMock<IPythonSettings>;
let procServiceFactory: TypeMoq.IMock<IProcessServiceFactory>;
let condaPathSetting: string;
let workspaceService: TypeMoq.IMock<IWorkspaceService>;
setup(async () => {
condaPathSetting = '';
processService = TypeMoq.Mock.ofType<IProcessService>();
workspaceService = TypeMoq.Mock.ofType<IWorkspaceService>();
platformService = TypeMoq.Mock.ofType<IPlatformService>();
fileSystem = TypeMoq.Mock.ofType<IFileSystem>();
config = TypeMoq.Mock.ofType<IConfigurationService>();
settings = TypeMoq.Mock.ofType<IPythonSettings>();
procServiceFactory = TypeMoq.Mock.ofType<IProcessServiceFactory>();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
processService.setup((x: any) => x.then).returns(() => undefined);
procServiceFactory
.setup((p) => p.create(TypeMoq.It.isAny()))
.returns(() => Promise.resolve(processService.object));

config.setup((c) => c.getSettings(TypeMoq.It.isValue(undefined))).returns(() => settings.object);
settings.setup((p) => p.condaPath).returns(() => condaPathSetting);
fileSystem
.setup((fs) => fs.arePathsSame(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns((p1, p2) => {
Expand All @@ -49,7 +40,6 @@ suite('Interpreters Conda Service', () => {
procServiceFactory.object,
platformService.object,
fileSystem.object,
config.object,
[],
workspaceService.object,
);
Expand Down
3 changes: 1 addition & 2 deletions src/test/pythonEnvironments/legacyIOC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { instance, mock } from 'ts-mockito';
import { IServiceContainer, IServiceManager } from '../../client/ioc/types';
import { IDiscoveryAPI } from '../../client/pythonEnvironments/base/locator';
import { initializeExternalDependencies } from '../../client/pythonEnvironments/common/externalDependencies';
import { registerLegacyDiscoveryForIOC, registerNewDiscoveryForIOC } from '../../client/pythonEnvironments/legacyIOC';
import { registerNewDiscoveryForIOC } from '../../client/pythonEnvironments/legacyIOC';

/**
* This is here to support old tests.
Expand All @@ -18,5 +18,4 @@ export async function registerForIOC(
initializeExternalDependencies(serviceContainer);
// The old tests do not need real instances, directly pass in mocks.
registerNewDiscoveryForIOC(serviceManager, instance(mock<IDiscoveryAPI>()));
await registerLegacyDiscoveryForIOC(serviceManager);
}

0 comments on commit ea3bb7e

Please sign in to comment.