Skip to content

Commit 597b10c

Browse files
Copiloteleanorjboyd
andcommitted
Implement basic Pipenv registration and manager scaffolding
Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
1 parent 1fff348 commit 597b10c

3 files changed

Lines changed: 79 additions & 25 deletions

File tree

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import {
7676
} from './managers/common/nativePythonFinder';
7777
import { IDisposable } from './managers/common/types';
7878
import { registerCondaFeatures } from './managers/conda/main';
79+
import { registerPipenvFeatures } from './managers/pipenv/main';
7980
import { registerPoetryFeatures } from './managers/poetry/main';
8081
import { registerPyenvFeatures } from './managers/pyenv/main';
8182

@@ -562,6 +563,7 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
562563
registerSystemPythonFeatures(nativeFinder, context.subscriptions, outputChannel, sysMgr),
563564
registerCondaFeatures(nativeFinder, context.subscriptions, outputChannel),
564565
registerPyenvFeatures(nativeFinder, context.subscriptions),
566+
registerPipenvFeatures(nativeFinder, context.subscriptions),
565567
registerPoetryFeatures(nativeFinder, context.subscriptions, outputChannel),
566568
shellStartupVarsMgr.initialize(),
567569
]);

src/managers/pipenv/pipenvManager.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,32 @@ import { PipenvStrings } from '../../common/localize';
1919
import { NativePythonFinder } from '../common/nativePythonFinder';
2020

2121
export class PipenvManager implements EnvironmentManager {
22-
private collection: PythonEnvironment[] = [];
23-
private fsPathToEnv: Map<string, PythonEnvironment> = new Map();
24-
private globalEnv: PythonEnvironment | undefined;
25-
2622
private readonly _onDidChangeEnvironment = new EventEmitter<DidChangeEnvironmentEventArgs>();
2723
public readonly onDidChangeEnvironment = this._onDidChangeEnvironment.event;
2824

2925
private readonly _onDidChangeEnvironments = new EventEmitter<DidChangeEnvironmentsEventArgs>();
3026
public readonly onDidChangeEnvironments = this._onDidChangeEnvironments.event;
31-
constructor(private readonly nativeFinder: NativePythonFinder, private readonly api: PythonEnvironmentApi) {
27+
28+
public readonly name: string;
29+
public readonly displayName: string;
30+
public readonly preferredPackageManagerId: string;
31+
public readonly description?: string;
32+
public readonly tooltip: string | MarkdownString;
33+
public readonly iconPath?: IconPath;
34+
35+
constructor(
36+
public readonly nativeFinder: NativePythonFinder,
37+
public readonly api: PythonEnvironmentApi
38+
) {
3239
this.name = 'pipenv';
3340
this.displayName = 'Pipenv';
34-
this.preferredPackageManagerId = 'ms-python.python:pip';
41+
this.preferredPackageManagerId = 'ms-python.python:pipenv';
3542
this.tooltip = new MarkdownString(PipenvStrings.pipenvManager, true);
3643
}
3744

38-
name: string;
39-
displayName: string;
40-
preferredPackageManagerId: string;
41-
description?: string;
42-
tooltip: string | MarkdownString;
43-
iconPath?: IconPath;
44-
4545
public dispose() {
46-
this.collection = [];
47-
this.fsPathToEnv.clear();
46+
this._onDidChangeEnvironment.dispose();
47+
this._onDidChangeEnvironments.dispose();
4848
}
4949

5050
quickCreateConfig?(): QuickCreateConfig | undefined {
@@ -65,29 +65,33 @@ export class PipenvManager implements EnvironmentManager {
6565
}
6666

6767
async refresh(_scope: RefreshEnvironmentsScope): Promise<void> {
68-
// To be implemented
68+
// TODO: Implement pipenv environment refresh
69+
// This should discover pipenv environments and update the collection
6970
}
7071

7172
async getEnvironments(_scope: GetEnvironmentsScope): Promise<PythonEnvironment[]> {
72-
// To be implemented
73+
// TODO: Implement pipenv environment discovery
74+
// This should return all discovered pipenv environments
7375
return [];
7476
}
7577

7678
async set(_scope: SetEnvironmentScope, _environment?: PythonEnvironment): Promise<void> {
77-
// To be implemented
79+
// TODO: Implement setting pipenv environment for a scope
80+
// This should update the selected environment for the given scope
7881
}
7982

8083
async get(_scope: GetEnvironmentScope): Promise<PythonEnvironment | undefined> {
81-
// To be implemented
84+
// TODO: Implement getting the selected pipenv environment for a scope
8285
return undefined;
8386
}
8487

8588
async resolve(_context: ResolveEnvironmentContext): Promise<PythonEnvironment | undefined> {
86-
// To be implemented
89+
// TODO: Implement resolving a path to a pipenv environment
8790
return undefined;
8891
}
8992

9093
async clearCache?(): Promise<void> {
91-
// To be implemented
94+
// TODO: Implement cache clearing
95+
// This should clear any cached environment discovery data
9296
}
9397
}

src/managers/pipenv/pipenvUtils.ts

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,59 @@
11
// Utility functions for Pipenv environment management
22

3+
import { traceInfo } from '../../common/logging';
4+
import { getWorkspacePersistentState } from '../../common/persistentState';
5+
import { ENVS_EXTENSION_ID } from '../../common/constants';
36
import { NativePythonFinder } from '../common/nativePythonFinder';
7+
import which from 'which';
48

5-
export class PipenvUtils {
6-
// Add static helper methods for pipenv operations here
9+
export const PIPENV_PATH_KEY = `${ENVS_EXTENSION_ID}:pipenv:PIPENV_PATH`;
10+
export const PIPENV_WORKSPACE_KEY = `${ENVS_EXTENSION_ID}:pipenv:WORKSPACE_SELECTED`;
11+
export const PIPENV_GLOBAL_KEY = `${ENVS_EXTENSION_ID}:pipenv:GLOBAL_SELECTED`;
12+
13+
let pipenvPath: string | undefined;
14+
15+
async function findPipenv(): Promise<string | undefined> {
16+
try {
17+
return await which('pipenv');
18+
} catch {
19+
return undefined;
20+
}
721
}
8-
export async function getPipenv(_native?: NativePythonFinder): Promise<string | undefined> {
9-
// Implementation to find and return the pipenv path
22+
23+
export async function clearPipenvCache(): Promise<void> {
24+
pipenvPath = undefined;
25+
}
26+
27+
export async function getPipenv(native?: NativePythonFinder): Promise<string | undefined> {
28+
if (pipenvPath) {
29+
return pipenvPath;
30+
}
31+
32+
const state = await getWorkspacePersistentState();
33+
pipenvPath = await state.get<string>(PIPENV_PATH_KEY);
34+
if (pipenvPath) {
35+
traceInfo(`Using pipenv from persistent state: ${pipenvPath}`);
36+
return pipenvPath;
37+
}
38+
39+
// Try to find pipenv in PATH
40+
const foundPipenv = await findPipenv();
41+
if (foundPipenv) {
42+
pipenvPath = foundPipenv;
43+
traceInfo(`Found pipenv in PATH: ${foundPipenv}`);
44+
return foundPipenv;
45+
}
46+
47+
// TODO: Add fallback to native finder when available
48+
if (native) {
49+
// Future enhancement: use native finder to locate pipenv
50+
traceInfo('Native finder available but not yet implemented for pipenv detection');
51+
}
52+
53+
traceInfo('Pipenv not found');
1054
return undefined;
1155
}
56+
57+
export class PipenvUtils {
58+
// Add static helper methods for pipenv operations here
59+
}

0 commit comments

Comments
 (0)