Skip to content
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
3 changes: 2 additions & 1 deletion src/client/common/process/pythonExecutionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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 @@ -50,7 +51,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(IWindowsStoreInterpreter) private readonly windowsStoreInterpreter: IWindowsStoreInterpreter,
@inject(WindowsStoreInterpreter) 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,10 +3,15 @@

'use strict';

import { inject, injectable } from 'inversify';
import { inject, injectable, named } from 'inversify';
import { Uri } from 'vscode';
import '../../../common/extensions';
import { IInterpreterService, IPipEnvService } from '../../../interpreter/contracts';
import {
IInterpreterLocatorService,
IInterpreterService,
IPipEnvService,
PIPENV_SERVICE
} from '../../../interpreter/contracts';
import { InterpreterType } from '../../../pythonEnvironments/info';
import { IWorkspaceService } from '../../application/types';
import { IFileSystem } from '../../platform/types';
Expand All @@ -16,7 +21,9 @@ import { ITerminalActivationCommandProvider, TerminalShellType } from '../types'
export class PipEnvActivationCommandProvider implements ITerminalActivationCommandProvider {
constructor(
@inject(IInterpreterService) private readonly interpreterService: IInterpreterService,
@inject(IPipEnvService) private readonly pipenvService: IPipEnvService,
@inject(IInterpreterLocatorService)
@named(PIPENV_SERVICE)
private readonly pipenvService: IPipEnvService,
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService,
@inject(IFileSystem) private readonly fs: IFileSystem
) {}
Expand Down
8 changes: 2 additions & 6 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 {
export interface IPipEnvService extends IInterpreterLocatorService {
executable: string;
isRelatedPipEnvironment(dir: string, pythonPath: string): Promise<boolean>;
}
Expand All @@ -99,15 +99,11 @@ 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: 2 additions & 1 deletion src/client/interpreter/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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 @@ -48,7 +49,7 @@ export class InterpreterHelper implements IInterpreterHelper {
private readonly persistentFactory: IPersistentStateFactory;
constructor(
@inject(IServiceContainer) private serviceContainer: IServiceContainer,
@inject(IInterpreterHashProviderFactory) private readonly hashProviderFactory: IInterpreterHashProviderFactory
@inject(InterpeterHashProviderFactory) private readonly hashProviderFactory: IInterpreterHashProviderFactory
) {
this.persistentFactory = this.serviceContainer.get<IPersistentStateFactory>(IPersistentStateFactory);
}
Expand Down
3 changes: 2 additions & 1 deletion src/client/interpreter/interpreterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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 @@ -69,7 +70,7 @@ export class InterpreterService implements Disposable, IInterpreterService {

constructor(
@inject(IServiceContainer) private serviceContainer: IServiceContainer,
@inject(IInterpreterHashProviderFactory) private readonly hashProviderFactory: IInterpreterHashProviderFactory
@inject(InterpeterHashProviderFactory) private readonly hashProviderFactory: IInterpreterHashProviderFactory
) {
this.locator = serviceContainer.get<IInterpreterLocatorService>(
IInterpreterLocatorService,
Expand Down
6 changes: 0 additions & 6 deletions src/client/interpreter/locators/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ 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 @@ -27,7 +26,6 @@ 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 @@ -46,10 +44,6 @@ 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: 5 additions & 2 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 { IPipEnvService } from '../contracts';
import { IInterpreterLocatorService, IPipEnvService, PIPENV_SERVICE } from '../contracts';
import { IVirtualEnvironmentManager } from './types';

@injectable()
Expand All @@ -26,7 +26,10 @@ 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<IPipEnvService>(IPipEnvService);
this.pipEnvService = serviceContainer.get<IInterpreterLocatorService>(
IInterpreterLocatorService,
PIPENV_SERVICE
) as IPipEnvService;
this.workspaceService = serviceContainer.get<IWorkspaceService>(IWorkspaceService);
}

Expand Down
6 changes: 4 additions & 2 deletions src/client/pythonEnvironments/discovery/locators/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as fsapi from 'fs-extra';
import { inject } from 'inversify';
import { inject, injectable } 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 @@ -25,7 +26,8 @@ export async function lookForInterpretersInDirectory(pathToCheck: string, _: IFi
}
}

export class InterpreterLocatorHelper {
@injectable()
export class InterpreterLocatorHelper implements IInterpreterLocatorHelper {
constructor(
@inject(IFileSystem) private readonly fs: IFileSystem,
@inject(IPipEnvServiceHelper) private readonly pipEnvServiceHelper: IPipEnvServiceHelper
Expand Down
7 changes: 5 additions & 2 deletions src/client/pythonEnvironments/discovery/locators/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { inject } from 'inversify';
import { inject, injectable } 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 @@ -27,7 +28,8 @@ const flatten = require('lodash/flatten') as typeof import('lodash/flatten');
/**
* Facilitates locating Python interpreters.
*/
export class PythonInterpreterLocatorService {
@injectable()
export class PythonInterpreterLocatorService implements IInterpreterLocatorService {
public didTriggerInterpreterSuggestions: boolean;

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

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,17 +3,18 @@

'use strict';

import { inject } from 'inversify';
import { inject, injectable } 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 { IInterpreterLocatorService } from '../../../interpreter/contracts';
import { IInterpreterLocatorProgressService, IInterpreterLocatorService } from '../../../interpreter/contracts';
import { IServiceContainer } from '../../../ioc/types';
import { PythonInterpreter } from '../../info';

export class InterpreterLocatorProgressService {
@injectable()
export class InterpreterLocatorProgressService implements IInterpreterLocatorProgressService {
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 } from 'inversify';
import { inject, injectable } from 'inversify';
import * as path from 'path';
import { Uri } from 'vscode';
import { IFileSystem, IPlatformService } from '../../../../common/platform/types';
Expand All @@ -14,6 +14,7 @@ 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 @@ -83,7 +84,8 @@ export class KnownPathsService extends CacheableLocatorService {
}
}

export class KnownSearchPathsForInterpreters {
@injectable()
export class KnownSearchPathsForInterpreters implements IKnownSearchPathsForInterpreters {
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,5 +1,6 @@
// 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 @@ -12,15 +13,16 @@ 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(
private searchPathsProvider: IVirtualEnvironmentsSearchPathProvider,
serviceContainer: IServiceContainer,
name: string,
cachePerWorkspace: boolean = false
@unmanaged() private searchPathsProvider: IVirtualEnvironmentsSearchPathProvider,
@unmanaged() serviceContainer: IServiceContainer,
@unmanaged() name: string,
@unmanaged() 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,6 +3,7 @@

// 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 @@ -59,6 +60,7 @@ export class CacheableLocatorPromiseCache {
}
}

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

constructor(
private readonly name: string,
protected readonly serviceContainer: IServiceContainer,
private cachePerWorkspace: boolean = false
@unmanaged() private readonly name: string,
@unmanaged() protected readonly serviceContainer: IServiceContainer,
@unmanaged() 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 } from 'inversify';
import { inject, injectable } from 'inversify';
import * as path from 'path';
import { Uri } from 'vscode';
import { traceError } from '../../../../common/logger';
Expand All @@ -22,6 +22,7 @@ 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 } from 'inversify';
import { inject, injectable } from 'inversify';
import { Uri } from 'vscode';
import { traceError } from '../../../../common/logger';
import { IFileSystem } from '../../../../common/platform/types';
Expand All @@ -14,6 +14,7 @@ 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, named, optional } from 'inversify';
import { inject, injectable, 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 { IInterpreterLocatorService, WINDOWS_REGISTRY_SERVICE } from '../../../../interpreter/contracts';
import { ICondaService, 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,7 +48,8 @@ export const CondaGetEnvironmentPrefix = 'Outputting Environment Now...';
/**
* A wrapper around a conda installation.
*/
export class CondaService {
@injectable()
export class CondaService implements ICondaService {
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 } from 'inversify';
import { inject, injectable } from 'inversify';
import { Uri } from 'vscode';
import { traceError, traceInfo } from '../../../../common/logger';
import { IFileSystem, IPlatformService } from '../../../../common/platform/types';
Expand All @@ -19,6 +19,7 @@ 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 @@ -124,7 +125,8 @@ export class CurrentPathService extends CacheableLocatorService {
}
}

export class PythonInPathCommandProvider {
@injectable()
export class PythonInPathCommandProvider implements IPythonInPathCommandProvider {
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