diff --git a/src/common/localize.ts b/src/common/localize.ts index 3caa8a9b..1674a397 100644 --- a/src/common/localize.ts +++ b/src/common/localize.ts @@ -156,6 +156,12 @@ export namespace PyenvStrings { export const pyenvRefreshing = l10n.t('Refreshing Pyenv Python versions'); } +export namespace PipenvStrings { + export const pipenvManager = l10n.t('Manages Pipenv environments'); + export const pipenvDiscovering = l10n.t('Discovering Pipenv environments'); + export const pipenvRefreshing = l10n.t('Refreshing Pipenv environments'); +} + export namespace PoetryStrings { export const poetryManager = l10n.t('Manages Poetry environments'); export const poetryDiscovering = l10n.t('Discovering Poetry environments'); diff --git a/src/managers/pipenv/main.ts b/src/managers/pipenv/main.ts new file mode 100644 index 00000000..b49affc5 --- /dev/null +++ b/src/managers/pipenv/main.ts @@ -0,0 +1,27 @@ +import { Disposable } from 'vscode'; +import { PythonEnvironmentApi } from '../../api'; +import { traceInfo } from '../../common/logging'; +import { getPythonApi } from '../../features/pythonApi'; +import { NativePythonFinder } from '../common/nativePythonFinder'; +import { PipenvManager } from './pipenvManager'; +import { getPipenv } from './pipenvUtils'; + +export async function registerPipenvFeatures( + nativeFinder: NativePythonFinder, + disposables: Disposable[], +): Promise { + const api: PythonEnvironmentApi = await getPythonApi(); + + try { + const pipenv = await getPipenv(nativeFinder); + + if (pipenv) { + const mgr = new PipenvManager(nativeFinder, api); + disposables.push(mgr, api.registerEnvironmentManager(mgr)); + } else { + traceInfo('Pipenv not found, turning off pipenv features.'); + } + } catch (ex) { + traceInfo('Pipenv not found, turning off pipenv features.', ex); + } +} diff --git a/src/managers/pipenv/pipenvManager.ts b/src/managers/pipenv/pipenvManager.ts new file mode 100644 index 00000000..6883a365 --- /dev/null +++ b/src/managers/pipenv/pipenvManager.ts @@ -0,0 +1,93 @@ +import { EventEmitter, MarkdownString } from 'vscode'; +import { + CreateEnvironmentOptions, + CreateEnvironmentScope, + DidChangeEnvironmentEventArgs, + DidChangeEnvironmentsEventArgs, + EnvironmentManager, + GetEnvironmentScope, + GetEnvironmentsScope, + IconPath, + PythonEnvironment, + PythonEnvironmentApi, + QuickCreateConfig, + RefreshEnvironmentsScope, + ResolveEnvironmentContext, + SetEnvironmentScope, +} from '../../api'; +import { PipenvStrings } from '../../common/localize'; +import { NativePythonFinder } from '../common/nativePythonFinder'; + +export class PipenvManager implements EnvironmentManager { + private collection: PythonEnvironment[] = []; + private fsPathToEnv: Map = new Map(); + private globalEnv: PythonEnvironment | undefined; + + private readonly _onDidChangeEnvironment = new EventEmitter(); + public readonly onDidChangeEnvironment = this._onDidChangeEnvironment.event; + + private readonly _onDidChangeEnvironments = new EventEmitter(); + public readonly onDidChangeEnvironments = this._onDidChangeEnvironments.event; + constructor(private readonly nativeFinder: NativePythonFinder, private readonly api: PythonEnvironmentApi) { + this.name = 'pipenv'; + this.displayName = 'Pipenv'; + this.preferredPackageManagerId = 'ms-python.python:pip'; + this.tooltip = new MarkdownString(PipenvStrings.pipenvManager, true); + } + + name: string; + displayName: string; + preferredPackageManagerId: string; + description?: string; + tooltip: string | MarkdownString; + iconPath?: IconPath; + + public dispose() { + this.collection = []; + this.fsPathToEnv.clear(); + } + + quickCreateConfig?(): QuickCreateConfig | undefined { + // To be implemented + return undefined; + } + + async create?( + _scope: CreateEnvironmentScope, + _options?: CreateEnvironmentOptions, + ): Promise { + // To be implemented + return undefined; + } + + async remove?(_environment: PythonEnvironment): Promise { + // To be implemented + } + + async refresh(_scope: RefreshEnvironmentsScope): Promise { + // To be implemented + } + + async getEnvironments(_scope: GetEnvironmentsScope): Promise { + // To be implemented + return []; + } + + async set(_scope: SetEnvironmentScope, _environment?: PythonEnvironment): Promise { + // To be implemented + } + + async get(_scope: GetEnvironmentScope): Promise { + // To be implemented + return undefined; + } + + async resolve(_context: ResolveEnvironmentContext): Promise { + // To be implemented + return undefined; + } + + async clearCache?(): Promise { + // To be implemented + } +} diff --git a/src/managers/pipenv/pipenvUtils.ts b/src/managers/pipenv/pipenvUtils.ts new file mode 100644 index 00000000..48997450 --- /dev/null +++ b/src/managers/pipenv/pipenvUtils.ts @@ -0,0 +1,11 @@ +// Utility functions for Pipenv environment management + +import { NativePythonFinder } from '../common/nativePythonFinder'; + +export class PipenvUtils { + // Add static helper methods for pipenv operations here +} +export async function getPipenv(_native?: NativePythonFinder): Promise { + // Implementation to find and return the pipenv path + return undefined; +}