darvid / zsh-poetry

🐚 Simple ZSH plugin for automatically activating and deactivating Poetry-created virtualenvs. 🐍
MIT License
75 stars 14 forks source link

Activate when entering subdirs #12

Open infotroph opened 2 years ago

infotroph commented 2 years ago

Current version only activates the venv when you enter the project root directory, and not if you cd directly from outside the project into a subdirectory.

This patch corrects that by checking for a pyproject.toml in the current pwd or any ancestor of it.

urbandw commented 2 years ago

I like this change! One thing I'm noticing is that even though you can cd into a project subdir and activate the correct venv, you still have to come into a project directory from above, and cannot cd directly between projects. E.g.

Works:

cd proj1_top_dir/sub1
cd ../..
cd proj2_top_dir/sub2

Does not work:

cd proj1_top_dir/sub1
cd ../../proj2_top_dir/sub2

Or, forgetting subdirs:

Works

cd proj1_top_dir
cd ..
cd proj2_top_dir

Does not work

cd proj1_top_dir
cd ../proj2_top_dir

This is not a huge inconvenience, but seemed worth noting.

infotroph commented 2 years ago

I and @urbandw are debugging this in another channel, and it appears the behavior he's seeing happens when moving between a Poetry project and a pyenv-virtualenv project, but not when moving between two Poetry projects. We'll report back here when we have an MRE.