Python3 not recognised for right item
schlomo opened this issue · 6 comments
Describe the bug
Steps to reproduce
change into a Python-relevant directory
Screenshots
Environment
Output of tide bug-report
:
fish version: 3.6.1
tide version: 6.0.1
term: xterm-256color
os: MacOS Ventura 13.6
terminal emulator: iTerm2
fish startup: $_tide_right_items[1]: |aws|
fisher plugins: jorgebucaran/fisher lgathy/google-cloud-sdk-fish-completion fabioantunes/fish-nvm edc/bass ilancosman/tide@v6
Additional context
I believe that the root cause is the fact that on recent MacOS python
is not available any more by default, but only python3
. OTOH, within a Python virtual env there might again be a python
binary.
While the _tide_remove_unusable_items
function does check for both python
and python3
, the _tide_item_python
function assumes that Python can always be called by python
and doesn't check for a python3
binary.
I was able to resolve the problem by amending _tide_item_python.fish
to read like this:
function _tide_python_version
type --query python && python --version || python3 --version
end
function _tide_item_python
if test -n "$VIRTUAL_ENV"
_tide_python_version | string match -qr "(?<v>[\d.]+)"
string match -qr "^.*/(?<dir>.*)/(?<base>.*)" $VIRTUAL_ENV
# pipenv $VIRTUAL_ENV looks like /home/ilan/.local/share/virtualenvs/pipenv_project-EwRYuc3l
# Detect whether we are using pipenv by looking for 'virtualenvs'. If so, remove the hash at the end.
if test "$dir" = virtualenvs
string match -qr "(?<base>.*)-.*" $base
_tide_print_item python $tide_python_icon' ' "$v ($base)"
else if contains -- "$base" virtualenv venv .venv env # avoid generic names
_tide_print_item python $tide_python_icon' ' "$v ($dir)"
else
_tide_print_item python $tide_python_icon' ' "$v ($base)"
end
else if path is .python-version Pipfile __init__.py pyproject.toml requirements.txt setup.py
_tide_python_version | string match -qr "(?<v>[\d.]+)"
_tide_print_item python $tide_python_icon' ' $v
end
end
Yep, it should check for python3
first.
Fish has an internal function __fish_anypython
for getting a proper Python binary. It was used by fish_update_completions
so probably won't go away any time soon.
For your case, you can simply alias python
to python3
:
function python
python3 $argv
end
This only works for Fish shell so won't break programs that find python
through $PATH
.
@kidonng yes and no. Yes, I tried that before and it works of course. However, my intention is that the default install of tide
just works on modern MacOS without any additional tinkering or setup. That is how we get a good user experience (or rather "unboxing experience").
Thanks for pointing out __fish_anypython
which is indeed part of the Fish distribution, however that is really expensive as it even runs xcode-select
so that I'd rather have a quick Fish-only implementation as I suggested.
In any case, I do believe that Fish and tide
should work well out of the box without requiring any local modification to work around shortcomings or bugs.
The bug I'm trying to address here is that the _tide_remove_unusable_items
function considers both python
and python3
whereas the _tide_item_python
function assumes that Python is always python
. This is an inconsistency between two different tide
functions that caused the bug for me.
@IlanCosman what do you think?
Sorry if I didn't make it clear, I'm not saying you should use a workaround (it is indeed a bug). I'm just pointing out a possible fix.
however that is really expensive as it even runs
xcode-select
It only checks stub /usr/bin/python3
if that's the only Python binary in your $PATH
, so if you have a separate Python (say /usr/local/bin/python3
via Homebrew), it doesn't do expensive xcode-select
check.