Commit 7b6a321
Fix Poetry environments misidentified as Venv (#268)
Poetry environments in cache directories were reported as `kind =
'Venv'` instead of `'Poetry'` when workspace directories weren't
configured or `pyproject.toml` wasn't in the workspace.
**Example:**
```
Path: /Users/user/Library/Caches/pypoetry/virtualenvs/nestedpoetry-yJwtIF_Q-py3.11/
Before: kind = 'Venv'
After: kind = 'Poetry'
```
## Changes
**Root cause:** `Poetry::try_from()` only checked cached environments
from `find()`. Uncached environments returned `None`, falling through to
Venv locator.
**Solution:** Added fallback path-based detection when cache lookup
fails:
```rust
fn is_poetry_environment(path: &Path) -> bool {
// Check path contains "pypoetry/virtualenvs"
// Validate directory name matches: {name}-{8-char-hash}-py{version}
// Regex: ^.+-[A-Za-z0-9_-]{8}-py.*$
}
```
Updated `try_from()` to check path pattern after cache miss, creating
Poetry environment if pattern matches. Works across platforms (macOS,
Linux, Windows) without filesystem I/O.
## Testing
Added 8 unit tests covering:
- Platform-specific paths (macOS/Linux/Windows cache directories)
- Pattern variations (with/without version suffix)
- Negative cases (non-Poetry paths, wrong hash length)
- Real-world examples from bug report
<!-- START COPILOT CODING AGENT SUFFIX -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>Bug: Poetry path returned as type "venv"</issue_title>
> <issue_description>you can see from the path it is in the poetry
folder but the type comes back as venv instead
>
> <img width="1071" height="403" alt="Image"
src="https://github.com/user-attachments/assets/f73acbcb-54e6-4849-a03b-af2a0b589a08"
/></issue_description>
>
> <agent_instructions>The issue is that poetry envs sometimes get
reported as venvs.
> Analyse and perform root causes analysis before attempting to fix this
issue.
> Once you have determine the root cause use that information to create
tests and then try to fix the issue and verify whether the tests pass.
> </agent_instructions>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
- Fixes #267
- Fixes #273
-
<!-- START COPILOT CODING AGENT TIPS -->
---
✨ Let Copilot coding agent [set things up for
you](https://github.com/microsoft/python-environment-tools/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: DonJayamanne <1948812+DonJayamanne@users.noreply.github.com>
Co-authored-by: Don Jayamanne <don.jayamanne@outlook.com>1 parent 47e2c23 commit 7b6a321
File tree
3 files changed
+160
-3
lines changed- crates
- pet-conda/tests/unix/conda_env_without_manager_but_found_in_history/env_python_3/conda-meta
- pet-poetry
- src
- tests
3 files changed
+160
-3
lines changedLines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | | - | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
31 | 65 | | |
32 | 66 | | |
33 | 67 | | |
| |||
153 | 187 | | |
154 | 188 | | |
155 | 189 | | |
| 190 | + | |
| 191 | + | |
156 | 192 | | |
157 | 193 | | |
158 | 194 | | |
| |||
162 | 198 | | |
163 | 199 | | |
164 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
165 | 219 | | |
166 | 220 | | |
167 | 221 | | |
| |||
| 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 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
0 commit comments