Summary
- This doc lists the tasks required to get pipenv integrated as an EnvironmentManager
Files & methods to implement
-
Registration/activation (src/managers/pipenv/main.ts)
- Implement
registerPipenvFeatures(nativeFinder: NativePythonFinder, disposables: Disposable[]). - Use the same registration pattern as
pyenvandpoetry(get Python API, detect pipenv, instantiate manager,api.registerEnvironmentManager(mgr), push disposables).
- Implement
-
Utilities (src/managers/pipenv/pipenvUtils.ts)
getPipenv(native?: NativePythonFinder)— locate thepipenvbinary (persisted override, env vars, which, ornativeFinderfallback).refreshPipenv(hardRefresh, nativeFinder, api, manager)— discover pipenv environments (workspace Pipfiles, native finder info, or scanningWORKON_HOME).resolvePipenvPath(fsPath, nativeFinder, api, manager)— resolve a path or Uri to a PythonEnvironment.nativeToPythonEnv(nativeInfo, api, manager, pipenvPath)— convert native discovery info into aPythonEnvironment:- set
execInfo.run.executable(usepipenv --pywhen possible) andexecInfo.shellActivation(see activation strategy below),sysPrefix, display metadata.
- set
-
Manager implementation (src/managers/pipenv/pipenvManager.ts)
- Implement class like
PoetryManager/PyEnvManager:- fields:
collection: PythonEnvironment[],fsPathToEnv: Map<string, PythonEnvironment>,globalEnv. - event emitters:
_onDidChangeEnvironments,_onDidChangeEnvironmentand public events. - constructor(nativeFinder, api) and metadata properties (
name,displayName,preferredPackageManagerId,tooltip). - lifecycle methods:
initialize(),getEnvironments(),refresh(),get(),set(),resolve(),clearCache(). - helpers:
loadEnvMap(),fromEnvMap(uri),findEnvironmentByPath(fsPath).
- fields:
- Use
api.createPythonEnvironmentItem()to createPythonEnvironmentitems.
- Implement class like
-
Exec info & activation behavior
- Resolve a Python executable using
pipenv --pywhen possible and setexecInfo.run.executable. - Activation options:
- Provide
shellActivationmapping with'unknown'fallback. For example{ executable: 'pipenv', args: ['shell'] }for activation. - Provide
activatedRunorrunthat uses resolved python (/path/to/venv/bin/python) or fallback topipenv run python(e.g., run.executable = 'pipenv', args = ['run', 'python']). - Set
shellDeactivationtoexit/deactivatewhere appropriate.
- Provide
- Resolve a Python executable using
-
Workspace mapping & persistence
- Implement per-workspace persistent selection (get/set persisted environment for workspace & global), similar to
pyenvandpoetryutils. - Implement logic in
loadEnvMap()to pick project-specific envs (Pipfile location), global fallback, and mapping to projects viaapi.getPythonProjects().
- Implement per-workspace persistent selection (get/set persisted environment for workspace & global), similar to
-
Package-manager (required)
- Implement a dedicated Pipenv
PackageManagerand register it viaapi.registerPackageManager(...). - Use package manager id:
ms-python.python:pipenv. - Implement install/uninstall by invoking
pipenv install/pipenv uninstalland firing package-change events.
- Implement a dedicated Pipenv
-
Tests
- Add unit tests (mocking
NativePythonFinderandgetPythonApi) for detection, discovery,resolve()and mapping. - Add integration tests that run
pipenv --py/pipenv --venvbehavior using a test fixture if desired.
- Add unit tests (mocking
-
Localization & assets
- Add localized strings (e.g.,
PipenvStrings) for messages and progress titles. - Add icon(s) if required and reference via
iconPath.
- Add localized strings (e.g.,
-
Documentation
- Update README/docs to include Pipenv support and configuration/setting notes.
-
CI & linting
- Run tests and fix TypeScript compile/lint issues (unused args, correct imports). Ensure
main.tsregistration usesapi.registerEnvironmentManagerlike other managers.
Minimal viable implementation (priority)
- Fix
main.tsto implementregisterPipenvFeatures(...)and register the manager (so the manager is known to the extension). - Implement
getPipenv()(detect pipenv binary) andnativeToPythonEnv()(at minimum obtain python path usingpipenv --pyand return a validPythonEnvironmentviaapi.createPythonEnvironmentItem). - Implement manager skeleton (constructor, event emitters,
initialize(),getEnvironments()andresolve()that uses utils above) and wire registration. - Add a simple integration test and run the extension in dev to validate detection.
Questions / decisions (resolved)
-
preferredPackageManagerId: create a distinct
pipenvpackage manager id:ms-python.python:pipenv. -
Activation approach: use
pipenv shellfor terminal activation (interactive terminals) andpipenv runas the fallback for non-interactive runs /activatedRun. -
Scope of discovery: discover both global pipenv virtualenvs and workspace-local pipenv environments (projects with Pipfile).
-
Create/quickCreate: implement
create()usingpipenv installto create environments and install requested packages as part of quick-create. -
Windows/PowerShell specifics: keep
shellActivationmapping with'unknown'fallback for now; revisit if issues surface. -
Tests: (deferred).