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

mise + direnv (use mise) + venv; virtual env gets randomly deactivated #2362

Closed
HWiese1980 opened this issue Jul 9, 2024 · 8 comments
Closed

Comments

@HWiese1980
Copy link

I'm using mise in conjunction with direnv and individual venvs for my projects. direnv is configured like use mise, in some places accompanied by a source .venv/bin/activate so that changing into a subdirectory automatically activates the venv.

Now, it seems like whether this works or not is rather erratic and every now and then it happens that something, I don't know if it is direnv, mise or whatever, deactivates the current venv in the midst of a terminal session, requiring me to manually activate it again.

What might cause this behavior and how do I fix it?

@iloveitaly
Copy link

I was running into this as well.

TRACE  2 [src/cache.rs:136] writing ~/Library/Caches/mise/poetry/1.8.4/list_bin_paths/a78ddc913a-20dd4eb33d-cfd6d.msgpack.z
TRACE  2 [src/file.rs:103] mv /Users/mike/Library/Caches/mise/poetry/1.8.4/list_bin_paths/a78ddc913a-20dd4eb33d-cfd6d.msgpack.part-xKwzg8ET /Users/mike/Library/Caches/mise/poetry/1.8.4/list_bin_paths/a78ddc913a-20dd4eb33d-cfd6d.msgpack.z
DEBUG  3 [src/cmd.rs:93] $ /opt/homebrew/bin/bash -c . /Users/mike/.local/share/mise/plugins/poetry/bin/exec-env
export -p

++ setup_virtualenv
+++ poetry_venv
+++ local pyproject
++++ eval 'echo '
+++++ echo
+++ pyproject=
+++ '[' '' = '' ']'
+++ return
++ VIRTUAL_ENV=
++ [[ -z '' ]]
++ return
+ export -p

export MISE_LOG_LEVEL=trace helped me track this down. Here's the fix:

mise-plugins/mise-poetry#18

@jdx
Copy link
Owner

jdx commented Dec 10, 2024

you probably just shouldn't use direnv and mise for venvs together

@HWiese1980
Copy link
Author

@jdx Do you have alternative workflows in mind that achieve the same, like, on a per repo basis automatically (or not) activating venvs and setting up environments upon entering the repo folder? I suppose, mise can do something like this itself, but as convenient and flexible as direnv?

@jdx
Copy link
Owner

jdx commented Dec 11, 2024

if you use uv you can enable https://mise.jdx.dev/lang/python.html#python.uv_venv_auto

@HWiese1980
Copy link
Author

Yeah, I do, thanks. The problem is that we also have repositories with multiple venvs that do not necessarily, but may, reside in the repo root dir. I'm not sure yet how to handle those.

@ssbarnea
Copy link
Contributor

ssbarnea commented Dec 11, 2024

I think that I hit this while testing the code from direnv/direnv#1338 and I want to mention few things, hoping this this might help

Mise should be incompatible with direnv and should not require direnv users to make changes to their .envrc file that would break its loading if mise is missing (some projects do track .envrc file in git)

In my case virtualenv activation only partially worked. which tool-name reported correct location of a tool installed in both venv and outside with correct order but running the same command from shell did execute the one from outside the venv,... very bad.

mise doctor was able to report that mise reshim is needed, so I run it and after this it did resolve correctly. Probably use mise in the .envrc file would work too, but at the cost of breaking the loading of .envrc for anyone that does not have mise installed.

Related: #2023

@jdx
Copy link
Owner

jdx commented Dec 11, 2024

I should just deprecate use mise. I haven't worked on it at all in a long time and it was always an alternative solution that has never really found its footing. It's effectively been deprecated for a long time, this would just communicate the actual state. The docs already kind of hint at this but I'm going to make it more explicit.

It's a relic from a time when direnv was much more popular and mise didn't have feature parity. There may still be some gaps with feature parity which could be addressed separately.

jdx added a commit that referenced this issue Dec 11, 2024
jdx added a commit that referenced this issue Dec 11, 2024
jdx added a commit that referenced this issue Dec 11, 2024
jdx added a commit that referenced this issue Dec 11, 2024
@jdx jdx closed this as completed in 816d6ee Dec 11, 2024
@jdx
Copy link
Owner

jdx commented Dec 11, 2024

Yeah, I do, thanks. The problem is that we also have repositories with multiple venvs that do not necessarily, but may, reside in the repo root dir. I'm not sure yet how to handle those.

I think at present the solution to this are uv_venv_auto or env._.python.venv though I don't think the latter works in an "automatic" way the same way that uv_venv_auto does—it needs to be manually configured per-project.

I see uv_venv_auto as the future. I don't write python or understand it well so I would like to dispatch to uv as much as possible. If you'd like to see more from mise+venvs you'll probably need to make the PR yourself at this point.

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

No branches or pull requests

4 participants