Repository navigation
fix(poetry-env): preserve venv in project subdirectories - #13932
Conversation
Keep the active environment while navigating ordinary project children, but switch when entering a nested Poetry project. Use a path-component boundary so similarly named sibling projects are not mistaken for subdirectories. Fixes ohmyzsh#12377
|
Heads-up while this is in flight: if [[ $poetry_active -eq 1 ]] && { [[ $in_poetry_dir -eq 0 ]] || [[ "$PWD" != "$poetry_dir"* ]]; }; then
Reproduced on current master with two sibling projects
Suggesting the component-boundary form rather than a prefix test — the same shape I landed for #14006 and used in #14021: local project_dir="${poetry_dir%/}"
if [[ "$PWD" != "$project_dir" && "$PWD" != "$project_dir"/* ]]; thenTruth table,
Not posting a competing patch since this PR is already open on the file — just flagging it so the fix can cover both cases if you want to fold it in. |
|
Thanks for the detailed boundary table. The existing PR head already used the component-aware |
|
You are right about the scope, and thanks for chasing it down instead of letting it slide — my note mis-attributed the bug. The string-prefix slip is in master's I have re-run the same stubbed-
I also exercised the containment condition from Nothing outstanding from me on this one. |
|
Clarification: The string-prefix bug I initially mentioned is in master's |
robbyrussell
left a comment
There was a problem hiding this comment.
Nice catch, and thanks for the writeup.
This one's more annoying than it looks in the diff... on master, walking into any ordinary subdirectory of your own project killed the venv, because in_poetry_dir only goes to 1 when the current directory itself has both marker files. So the fix isn't really about sibling directories, it's about the most normal thing you can do in a project.
I ran the decision table against both branches. Subdirectories stay active now, nested projects switch properly, and a project at / still behaves. Three of those cases were wrong on master, so this fixes more than it advertises.
One tiny thing, not for this PR: venv_dir on line 17 still isn't local, so it leaks into the global namespace. Pre-existing, and I'll pick it up separately.
Merging. Thanks!
🤖 Co-authored with Claude Code
|
Follow-up on the |
venv_dir was assigned without `local`, so every activation left it in the caller's scope. The sibling uv-env plugin already declares it `local`. Noticed while reviewing #13932. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
* fix(poetry-env): preserve venv in project subdirectories Keep the active environment while navigating ordinary project children, but switch when entering a nested Poetry project. Use a path-component boundary so similarly named sibling projects are not mistaken for subdirectories. Fixes ohmyzsh#12377 * fix(poetry-env): normalize active project root
* fix(poetry-env): preserve venv in project subdirectories Keep the active environment while navigating ordinary project children, but switch when entering a nested Poetry project. Use a path-component boundary so similarly named sibling projects are not mistaken for subdirectories. Fixes ohmyzsh#12377 * fix(poetry-env): normalize active project root
* fix(poetry-env): preserve venv in project subdirectories Keep the active environment while navigating ordinary project children, but switch when entering a nested Poetry project. Use a path-component boundary so similarly named sibling projects are not mistaken for subdirectories. Fixes ohmyzsh#12377 * fix(poetry-env): normalize active project root
* fix(poetry-env): preserve venv in project subdirectories Keep the active environment while navigating ordinary project children, but switch when entering a nested Poetry project. Use a path-component boundary so similarly named sibling projects are not mistaken for subdirectories. Fixes ohmyzsh#12377 * fix(poetry-env): normalize active project root
Standards checklist:
Changes:
project2is not treated as a child ofproject.Fixes #12377.
Testing:
zsh -n.zsh -fnavigation smoke test covering project activation, ordinary and incomplete nested directories, a valid nested Poetry project, its child, returning to the parent project, a same-prefix sibling project, paths with spaces, and leaving the project tree.origin/master; all eight navigation scenarios pass with this branch.Other comments:
No aliases are introduced, so the alias-use-case checklist item is not applicable.
AI-assisted: Codex analyzed the existing state transitions, drafted the condition, and assembled the test matrix. The final condition was cross-checked against the reported regression and edge cases, and the tests above were run locally.
cc @carlosala