Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 not recognised for right item #459

Closed
schlomo opened this issue Oct 25, 2023 · 6 comments
Closed

Python3 not recognised for right item #459

schlomo opened this issue Oct 25, 2023 · 6 comments
Labels
🐛 bug Something isn't working

Comments

@schlomo
Copy link

schlomo commented Oct 25, 2023

Describe the bug

  1. I get error messages like this:
    image
  2. the right item doesn't show the Python version:
    image

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

And the result works:
image

@schlomo schlomo added the 🐛 bug Something isn't working label Oct 25, 2023
@kidonng
Copy link
Contributor

kidonng commented Oct 25, 2023

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.

@schlomo
Copy link
Author

schlomo commented Oct 25, 2023

@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?

@kidonng
Copy link
Contributor

kidonng commented Oct 25, 2023

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.

@JesseFarebro
Copy link

To add to this, no error should be raised if there's no Python binary.

@thatguy7
Copy link

I ran into this as well. Latest Ubuntu LTS comes with a python3 and no python binary.

So this affects not only MacOS.

It's no big deal to fix this on my system (suggestions are in this thread, a simple symlink does the trick as well), but it should be handled by tide as suggested by @JesseFarebro and @schlomo.

The case of python3 only or no python at all should not cause errors.

@schlomo
Copy link
Author

schlomo commented Dec 23, 2023

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants