Repository navigation
Commit dd372a8
authored
Avoid selecting no-Python Conda base on startup (#1707)
## Context
Fixes
[#1689](#1689).
The reporter uses Conda/Micromamba with:
- `python-envs.defaultEnvManager` set to Conda
- a valid named environment (`c8`) configured through
`python.defaultInterpreterPath`
- a Micromamba `base` prefix that legitimately does not contain Python
On startup, the workspace-specific environment resolves successfully to
`c8`, but global selection is resolved separately (and may be deferred).
The issue log shows that the global path selected the no-Python base
through `defaultEnvManager`:
```text
Changed environment from undefined to base (no-python) for: global
[interpreterSelection] global: base (no-python) (source: defaultEnvManager)
```
Passing that automatically selected environment to
`CondaEnvManager.set()` invokes the same no-Python check used for
explicit user selection, producing the modal `No python found in the
selected conda environment: base`.
This can vary by workspace because Conda's global selection is stored in
VS Code workspace state. A workspace with a previously persisted usable
selection does not take the implicit base fallback, while a fresh
workspace commonly does.
## Root cause
When no persisted global Conda selection exists,
`CondaEnvManager.loadEnvMap()` unconditionally uses the environment
named `base` as its implicit global fallback. A no-Python Conda prefix
is valid for discovery and display in the Environment Manager, but it is
not a usable Python interpreter and should not be selected
automatically.
The explicit-selection flow is different: when a user intentionally
selects a no-Python Conda environment, the existing modal offers to
install Python into it. That behavior should remain available.
## Fix
Only assign `base` as the implicit global fallback when it contains
Python:
```ts
const base = this.findEnvironmentByName('base');
if (base?.version !== 'no-python') {
this.globalEnv = base;
}
```
With an empty Micromamba base and no persisted global selection,
`globalEnv` remains undefined. Initial selection therefore never passes
the no-Python base into the modal-producing `set()` path.
## Behavior preserved
- A valid base environment containing Python remains the implicit global
fallback.
- Explicitly persisted no-Python selections are restored, preserving
user intent.
- Explicitly selecting a no-Python environment still presents the
install-Python modal.
- No-Python environments remain in the discovered collection and visible
in the Environment Manager.
- Workspace-specific Conda selections, named/prefix environments,
discovery, settings, and persistence formats are unchanged.
- Interpreter priority resolution is unchanged; this PR intentionally
prevents the invalid implicit selection rather than changing
`defaultEnvManager` precedence.
If no usable persisted global selection exists and base has no Python,
the effective global environment is now undefined instead of an unusable
interpreter.
## Testing
Added coverage for all relevant initialization boundaries:
- no-Python base is not used as the implicit global fallback
- base containing Python remains the implicit global fallback
- explicitly persisted no-Python base remains selected
Validation performed:
- `npm run compile-tests`
- focused Conda initialization, global-selection, and
interpreter-selection unit suites (57 passing)1 parent dbb10ec commit dd372a8
2 files changed
Lines changed: 45 additions & 2 deletions
File tree
- src
- managers/conda
- test/managers/conda
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
509 | 509 | | |
510 | 510 | | |
511 | 511 | | |
512 | | - | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
513 | 516 | | |
514 | 517 | | |
515 | 518 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
40 | | - | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
| |||
101 | 103 | | |
102 | 104 | | |
103 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
104 | 144 | | |
105 | 145 | | |
106 | 146 | | |
| |||
0 commit comments