MichaelAquilina / zsh-autoswitch-virtualenv

🐍 ZSH plugin to automatically switch python virtualenvs (including pipenv and poetry) as you move between directories
GNU General Public License v3.0
507 stars 80 forks source link

Invalid warning when going into GitLab directory #161

Closed stevenxxiu closed 2 years ago

stevenxxiu commented 2 years ago

Issue Details

When I go in the gitlab directory the following invalid warning always shows up:

$ cd /usr/share/webapps/gitlab/
Unable to find simple"
verify_ssl = true

[dev-packages]

[packages]
docutils = "==0.13.1"

[requires]
python_version = "3.4" virtualenv
If the issue persists run rmvenv && mkvenv in this directory
Unable to find simple"
verify_ssl = true

[dev-packages]

[packages]
docutils = "==0.13.1"

[requires]
python_version = "3.4" virtualenv
If the issue persists run rmvenv && mkvenv in this directory

The file that causes this is:

$ cat Pipfile
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
docutils = "==0.13.1"

[requires]
python_version = "3.4"

Operating System (uname -a)

Arch Linux

$ uname -a
Linux arch 5.14.8-arch1-1 #1 SMP PREEMPT Sun, 26 Sep 2021 19:36:15 +0000 x86_64 GNU/Linux

zsh version (zsh --version)

$ zsh --version
zsh 5.8 (x86_64-pc-linux-gnu)

autoswitch-virtualenv version

echo "$AUTOSWITCH_VERSION"
3.3.1

How is zsh-autoswitch-virtualenv installed?

stevenxxiu commented 2 years ago

I managed to make an ugly temporary fix for this now. Put this in at the end of ~/.zshrc:

# Disable `autoswitch_virtualenv` in subdirectories it doesn't work in
functions[check_venv_orig]=$functions[check_venv]
function check_venv() {
  if [[ $PWD/ = /usr/share/webapps/gitlab/* ]]; then
    return
  fi
  check_venv_orig "$@"
}
MichaelAquilina commented 2 years ago

What does this directly contain? Is it an installation of gitlab? Is there any way you can reproduce this in a docker container so that I can test and debug?

stevenxxiu commented 2 years ago

Ah I debugged it a bit and think I get the issue. The bug happens when I don't have pipenv installed, and the directory has a Pipfile in it. Its contents don't really matter, but fyi it's shown in my first comment.

When this happens, the first condition below in autoswitch_virtualenv.plugin.zsh doesn't evaluate to true, and the else part is ran instead. This isn't really valid:

if [[ "$venv_path" == *"/Pipfile" ]] && type "pipenv" > /dev/null; then
    if _activate_pipenv; then
        return
    fi
elif [[ "$venv_path" == *"/poetry.lock" ]] && type "poetry" > /dev/null; then
    if _activate_poetry; then
        return
    fi
else
    local switch_to="$(<"$venv_path")"
    _maybeworkon "$(_virtual_env_dir "$switch_to")" "virtualenv"
    return
fi

And yes, it's just an installation of gitlab. It happens in any directory with a Pipfile in it, if pipenv isn't installed.

The same could be set if the directory has a poetry.lock in it, and poetry isn't installed.

MichaelAquilina commented 2 years ago

Fixed in 3.3.2

Thanks for the fix @stevenxxiu !