Skip to content

Commit e8d6091

Browse files
authored
initial scaffolding (#741)
scaffolding for pipenv as an env manager
1 parent ef67c74 commit e8d6091

File tree

4 files changed

+137
-0
lines changed

4 files changed

+137
-0
lines changed

src/common/localize.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ export namespace PyenvStrings {
156156
export const pyenvRefreshing = l10n.t('Refreshing Pyenv Python versions');
157157
}
158158

159+
export namespace PipenvStrings {
160+
export const pipenvManager = l10n.t('Manages Pipenv environments');
161+
export const pipenvDiscovering = l10n.t('Discovering Pipenv environments');
162+
export const pipenvRefreshing = l10n.t('Refreshing Pipenv environments');
163+
}
164+
159165
export namespace PoetryStrings {
160166
export const poetryManager = l10n.t('Manages Poetry environments');
161167
export const poetryDiscovering = l10n.t('Discovering Poetry environments');

src/managers/pipenv/main.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Disposable } from 'vscode';
2+
import { PythonEnvironmentApi } from '../../api';
3+
import { traceInfo } from '../../common/logging';
4+
import { getPythonApi } from '../../features/pythonApi';
5+
import { NativePythonFinder } from '../common/nativePythonFinder';
6+
import { PipenvManager } from './pipenvManager';
7+
import { getPipenv } from './pipenvUtils';
8+
9+
export async function registerPipenvFeatures(
10+
nativeFinder: NativePythonFinder,
11+
disposables: Disposable[],
12+
): Promise<void> {
13+
const api: PythonEnvironmentApi = await getPythonApi();
14+
15+
try {
16+
const pipenv = await getPipenv(nativeFinder);
17+
18+
if (pipenv) {
19+
const mgr = new PipenvManager(nativeFinder, api);
20+
disposables.push(mgr, api.registerEnvironmentManager(mgr));
21+
} else {
22+
traceInfo('Pipenv not found, turning off pipenv features.');
23+
}
24+
} catch (ex) {
25+
traceInfo('Pipenv not found, turning off pipenv features.', ex);
26+
}
27+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { EventEmitter, MarkdownString } from 'vscode';
2+
import {
3+
CreateEnvironmentOptions,
4+
CreateEnvironmentScope,
5+
DidChangeEnvironmentEventArgs,
6+
DidChangeEnvironmentsEventArgs,
7+
EnvironmentManager,
8+
GetEnvironmentScope,
9+
GetEnvironmentsScope,
10+
IconPath,
11+
PythonEnvironment,
12+
PythonEnvironmentApi,
13+
QuickCreateConfig,
14+
RefreshEnvironmentsScope,
15+
ResolveEnvironmentContext,
16+
SetEnvironmentScope,
17+
} from '../../api';
18+
import { PipenvStrings } from '../../common/localize';
19+
import { NativePythonFinder } from '../common/nativePythonFinder';
20+
21+
export class PipenvManager implements EnvironmentManager {
22+
private collection: PythonEnvironment[] = [];
23+
private fsPathToEnv: Map<string, PythonEnvironment> = new Map();
24+
private globalEnv: PythonEnvironment | undefined;
25+
26+
private readonly _onDidChangeEnvironment = new EventEmitter<DidChangeEnvironmentEventArgs>();
27+
public readonly onDidChangeEnvironment = this._onDidChangeEnvironment.event;
28+
29+
private readonly _onDidChangeEnvironments = new EventEmitter<DidChangeEnvironmentsEventArgs>();
30+
public readonly onDidChangeEnvironments = this._onDidChangeEnvironments.event;
31+
constructor(private readonly nativeFinder: NativePythonFinder, private readonly api: PythonEnvironmentApi) {
32+
this.name = 'pipenv';
33+
this.displayName = 'Pipenv';
34+
this.preferredPackageManagerId = 'ms-python.python:pip';
35+
this.tooltip = new MarkdownString(PipenvStrings.pipenvManager, true);
36+
}
37+
38+
name: string;
39+
displayName: string;
40+
preferredPackageManagerId: string;
41+
description?: string;
42+
tooltip: string | MarkdownString;
43+
iconPath?: IconPath;
44+
45+
public dispose() {
46+
this.collection = [];
47+
this.fsPathToEnv.clear();
48+
}
49+
50+
quickCreateConfig?(): QuickCreateConfig | undefined {
51+
// To be implemented
52+
return undefined;
53+
}
54+
55+
async create?(
56+
_scope: CreateEnvironmentScope,
57+
_options?: CreateEnvironmentOptions,
58+
): Promise<PythonEnvironment | undefined> {
59+
// To be implemented
60+
return undefined;
61+
}
62+
63+
async remove?(_environment: PythonEnvironment): Promise<void> {
64+
// To be implemented
65+
}
66+
67+
async refresh(_scope: RefreshEnvironmentsScope): Promise<void> {
68+
// To be implemented
69+
}
70+
71+
async getEnvironments(_scope: GetEnvironmentsScope): Promise<PythonEnvironment[]> {
72+
// To be implemented
73+
return [];
74+
}
75+
76+
async set(_scope: SetEnvironmentScope, _environment?: PythonEnvironment): Promise<void> {
77+
// To be implemented
78+
}
79+
80+
async get(_scope: GetEnvironmentScope): Promise<PythonEnvironment | undefined> {
81+
// To be implemented
82+
return undefined;
83+
}
84+
85+
async resolve(_context: ResolveEnvironmentContext): Promise<PythonEnvironment | undefined> {
86+
// To be implemented
87+
return undefined;
88+
}
89+
90+
async clearCache?(): Promise<void> {
91+
// To be implemented
92+
}
93+
}

src/managers/pipenv/pipenvUtils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Utility functions for Pipenv environment management
2+
3+
import { NativePythonFinder } from '../common/nativePythonFinder';
4+
5+
export class PipenvUtils {
6+
// Add static helper methods for pipenv operations here
7+
}
8+
export async function getPipenv(_native?: NativePythonFinder): Promise<string | undefined> {
9+
// Implementation to find and return the pipenv path
10+
return undefined;
11+
}

0 commit comments

Comments
 (0)