-
Notifications
You must be signed in to change notification settings - Fork 294
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
_.python.venv
does not correctly prepend the venv path if a virtualenv is active (fish shell)
#2718
Comments
Seconding this issue:
Then
It looks like the incorrect path value exists in both
|
this is by design, mise doesn't modify PATH to override things after it was activated to prevent it from aggressively modifying PATH. The |
@jdx am I understanding correctly that the aggressive setting will prepend the new path, while the default should overwrite the old one? If so, the issue is that it’s not being overwritten. |
@jdx Hello 👋 Sorry to disturb you, but have you an update on this? 🙏 From your point of view, how are we supposed to use the |
Not an expert but hope I can lend a thought here.
Yes, but not just the new path, but all mise paths: e.g.
to
Depends what you mean by "old one". I don't believe mise ever overwrites/deletes any paths other than the ones it manages. If mise was managing both then it would unload the old one and load the new one Like this~/Code/sandbox
❯ mkdir py1 py2
~/Code/sandbox
❯ cat > py1/mise.toml
[tools]
python = "latest"
[env]
_.python.venv = { path = ".venv", create = true }
~/Code/sandbox
❯ cp py1/mise.toml py2/
~/Code/sandbox
❯ mise trust py1/mise.toml; mise trust py2/mise.toml;
mise trusted /Users/syhol/Code/sandbox/py1/mise.toml
mise trusted /Users/syhol/Code/sandbox/py2/mise.toml
~/Code/sandbox
❯ cd py1
Code/sandbox/py1 via 🐍 v3.11.10 (.venv)
❯ echo $PATH | sed 's/ /\n/g'
/Users/syhol/Code/sandbox/py1/.venv/bin
/Users/syhol/.local/share/mise/installs/python/3.11.10/bin
...
Code/sandbox/py1 via 🐍 v3.11.10 (.venv)
❯ cd ../py2
Code/sandbox/py2 via 🐍 v3.11.10 (.venv)
❯ echo $PATH | sed 's/ /\n/g'
/Users/syhol/Code/sandbox/py2/.venv/bin
/Users/syhol/.local/share/mise/installs/python/3.11.10/bin
...
If For some reason my install of mise seems to always do the "aggressive setting" behaviour even though I haven't enabled it, so I can't recreate your behaviour with an unmanaged My recommendation is to do one of the following:
I hope I've understood your problem properly, let me know if I've gotten anything wrong. |
Hello 👋 @syhol Thanks for your reply, concerning this point:
If we use |
I don't think I understand this use-case. It sounds like you've activated a venv after mise, then are wanting mise to override that venv. Why activate the other one at all? I would just use mise for both of them. mise is careful not to make modifications to PATH that overwrite changes after it was started. Otherwise it would be impossible to do something like |
mise is actually activating the environment, check However, to your credit, I checked what happens when you have 2 venvs (both not managed by mise) and activate them one after the other. The second activation did remove the path from the first. uv's venv clobbering old venv paths# Code/sandbox/unmanaged-venv
❯ uv venv .venv
Using Python 3.13.0 interpreter at: /opt/homebrew/opt/[email protected]/bin/python3.13
Creating virtualenv at: .venv
Activate with: source .venv/bin/activate.fish
# Code/sandbox/unmanaged-venv
❯ source .venv/bin/activate.fish
# Code/sandbox/unmanaged-venv via 🐍 v3.13.0 (unmanaged-venv)
❯ echo $PATH | sed 's/ /\n/g'
/Users/simon/Code/sandbox/unmanaged-venv/.venv/bin
/Users/simon/.local/share/mise/installs/node/21.4.0/bin
...
# ~/Code/sandbox/unmanaged-venv via 🐍 v3.13.0 (unmanaged-venv)
❯ mkdir ../unmanaged-venv-2
# ~/Code/sandbox/unmanaged-venv via 🐍 v3.13.0 (unmanaged-venv)
❯ cd ../unmanaged-venv-2/
# Code/sandbox/unmanaged-venv-2 via 🐍 v3.13.0 (unmanaged-venv)
❯ uv venv .venv
Using Python 3.13.0 interpreter at: /opt/homebrew/opt/[email protected]/bin/python3.13
Creating virtualenv at: .venv
Activate with: source .venv/bin/activate.fish
# Code/sandbox/unmanaged-venv-2 via 🐍 v3.13.0 (unmanaged-venv)
❯ source .venv/bin/activate.fish
# Code/sandbox/unmanaged-venv-2 via 🐍 v3.13.0 (unmanaged-venv-2)
❯ echo $PATH | sed 's/ /\n/g'
/Users/syhol/Code/sandbox/unmanaged-venv-2/.venv/bin
/Users/syhol/.local/share/mise/installs/node/21.4.0/bin
... @jdx would you be open to matching this behaviour? If you check to see what venv deactivate fish function (runs on activate to clear out the old venv)Here is the source of the virtualenv version https://github.com/pypa/virtualenv/blob/main/src/virtualenv/activation/fish/activate.fish and a very similar source for uv: function deactivate -d 'Exit virtualenv mode and return to the normal environment.'
# reset old environment variables
if test -n "$_OLD_VIRTUAL_PATH"
# https://github.com/fish-shell/fish-shell/issues/436 altered PATH handling
if test (echo $FISH_VERSION | head -c 1) -lt 3
set -gx PATH (_fishify_path "$_OLD_VIRTUAL_PATH")
else
set -gx PATH $_OLD_VIRTUAL_PATH
end
set -e _OLD_VIRTUAL_PATH
end
if test -n "$_OLD_VIRTUAL_PYTHONHOME"
set -gx PYTHONHOME "$_OLD_VIRTUAL_PYTHONHOME"
set -e _OLD_VIRTUAL_PYTHONHOME
end
if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
and functions -q _old_fish_prompt
# Set an empty local `$fish_function_path` to allow the removal of `fish_prompt` using `functi
ons -e`.
set -l fish_function_path
# Erase virtualenv's `fish_prompt` and restore the original.
functions -e fish_prompt
functions -c _old_fish_prompt fish_prompt
functions -e _old_fish_prompt
set -e _OLD_FISH_PROMPT_OVERRIDE
end
set -e VIRTUAL_ENV
set -e VIRTUAL_ENV_PROMPT
if test "$argv[1]" != 'nondestructive'
# Self-destruct!
functions -e pydoc
functions -e deactivate
functions -e _bashify_path
functions -e _fishify_path
end
end I can't see this behaviour in any formal spec but that does seem to be the practical standard for venv activation. Also it is what many (at least 3) people expect to happen. What do you think? |
I would be, though I don't think we have any mechanism for removing entries from PATH. I don't think that would be simple to achieve. |
what would probably need to be done is to have a special env var sort of like how we use mise/src/plugins/core/python.rs Line 425 in 7ba9eab
however we wouldn't be able to use that in the same place That only would solve Lines 491 to 505 in 7ba9eab
|
Are you suggesting you set the old Re: shims and
yeah that should be fine. |
It could be that I missed something while configuring mise. mise doctor output
Just to clarify, in my case the venv in both directories are created by mise:
|
Describe the bug
When one already has a virtualenv active, a
.mise.toml
file with a_.python.venv
directive will add the commanded venv to PATH but always after the already active one. For example if I have a$PATH
likewhere
/Users/gallegoj/.local/share/virtualenv/gallegoj/bin
is an activated environment, andcd
to a directory with a.mise.toml
the resulting
$PATH
will beinstead of the expected
I've only tested this in
fish
.mise doctor
outputThe text was updated successfully, but these errors were encountered: