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
527 stars 82 forks source link

Not work with Pipenv #79

Closed posquit0 closed 5 years ago

posquit0 commented 5 years ago

Issue Details

Please provide the following details when opening an issue:

Operating System (uname -a)

Darwin jina 18.2.0 Darwin Kernel Version 18.2.0: Mon Nov 12 20:24:46 PST 2018; root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64

zsh version (zsh --version)

zsh 5.7.1 (x86_64-apple-darwin18.2.0)

autoswitch-virtualenv version (echo "$AUTOSWITCH_VERSION")

1.8.0

How is zsh-you-should-use installed?

Steps to reproduce the issue

# `Pipfile` exists in `my-project` directory and already create virtualenv with `pipenv shell` command.
$ cd my_project
Unable to find .venv virtualenv
If the issue persists run rmvenv && mkvenv in this directory

gist link to your zshrc

### Plugin: Python Auto Switch Virtualenv {{{
  # Automatically switch python virtualenvs as you move between directories
  # Commands: mkvenv, rmvenv
  zplug "MichaelAquilina/zsh-autoswitch-virtualenv"
### }}}
MichaelAquilina commented 5 years ago

You mention in your issue you have a Pipefile. Is this a typo in the issue or do you have that actual file locally?

Either way, could you provide the ls -lA output of that directory?

posquit0 commented 5 years ago

Sorry, it's jsut typo. I'm using following pipenv option.

# Creating the virtualenv inside project’s directory
export PIPENV_VENV_IN_PROJECT=1

And I tried with/without the option. But failed both.

.rw-r--r--    0 posquit0  9 Feb 19:22 .env
.rw-r--r--    0 posquit0  9 Feb 19:22 .env.example
drwxr-xr-x    - posquit0 10 Feb  0:59 .git
.rw-r--r-- 2.5k posquit0  9 Feb 20:03 .gitignore
drwxr-xr-x    - posquit0  9 Feb 18:58 .venv
.rw-r--r--    0 posquit0 10 Feb  0:01 docker-compose.yml
.rw-r--r-- 1.6k posquit0 10 Feb  0:24 Dockerfile
.rwxr-xr-x  538 posquit0  9 Feb 19:01 manage.py
.rw-r--r--  195 posquit0  9 Feb 19:44 Pipfile
.rw-r--r-- 4.4k posquit0  9 Feb 19:44 Pipfile.lock
.rw-r--r--  510 posquit0 10 Feb  0:00 README.md
drwxr-xr-x    - posquit0 10 Feb  0:56 server
MichaelAquilina commented 5 years ago

Sorry about the delayed response! Could you also provide the output for the following commands within the directory:

cat .venv PIPENV_IGNORE_VIRTUALENVS=1 pipenv --venv

posquit0 commented 5 years ago

I redacted the detailed path for security. :)

> pwd
/Users/posquit0/${my-project-path}
> cat .venv
cat: .venv: Is a directory
> PIPENV_IGNORE_VIRTUALENVS=1 pipenv --venv
/Users/posquit0/${my-project-path}/.venv
posquit0 commented 5 years ago

More info about PIPENV_VENV_IN_PROJECT https://pipenv.readthedocs.io/en/latest/advanced/#pipenv.environments.PIPENV_VENV_IN_PROJECT

MichaelAquilina commented 5 years ago

ah, there is deff a problem with your .venv. This plugin uses .venv to autoswitch. I wonder if that is interfering with the check process.

Would you mind ls -lAing the contents of that directory? Is it used by pip because of your PIPENV_VENV_IN_PROJECT?

If you remove .venv using mv .venv ~/.venvbak does autoswitching then start working for you?

posquit0 commented 5 years ago

First, thanks to your support and awesome plugin. :)

This is the contents of .venv:

> ls -la .venv
.rw-r--r-- 36 posquit0  9 Feb 18:40 .project
lrwxr-xr-x 80 posquit0  9 Feb 18:40 .Python -> /usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/Python
drwxr-xr-x  - posquit0 11 Feb  3:38 bin
drwxr-xr-x  - posquit0 10 Feb 23:01 include
drwxr-xr-x  - posquit0  9 Feb 18:40 lib
drwxr-xr-x  - posquit0  9 Feb 18:58 src

After mv .venv .venv.bak and disable PIPENV_VENV_IN_PROJECT:

> pipenv shell
Loading .env environment variables…
Creating a virtualenv for this project…
Pipfile: /Users/posquit0/${my-project-path}/Pipfile
Using /usr/local/bin/python3 (3.7.2) to create virtualenv…
⠴ Creating virtual environment...Using base prefix '/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7'
New python executable in /Users/posquit0/.local/share/virtualenvs/admin-Gr9yJNos/bin/python3.7
Also creating executable in /Users/posquit0/.local/share/virtualenvs/admin-Gr9yJNos/bin/python
Installing setuptools, pip, wheel...
done.
Running virtualenv with interpreter /usr/local/bin/python3

✔ Successfully created virtual environment!
Virtualenv location: /Users/posquit0/.local/share/virtualenvs/admin-Gr9yJNos
Launching subshell in virtual environment…
 . /Users/posquit0/.local/share/virtualenvs/admin-Gr9yJNos/bin/activate
Unable to find admin-Gr9yJNos virtualenv
If the issue persists run rmvenv && mkvenv in this directory

I know this plugin uses .venv because I used this plugin very well when I didn't use pipenv. However, I saw following message in README.md.

This plugin will also detect and auto activate virtualenvs made with pipenv.

So, I expected that this plugin should work with and without PIPENV_VENV_IN_PROJECT option. But this doesn't work in both cases.

In addition, Pipenv documented like below. I think this option should be considered to support Pipenv.

You might want to set export PIPENV_VENV_IN_PROJECT=1 in your .bashrc/.zshrc (or any shell configuration file) for creating the virtualenv inside your project’s directory, avoiding problems with subsequent path
changes.
MichaelAquilina commented 5 years ago

This deff seems like a bug in this plugin. Unfortunately I probably have not detected it as I do not use Pipenv myself (it was added as a PR by an external contributor).

I'll give the code a better look based on the information you posted to me and get back to you with any next steps that would be needed.

If you want to be adventurous I would suggest you try debug the issue yourself (first step would be to add echo statements where appropriate :))

MichaelAquilina commented 5 years ago

I've found the issue and will open a PR once I've found a simple fix for it. Will tag you once it's open @posquit0