justinmayer / virtualfish

Fish shell tool for managing Python virtual environments
MIT License
1.07k stars 101 forks source link

`vf upgrade` yields error when virtual environment does not exist #239

Open ammgws opened 1 year ago

ammgws commented 1 year ago
>vf upgrade doesnotexist
doesnotexist is broken. Rebuilding…
fish: Unknown command: /home/ammgws/.local/share/virtualenvs/doesnotexist/bin/python
in command substitution
    called on line 603 of file /usr/lib/python3.11/site-packages/virtualfish/virtual.fish
in function '__vf_upgrade' with arguments 'doesnotexist'
    called on line 1 of file /usr/lib/python3.11/site-packages/virtualfish/virtual.fish
in function 'vf' with arguments 'upgrade doesnotexist'
/usr/lib/python3.11/site-packages/virtualfish/virtual.fish (line 603): Unknown command
            set -l old_py_fv ($venv_path/bin/python -V | string split " ")[2]
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
in function '__vf_upgrade' with arguments 'doesnotexist'
    called on line 1 of file /usr/lib/python3.11/site-packages/virtualfish/virtual.fish
in function 'vf' with arguments 'upgrade doesnotexist'
Argument is not a number: '.'
/usr/lib/python3.11/site-packages/virtualfish/virtual.fish (line 611): 
            if test "$old_py_mv" -ne "$new_py_mv"
               ^
in function '__vf_upgrade' with arguments 'doesnotexist'
    called on line 1 of file /usr/lib/python3.11/site-packages/virtualfish/virtual.fish
in function 'vf' with arguments 'upgrade doesnotexist'
Upgrading doesnotexist from  to 3.11.5
ln: failed to create symbolic link '/home/ammgws/.local/share/virtualenvs/doesnotexist/bin/python': No such file or directory
ln: failed to create symbolic link '/home/ammgws/.local/share/virtualenvs/doesnotexist/bin/python3': No such file or directory
ln: failed to create symbolic link '/home/ammgws/.local/share/virtualenvs/doesnotexist/bin/python3.11': No such file or directory
find: ‘/home/ammgws/.local/share/virtualenvs/doesnotexist’: No such file or directory
rm: missing operand
Try 'rm --help' for more information.

Expected behaviour

Check if valid venv and exit earlier. Especially since the vf upgrade --help text does say it's for existing venvs: "Purpose: Upgrades existing virtual environment(s)"

Perhaps add a check around here or in the following for loop: https://github.com/justinmayer/virtualfish/blob/3f0de6e9a41d795237beaaa04789c529787906d3/virtualfish/virtual.fish#L551