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

Don't add python bin to PATH when executing pip-installed commands #1774

Open
juhoautio opened this issue Aug 19, 2024 · 1 comment
Open

Comments

@juhoautio
Copy link

juhoautio commented Aug 19, 2024

Is your feature request related to a problem? Please describe

I've installed some python CLI commands with pip. My pip is wrapped by asdf and so it points to a python version that was installed with asdf's Python plugin.

Now, if I run any pip-installed command via asdf, PATH is modified so that the associated python installation's bin folder comes before asdf shims. So, if I execute a system command inside this scope, the asdf shims don't apply, because the {python-version}/bin comes first in the PATH.

Would it be possible to avoid this?

My setup:

asdf which python

/Users/juhoautio/.asdf_rosetta/installs/python/3.7.17/bin/python

The PATH rewriting by asdf Python plugin can be demonstrated with a python command.

Executed via asdf:

python -c "import os; print(os.environ['PATH'])"

/Users/juhoautio/.asdf_rosetta/plugins/python/shims:/Users/juhoautio/.asdf_rosetta/installs/python/3.7.17/bin:/Users/juhoautio/.asdf_rosetta/shims:/usr/local/opt/asdf/libexec/bin:...

Which is the same as:

asdf exec python -c "import os; print(os.environ['PATH'])"

Executed directly:

/Users/juhoautio/.asdf_rosetta/installs/python/3.7.17/bin/python -c "import os; print(os.environ['PATH'])"

/Users/juhoautio/.asdf_rosetta/shims:/usr/local/opt/asdf/libexec/bin:...

The same issue affects any pip-installed CLI commands. For example, I installed poetry==1.1.8 with pip inside this python version. Now that version of poetry takes precedense over any asdf-managed version, when executing poetry from inside python.

As a practical example, I set:

asdf local poetry 1.5.1

With this asdf provides the expected version (not 1.1.8 which is the default in my case):

poetry --version

Poetry (version 1.5.1)

Running python directly, I get the expected result:

/Users/juhoautio/.asdf_rosetta/installs/python/3.7.17/bin/python -c \
  "import subprocess; subprocess.check_call(['poetry', '--version'])"

Poetry (version 1.5.1)

But via asdf the shim for poetry gets overridden by the version from the chosen python's bin:

python -c "import subprocess; subprocess.check_call(['poetry', '--version'])"

Poetry version 1.1.8

Describe the proposed solution

I would like to see this when invoking via asdf:

Executed via asdf:

python -c "import os; print(os.environ['PATH'])"

/Users/juhoautio/.asdf_rosetta/plugins/python/shims:/Users/juhoautio/.asdf_rosetta/shims:/usr/local/opt/asdf/libexec/bin:...

So otherwise the same as currently, but with this part removed: /Users/juhoautio/.asdf_rosetta/installs/python/3.7.17/bin:

Is there some valid reason why pip-installed commands should behave differently when executed via asdf vs. directly?

Describe similar asdf features and why they are not sufficient

N/A

Describe other workarounds you've considered

N/A

@RobLoach
Copy link

May want to create an issue in the asdf-python queue: https://github.com/asdf-community/asdf-python/issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants