justinmayer / virtualfish

Fish shell tool for managing Python virtual environments
MIT License
1.06k stars 100 forks source link

Bug with ls --details with macos provided python #195

Closed etienned closed 3 years ago

etienned commented 3 years ago

Issue

When running vf ls --details I received this error:

Python 2.7.16
test: Missing argument at index 2

/usr/local/lib/python3.8/site-packages/virtualfish/virtual.fish (line 718): 
    if test $version_to_compare[1] -lt $reference_version[1]
       ^
in function '__vfsupport_compare_py_versions' with arguments '3.8.6'
    called on line 344 of file /usr/local/lib/python3.8/site-packages/virtualfish/virtual.fish
in function '__vf_ls' with arguments '--details'
    called on line 1 of file /usr/local/lib/python3.8/site-packages/virtualfish/virtual.fish
in function 'vf' with arguments 'ls --details'

(Type 'help test' for related documentation)
test: Missing argument at index 2

etc. for each test in the function

After digging a little bit the problem seems to come from the Apple provided python that, when called with -V to get the version, return the version string to stderr instead of sdtout (that's why we see the version above the error). I know that the real problem is with the macos' python but we can't change it. So what I did on line https://github.com/justinmayer/virtualfish/blob/master/virtualfish/virtual.fish#L343 is to redirect stderr to stdout like this:

set env_python_version ("$VIRTUALFISH_HOME/$p" -V 2>&1 | string split " ")[2]

I'm definitely not sure it's the best solution but it works in my case.

justinmayer commented 3 years ago

✅ I am using Python version 3.6 or higher.

Well, the reason the above item appears when filing an issue here is that Python 3.6+ is required, which as you can imagine precludes any expectations that VirtualFish will function correctly on Python 2.7, much less the wonky macOS version of Python 2.7.

I'm not sure what the best solution is either, but as a first step, I highly recommend using a supported version of Python. 😊

etienned commented 3 years ago

In general I'm using the current python version but I have a few old projects where it's not really possible or doesn't have sens to migrate them to python 3. Until recently those old projects, locally, were using the python 2 brew version and all was well, but now brew removed python 2, so they fallback at using the macos version.

Maybe the good solution is to reinstall a decent python 2 version with pyenv or asdf but that's an overhead for me as I'm using those virtualenv mostly to have code completion, access to code, etc. in my editor, the real projects are in Docker containers. Or another solution is to configure my linter/etc. to work with Docker, but I'm not a fan of this solution. I'll see...

Thanks for your answer!