From f61f623b5b7116ba7f969d6fd224b4bf02fdb615 Mon Sep 17 00:00:00 2001 From: Developer Date: Wed, 25 Jun 2025 00:51:17 +0100 Subject: [PATCH] fix(poetry-env): handle in-project virtual environments when path returns "." When Poetry is configured with virtualenvs.in-project = true, poetry env info --path returns "." instead of the full path. This causes the plugin to fail with "no such file or directory: ./bin/activate". Changes: - Handle case where poetry returns "." by converting to $PWD/.venv - Add safety check to ensure activate script exists before sourcing - Maintain backward compatibility with existing setups Fixes issue with in-project virtual environments used in monorepos and git worktrees. --- plugins/poetry-env/poetry-env.plugin.zsh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/poetry-env/poetry-env.plugin.zsh b/plugins/poetry-env/poetry-env.plugin.zsh index dca388dfe..6fff2148b 100644 --- a/plugins/poetry-env/poetry-env.plugin.zsh +++ b/plugins/poetry-env/poetry-env.plugin.zsh @@ -15,7 +15,12 @@ _togglePoetryShell() { # Activate the environment if in a Poetry directory and no environment is currently active if [[ $in_poetry_dir -eq 1 ]] && [[ $poetry_active -ne 1 ]]; then venv_dir=$(poetry env info --path 2>/dev/null) - if [[ -n "$venv_dir" ]]; then + # Handle case where poetry returns "." for in-project virtual environments + if [[ "$venv_dir" == "." ]]; then + venv_dir="$PWD/.venv" + fi + # Only proceed if venv_dir is set and the activate script exists + if [[ -n "$venv_dir" && -f "${venv_dir}/bin/activate" ]]; then export poetry_active=1 export poetry_dir="$PWD" source "${venv_dir}/bin/activate"