Commit 25d851c
Fix PyEnv Windows path calculation for environment grouping (#1210)
- [x] Fix `nativeToPythonEnv` in `pyenvUtils.ts` - extract `getPyenvDir`
helper
- [x] Address reviewer feedback: use `PYENV_ROOT` env var as primary
source, revert 3-levels-up to 2-levels-up (old behavior was correct for
pyenv-win since versions live under `~/.pyenv/pyenv-win/versions/`)
- [x] Fix POSIX test to use absolute path with `path.sep`
- [x] Add test for `PYENV_ROOT` preference
- [x] Validate changes compile and all 583 tests pass (no regressions)
- [x] Run code review and security scan
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>PyEnv: Windows path calculation bug causes environment
grouping to fail</issue_title>
> <issue_description>## Problem
>
> In `pyenvUtils.ts`, the calculation of `versionsPath` and `envsPaths`
is incorrect on Windows due to the pyenv-win directory structure.
>
> ### Current Code
> ```typescript
> // pyenvUtils.ts L128-130
> const versionsPath =
normalizePath(path.join(path.dirname(path.dirname(pyenv)), 'versions'));
> const envsPaths = normalizePath(path.join(path.dirname(versionsPath),
'envs'));
> ```
>
> ### Issue
> On Windows, pyenv is located at `~/.pyenv/pyenv-win/bin/pyenv.bat`.
The current logic calculates:
> - `path.dirname(path.dirname(pyenv))` → `~/.pyenv/pyenv-win` ❌
> - Should be `~/.pyenv` to find `versions` folder properly
>
> This causes:
> 1. Environment grouping (`PYENV_VERSIONS` vs `PYENV_ENVIRONMENTS`) to
fail
> 2. Environments not being associated with the correct manager
>
> ### PET Server Reference
> The PET server handles this correctly with platform-specific code in
`pet-pyenv/src/environment_locations.rs`:
> ```rust
> #[cfg(windows)]
> pub fn get_home_pyenv_dir(env_vars: &EnvVariables) -> Option<PathBuf>
{
> let home = env_vars.home.clone()?;
> Some(norm_case(home.join(".pyenv").join("pyenv-win")))
> }
> ```
>
> ### Suggested Fix
> Add Windows-specific handling when calculating the versions and envs
paths:
> ```typescript
> const pyenvDir = isWindows()
> ? path.dirname(path.dirname(path.dirname(pyenv))) // Go up 3 levels on
Windows
> : path.dirname(path.dirname(pyenv));
> const versionsPath = normalizePath(path.join(pyenvDir, 'versions'));
> ```
>
> ### Affected File
> `src/managers/pyenv/pyenvUtils.ts`</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
<!-- START COPILOT CODING AGENT SUFFIX -->
- Fixes #1180
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>1 parent de4493f commit 25d851c
File tree
2 files changed
+62
-2
lines changed- src
- managers/pyenv
- test/managers/pyenv
2 files changed
+62
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
26 | 41 | | |
27 | 42 | | |
28 | 43 | | |
| |||
174 | 189 | | |
175 | 190 | | |
176 | 191 | | |
177 | | - | |
178 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
179 | 195 | | |
180 | 196 | | |
181 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
0 commit comments