Skip to content

Commit 7551eb5

Browse files
authored
fix: streamline environment retrieval in venvManager and pyenvManager (microsoft#1157)
Fixes microsoft#610 ## Summary This PR enables pyenv-installed Python versions to appear as available base interpreters when creating new venv environments. ## Changes ### 1. Fixed bug in `PyEnvManager.getEnvironments()` The filter callback for the `'global'` scope was missing a return statement - it used braces without returning a value, causing it to always return an empty array: ```typescript // Before (buggy): return this.collection.filter((env) => { env.group === PYENV_VERSIONS; // Statement - doesn't return anything }); // After (fixed): return this.collection.filter((env) => env.group === PYENV_VERSIONS); ``` ### 2. Updated `VenvManager` to use API for aggregating global environments Changed from using only `baseManager.getEnvironments('global')` (which only returns system Python) to `api.getEnvironments('global')` which aggregates environments from ALL registered managers including pyenv, conda, etc. This change was applied to three locations in `venvManager.ts`: - `create()` method - when showing available base interpreters for venv creation - `resetGlobalEnv()` method - when resetting the global environment reference - `loadEnvMap()` method - when loading environment mappings ## Result When users create a new venv environment, pyenv-installed Python versions (those in the `PYENV_VERSIONS` group) will now appear alongside system Python installations as available base interpreters.
1 parent 5e4a386 commit 7551eb5

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

src/managers/builtin/venvManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export class VenvManager implements EnvironmentManager {
142142

143143
const venvRoot: Uri = Uri.file(await findParentIfFile(uri.fsPath));
144144

145-
const globals = await this.baseManager.getEnvironments('global');
145+
const globals = await this.api.getEnvironments('global');
146146
let result: CreateEnvironmentResult | undefined = undefined;
147147
if (options?.quickCreate) {
148148
// error on missing information

src/managers/pyenv/pyenvManager.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ export class PyEnvManager implements EnvironmentManager, Disposable {
9696
}
9797

9898
if (scope === 'global') {
99-
return this.collection.filter((env) => {
100-
env.group === PYENV_VERSIONS;
101-
});
99+
return this.collection.filter((env) => env.group === PYENV_VERSIONS);
102100
}
103101

104102
if (scope instanceof Uri) {

0 commit comments

Comments
 (0)