Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b11a544
Add an IOC proxy for PythonInterpreterLocatorService.
ericsnowcurrently Jul 7, 2020
519e3cd
Add an IOC proxy for InterpreterLocatorHelper.
ericsnowcurrently Jul 7, 2020
f822802
Add an IOC proxy for InterpreterLocatorProgressService.
ericsnowcurrently Jul 7, 2020
d5be551
Add an IOC proxy for InterpreterHashProviderFactory.
ericsnowcurrently Jul 7, 2020
1525b18
Factor out BaseLocatorServiceProxy.
ericsnowcurrently Jul 7, 2020
0efaf92
Add an IOC proxy for CondaEnvFileService.
ericsnowcurrently Jul 7, 2020
b327c2f
Add an IOC proxy for CondaEnvService.
ericsnowcurrently Jul 7, 2020
657d1c1
Add an IOC proxy for CurrentPathService.
ericsnowcurrently Jul 7, 2020
937d152
Add an IOC proxy for GlobalVirtualEnvService.
ericsnowcurrently Jul 7, 2020
c5a1848
Add an IOC proxy for WorkspaceVirtualEnvService.
ericsnowcurrently Jul 7, 2020
549821b
Drop @injectable from BaseVirtualEnvService.
ericsnowcurrently Jul 7, 2020
fffdade
Add an IOC proxy for KnownPathsService.
ericsnowcurrently Jul 7, 2020
b4443d4
Add an IOC proxy for PipEnvService.
ericsnowcurrently Jul 7, 2020
a30882c
Add an IOC proxy for WindowsRegistryService.
ericsnowcurrently Jul 7, 2020
af2a75e
Drop @injectable from CacheableLocatorService.
ericsnowcurrently Jul 7, 2020
de735eb
Add an IOC proxy for InterpreterHashProvider.
ericsnowcurrently Jul 7, 2020
37f879e
Add an IOC proxy for WindowsStoreInterpreter.
ericsnowcurrently Jul 7, 2020
0d7a990
Group the hash-related classes.
ericsnowcurrently Jul 7, 2020
0ba480e
Add an IOC proxy for PythonInPathCommandProvider.
ericsnowcurrently Jul 7, 2020
464564f
Add an IOC proxy for KnownSearchPathsForInterpreters.
ericsnowcurrently Jul 7, 2020
6acd67f
Add an IOC proxy for WorkspaceVirtualEnvironmentsSearchPathProvider.
ericsnowcurrently Jul 7, 2020
4b99446
Add an IOC proxy for PipEnvServiceHelper.
ericsnowcurrently Jul 7, 2020
8d4f537
Add an IOC proxy for GlobalVirtualEnvironmentsSearchPathProvider.
ericsnowcurrently Jul 7, 2020
be8b4a2
Add an IOC proxy for CondaService.
ericsnowcurrently Jul 7, 2020
0e964e7
Add an IOC proxy for InterpreterWatcherBuilder.
ericsnowcurrently Jul 7, 2020
d1e900d
Add an IOC proxy for WorkspaceVirtualEnvWatcherService.
ericsnowcurrently Jul 7, 2020
78fc597
Drop the legacy DI registration test.
ericsnowcurrently Jul 7, 2020
45a2d53
Fix sneaky usage of IPipEnvService.
ericsnowcurrently Jul 8, 2020
fa2ec88
Fix sneaky usage of WorkspaceVirtualEnvWatcherService.
ericsnowcurrently Jul 8, 2020
5bc2bdd
Add a setter for BaseLocatorServiceProxy.didTriggerInterpreterSuggest…
ericsnowcurrently Jul 8, 2020
7215db0
Fix some "standard" tests.
ericsnowcurrently Jul 8, 2020
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/process/pythonExecutionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { ICondaService, IInterpreterService } from '../../interpreter/contracts'
import { IWindowsStoreInterpreter } from '../../interpreter/locators/types';
import { IServiceContainer } from '../../ioc/types';
import { CondaEnvironmentInfo } from '../../pythonEnvironments/discovery/locators/services/conda';
import { WindowsStoreInterpreter } from '../../pythonEnvironments/discovery/locators/services/windowsStoreInterpreter';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
import { traceError } from '../logger';
Expand Down Expand Up @@ -51,7 +50,7 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {
@inject(IConfigurationService) private readonly configService: IConfigurationService,
@inject(ICondaService) private readonly condaService: ICondaService,
@inject(IBufferDecoder) private readonly decoder: IBufferDecoder,
@inject(WindowsStoreInterpreter) private readonly windowsStoreInterpreter: IWindowsStoreInterpreter,
@inject(IWindowsStoreInterpreter) private readonly windowsStoreInterpreter: IWindowsStoreInterpreter,
@inject(IPlatformService) private readonly platformService: IPlatformService
) {
// Acquire other objects here so that if we are called during dispose they are available.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@

'use strict';

import { inject, injectable, named } from 'inversify';
import { inject, injectable } from 'inversify';
import { Uri } from 'vscode';
import '../../../common/extensions';
import {
IInterpreterLocatorService,
IInterpreterService,
IPipEnvService,
PIPENV_SERVICE
} from '../../../interpreter/contracts';
import { IInterpreterService, IPipEnvService } from '../../../interpreter/contracts';
import { InterpreterType } from '../../../pythonEnvironments/info';
import { IWorkspaceService } from '../../application/types';
import { IFileSystem } from '../../platform/types';
Expand All @@ -21,9 +16,7 @@ import { ITerminalActivationCommandProvider, TerminalShellType } from '../types'
export class PipEnvActivationCommandProvider implements ITerminalActivationCommandProvider {
constructor(
@inject(IInterpreterService) private readonly interpreterService: IInterpreterService,
@inject(IInterpreterLocatorService)
@named(PIPENV_SERVICE)
private readonly pipenvService: IPipEnvService,
@inject(IPipEnvService) private readonly pipenvService: IPipEnvService,
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService,
@inject(IFileSystem) private readonly fs: IFileSystem
) {}
Expand Down
8 changes: 6 additions & 2 deletions src/client/interpreter/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export interface IInterpreterHelper {
}

export const IPipEnvService = Symbol('IPipEnvService');
export interface IPipEnvService extends IInterpreterLocatorService {
export interface IPipEnvService {
executable: string;
isRelatedPipEnvironment(dir: string, pythonPath: string): Promise<boolean>;
}
Expand All @@ -99,11 +99,15 @@ export interface IInterpreterLocatorHelper {
mergeInterpreters(interpreters: PythonInterpreter[]): Promise<PythonInterpreter[]>;
}

export const IInterpreterWatcher = Symbol('IInterpreterWatcher');
export interface IInterpreterWatcher {
onDidCreate: Event<Resource>;
}

export const IInterpreterWatcherRegistry = Symbol('IInterpreterWatcherRegistry');
export interface IInterpreterWatcherRegistry extends IInterpreterWatcher {
register(resource: Resource): Promise<void>;
}

export const IInterpreterWatcherBuilder = Symbol('IInterpreterWatcherBuilder');
export interface IInterpreterWatcherBuilder {
getWorkspaceVirtualEnvInterpreterWatcher(resource: Resource): Promise<IInterpreterWatcher>;
Expand Down
3 changes: 1 addition & 2 deletions src/client/interpreter/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { IPythonExecutionFactory } from '../common/process/types';
import { IPersistentStateFactory, Resource } from '../common/types';
import { IServiceContainer } from '../ioc/types';
import { isMacDefaultPythonPath } from '../pythonEnvironments/discovery';
import { InterpeterHashProviderFactory } from '../pythonEnvironments/discovery/locators/services/hashProviderFactory';
import {
getInterpreterTypeName,
InterpreterInformation,
Expand Down Expand Up @@ -49,7 +48,7 @@ export class InterpreterHelper implements IInterpreterHelper {
private readonly persistentFactory: IPersistentStateFactory;
constructor(
@inject(IServiceContainer) private serviceContainer: IServiceContainer,
@inject(InterpeterHashProviderFactory) private readonly hashProviderFactory: IInterpreterHashProviderFactory
@inject(IInterpreterHashProviderFactory) private readonly hashProviderFactory: IInterpreterHashProviderFactory
) {
this.persistentFactory = this.serviceContainer.get<IPersistentStateFactory>(IPersistentStateFactory);
}
Expand Down
3 changes: 1 addition & 2 deletions src/client/interpreter/interpreterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
} from '../common/types';
import { sleep } from '../common/utils/async';
import { IServiceContainer } from '../ioc/types';
import { InterpeterHashProviderFactory } from '../pythonEnvironments/discovery/locators/services/hashProviderFactory';
import { InterpreterType, PythonInterpreter } from '../pythonEnvironments/info';
import { captureTelemetry } from '../telemetry';
import { EventName } from '../telemetry/constants';
Expand Down Expand Up @@ -70,7 +69,7 @@ export class InterpreterService implements Disposable, IInterpreterService {

constructor(
@inject(IServiceContainer) private serviceContainer: IServiceContainer,
@inject(InterpeterHashProviderFactory) private readonly hashProviderFactory: IInterpreterHashProviderFactory
@inject(IInterpreterHashProviderFactory) private readonly hashProviderFactory: IInterpreterHashProviderFactory
) {
this.locator = serviceContainer.get<IInterpreterLocatorService>(
IInterpreterLocatorService,
Expand Down
6 changes: 6 additions & 0 deletions src/client/interpreter/locators/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface IPipEnvServiceHelper {
trackWorkspaceFolder(pythonPath: string, workspaceFolder: Uri): Promise<void>;
}

export const IInterpreterHashProviderFactory = Symbol('IInterpreterHashProviderFactory');
/**
* Factory to create a hash provider.
* Getting the hash of an interpreter can vary based on the type of the interpreter.
Expand All @@ -26,6 +27,7 @@ export interface IInterpreterHashProviderFactory {
create(options: { pythonPath: string } | { resource: Uri }): Promise<IInterpreterHashProvider>;
}

export const IInterpreterHashProvider = Symbol('IInterpreterHashProvider');
/**
* Provides the ability to get the has of a given interpreter.
*
Expand All @@ -44,6 +46,10 @@ export interface IInterpreterHashProvider {
getInterpreterHash(pythonPath: string): Promise<string>;
}

export const IWindowsStoreHashProvider = Symbol('IWindowStoreHashProvider');
export interface IWindowsStoreHashProvider extends IInterpreterHashProvider {}

export const IWindowsStoreInterpreter = Symbol('IWindowsStoreInterpreter');
export interface IWindowsStoreInterpreter {
/**
* Whether this is a Windows Store/App Interpreter.
Expand Down
7 changes: 2 additions & 5 deletions src/client/interpreter/virtualEnvs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { IServiceContainer } from '../../ioc/types';
import * as globalenvs from '../../pythonEnvironments/discovery/globalenv';
import * as subenvs from '../../pythonEnvironments/discovery/subenv';
import { InterpreterType } from '../../pythonEnvironments/info';
import { IInterpreterLocatorService, IPipEnvService, PIPENV_SERVICE } from '../contracts';
import { IPipEnvService } from '../contracts';
import { IVirtualEnvironmentManager } from './types';

@injectable()
Expand All @@ -26,10 +26,7 @@ export class VirtualEnvironmentManager implements IVirtualEnvironmentManager {
constructor(@inject(IServiceContainer) private readonly serviceContainer: IServiceContainer) {
this.processServiceFactory = serviceContainer.get<IProcessServiceFactory>(IProcessServiceFactory);
this.fs = serviceContainer.get<IFileSystem>(IFileSystem);
this.pipEnvService = serviceContainer.get<IInterpreterLocatorService>(
IInterpreterLocatorService,
PIPENV_SERVICE
) as IPipEnvService;
this.pipEnvService = serviceContainer.get<IPipEnvService>(IPipEnvService);
this.workspaceService = serviceContainer.get<IWorkspaceService>(IWorkspaceService);
}

Expand Down
6 changes: 2 additions & 4 deletions src/client/pythonEnvironments/discovery/locators/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as fsapi from 'fs-extra';
import { inject, injectable } from 'inversify';
import { inject } from 'inversify';
import * as path from 'path';
import { traceError } from '../../../common/logger';
import { IS_WINDOWS } from '../../../common/platform/constants';
import { IFileSystem } from '../../../common/platform/types';
import { IInterpreterLocatorHelper } from '../../../interpreter/contracts';
import { IPipEnvServiceHelper } from '../../../interpreter/locators/types';
import { InterpreterType, PythonInterpreter } from '../../info';

Expand All @@ -26,8 +25,7 @@ export async function lookForInterpretersInDirectory(pathToCheck: string, _: IFi
}
}

@injectable()
export class InterpreterLocatorHelper implements IInterpreterLocatorHelper {
export class InterpreterLocatorHelper {
constructor(
@inject(IFileSystem) private readonly fs: IFileSystem,
@inject(IPipEnvServiceHelper) private readonly pipEnvServiceHelper: IPipEnvServiceHelper
Expand Down
7 changes: 2 additions & 5 deletions src/client/pythonEnvironments/discovery/locators/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { inject, injectable } from 'inversify';
import { inject } from 'inversify';
import { Disposable, Event, EventEmitter, Uri } from 'vscode';
import { traceDecorators } from '../../../common/logger';
import { IPlatformService } from '../../../common/platform/types';
import { IDisposableRegistry } from '../../../common/types';
import { createDeferred, Deferred } from '../../../common/utils/async';
import { OSType } from '../../../common/utils/platform';
import {
Expand All @@ -28,8 +27,7 @@ const flatten = require('lodash/flatten') as typeof import('lodash/flatten');
/**
* Facilitates locating Python interpreters.
*/
@injectable()
export class PythonInterpreterLocatorService implements IInterpreterLocatorService {
export class PythonInterpreterLocatorService {
public didTriggerInterpreterSuggestions: boolean;

private readonly disposables: Disposable[] = [];
Expand All @@ -39,7 +37,6 @@ export class PythonInterpreterLocatorService implements IInterpreterLocatorServi

constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer) {
this._hasInterpreters = createDeferred<boolean>();
serviceContainer.get<Disposable[]>(IDisposableRegistry).push(this);
this.platform = serviceContainer.get<IPlatformService>(IPlatformService);
this.interpreterLocatorHelper = serviceContainer.get<IInterpreterLocatorHelper>(IInterpreterLocatorHelper);
this.didTriggerInterpreterSuggestions = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@

'use strict';

import { inject, injectable } from 'inversify';
import { inject } from 'inversify';
import { Disposable, Event, EventEmitter } from 'vscode';
import { traceDecorators } from '../../../common/logger';
import { IDisposableRegistry } from '../../../common/types';
import { createDeferredFrom, Deferred } from '../../../common/utils/async';
import { noop } from '../../../common/utils/misc';
import { IInterpreterLocatorProgressService, IInterpreterLocatorService } from '../../../interpreter/contracts';
import { IInterpreterLocatorService } from '../../../interpreter/contracts';
import { IServiceContainer } from '../../../ioc/types';
import { PythonInterpreter } from '../../info';

@injectable()
export class InterpreterLocatorProgressService implements IInterpreterLocatorProgressService {
export class InterpreterLocatorProgressService {
private deferreds: Deferred<PythonInterpreter[]>[] = [];
private readonly refreshing = new EventEmitter<void>();
private readonly refreshed = new EventEmitter<void>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-require-imports no-var-requires no-unnecessary-callback-wrapper
import { inject, injectable } from 'inversify';
import { inject } from 'inversify';
import * as path from 'path';
import { Uri } from 'vscode';
import { IFileSystem, IPlatformService } from '../../../../common/platform/types';
Expand All @@ -14,7 +14,6 @@ const flatten = require('lodash/flatten') as typeof import('lodash/flatten');
/**
* Locates "known" paths.
*/
@injectable()
export class KnownPathsService extends CacheableLocatorService {
public constructor(
@inject(IKnownSearchPathsForInterpreters) private knownSearchPaths: IKnownSearchPathsForInterpreters,
Expand Down Expand Up @@ -84,8 +83,7 @@ export class KnownPathsService extends CacheableLocatorService {
}
}

@injectable()
export class KnownSearchPathsForInterpreters implements IKnownSearchPathsForInterpreters {
export class KnownSearchPathsForInterpreters {
constructor(@inject(IServiceContainer) private readonly serviceContainer: IServiceContainer) {}
/**
* Return the paths where Python interpreters might be found.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// tslint:disable:no-unnecessary-callback-wrapper no-require-imports no-var-requires

import { injectable, unmanaged } from 'inversify';
import * as path from 'path';
import { Uri } from 'vscode';
import { traceError } from '../../../../common/logger';
Expand All @@ -13,16 +12,15 @@ import { lookForInterpretersInDirectory } from '../helpers';
import { CacheableLocatorService } from './cacheableLocatorService';
const flatten = require('lodash/flatten') as typeof import('lodash/flatten');

@injectable()
export class BaseVirtualEnvService extends CacheableLocatorService {
private readonly virtualEnvMgr: IVirtualEnvironmentManager;
private readonly helper: IInterpreterHelper;
private readonly fileSystem: IFileSystem;
public constructor(
@unmanaged() private searchPathsProvider: IVirtualEnvironmentsSearchPathProvider,
@unmanaged() serviceContainer: IServiceContainer,
@unmanaged() name: string,
@unmanaged() cachePerWorkspace: boolean = false
private searchPathsProvider: IVirtualEnvironmentsSearchPathProvider,
serviceContainer: IServiceContainer,
name: string,
cachePerWorkspace: boolean = false
) {
super(name, serviceContainer, cachePerWorkspace);
this.virtualEnvMgr = serviceContainer.get<IVirtualEnvironmentManager>(IVirtualEnvironmentManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

// tslint:disable:no-any

import { injectable, unmanaged } from 'inversify';
import * as md5 from 'md5';
import { Disposable, Event, EventEmitter, Uri } from 'vscode';
import { IWorkspaceService } from '../../../../common/application/types';
Expand Down Expand Up @@ -60,7 +59,6 @@ export class CacheableLocatorPromiseCache {
}
}

@injectable()
export abstract class CacheableLocatorService implements IInterpreterLocatorService {
protected readonly _hasInterpreters: Deferred<boolean>;
private readonly promisesPerResource = new CacheableLocatorPromiseCache();
Expand All @@ -70,9 +68,9 @@ export abstract class CacheableLocatorService implements IInterpreterLocatorServ
private _didTriggerInterpreterSuggestions: boolean;

constructor(
@unmanaged() private readonly name: string,
@unmanaged() protected readonly serviceContainer: IServiceContainer,
@unmanaged() private cachePerWorkspace: boolean = false
private readonly name: string,
protected readonly serviceContainer: IServiceContainer,
private cachePerWorkspace: boolean = false
) {
this._hasInterpreters = createDeferred<boolean>();
this.cacheKeyPrefix = `INTERPRETERS_CACHE_v3_${name}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* More details: https://github.com/microsoft/vscode-python/issues/8886
*/

import { inject, injectable } from 'inversify';
import { inject } from 'inversify';
import * as path from 'path';
import { Uri } from 'vscode';
import { traceError } from '../../../../common/logger';
Expand All @@ -22,7 +22,6 @@ import { AnacondaCompanyName } from './conda';
/**
* Locate conda env interpreters based on the "conda environments file".
*/
@injectable()
export class CondaEnvFileService extends CacheableLocatorService {
constructor(
@inject(IInterpreterHelper) private helperService: IInterpreterHelper,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { inject, injectable } from 'inversify';
import { inject } from 'inversify';
import { Uri } from 'vscode';
import { traceError } from '../../../../common/logger';
import { IFileSystem } from '../../../../common/platform/types';
Expand All @@ -14,7 +14,6 @@ import { parseCondaInfo } from './conda';
/**
* Locates conda env interpreters based on the conda service's info.
*/
@injectable()
export class CondaEnvService extends CacheableLocatorService {
constructor(
@inject(ICondaService) private condaService: ICondaService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { inject, injectable, named, optional } from 'inversify';
import { inject, named, optional } from 'inversify';
import * as path from 'path';
import { compare, parse, SemVer } from 'semver';
import { ConfigurationChangeEvent, Uri } from 'vscode';
Expand All @@ -9,7 +9,7 @@ import { IFileSystem, IPlatformService } from '../../../../common/platform/types
import { IProcessServiceFactory } from '../../../../common/process/types';
import { IConfigurationService, IDisposableRegistry, IPersistentStateFactory } from '../../../../common/types';
import { cache } from '../../../../common/utils/decorators';
import { ICondaService, IInterpreterLocatorService, WINDOWS_REGISTRY_SERVICE } from '../../../../interpreter/contracts';
import { IInterpreterLocatorService, WINDOWS_REGISTRY_SERVICE } from '../../../../interpreter/contracts';
import { InterpreterType, PythonInterpreter } from '../../../info';
import { CondaEnvironmentInfo, CondaInfo } from './conda';
import { parseCondaEnvFileContents } from './condaHelper';
Expand Down Expand Up @@ -48,8 +48,7 @@ export const CondaGetEnvironmentPrefix = 'Outputting Environment Now...';
/**
* A wrapper around a conda installation.
*/
@injectable()
export class CondaService implements ICondaService {
export class CondaService {
private condaFile?: Promise<string | undefined>;
private isAvailable: boolean | undefined;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-require-imports no-var-requires underscore-consistent-invocation no-unnecessary-callback-wrapper
import { inject, injectable } from 'inversify';
import { inject } from 'inversify';
import { Uri } from 'vscode';
import { traceError, traceInfo } from '../../../../common/logger';
import { IFileSystem, IPlatformService } from '../../../../common/platform/types';
Expand All @@ -19,7 +19,6 @@ import { CacheableLocatorService } from './cacheableLocatorService';
* If no interpreter is configured then it falls back to the system
* Python (3 then 2).
*/
@injectable()
export class CurrentPathService extends CacheableLocatorService {
private readonly fs: IFileSystem;

Expand Down Expand Up @@ -125,8 +124,7 @@ export class CurrentPathService extends CacheableLocatorService {
}
}

@injectable()
export class PythonInPathCommandProvider implements IPythonInPathCommandProvider {
export class PythonInPathCommandProvider {
constructor(@inject(IPlatformService) private readonly platform: IPlatformService) {}
public getCommands(): { command: string; args?: string[] }[] {
const paths = ['python3.7', 'python3.6', 'python3', 'python2', 'python'].map((item) => {
Expand Down
Loading