jdx / mise

dev tools, env vars, task runner
https://mise.jdx.dev
MIT License
9.01k stars 243 forks source link

Python virtualenvs created but not activated #1336

Closed delicb closed 8 months ago

delicb commented 8 months ago

Describe the bug Since rtx -> mise rename, python virtualenvs are not activated any more. If they don't exist, they are created, but not activated.

To Reproduce

~                                                                                                                                                                                                                                               
❯ mkdir /tmp/mise-venv

~                                                                                                                                                                                                                                               
❯ cat > /tmp/mise-venv/.mise.toml
[tools]
python = {version="3.12", virtualenv=".venv"}

~ ⏱ 21s850ms                                                                                                                                                                                                                                    
❯ cd /tmp/mise-venv/
mise setting up virtualenv at: /private/tmp/mise-venv/.venv

/tmp/mise-venv                                                                                                                                                                                                                        
❯ which python
/Users/del-boy/.local/share/mise/installs/python/3.12/bin/python

/tmp/mise-venv                                                                                                                                                                                                                        
❯ ls -a
.mise.toml  .venv

/tmp/mise-venv                                                                                                                                                                                                                        
❯ ls .venv
bin  include  lib  pyvenv.cfg

/tmp/mise-venv                                                                                                                                                                                                                        
❯ python -c "import sys; print(sys.prefix)"
/Users/del-boy/.local/share/mise/installs/python/3.12

/tmp/mise-venv                                                                                                                                                                                                                        
❯ 

Expected behavior As before, I expect that virtualenv is activated when cd into folder that has config file declaring virtualenv.

mise doctor output

mise version:
  2024.1.0 macos-arm64 (2024-01-02)

build:
  Target: aarch64-apple-darwin
  Features: DEFAULT, NATIVE_TLS
  Built: Tue, 2 Jan 2024 23:47:11 +0000
  Rust Version: rustc 1.75.0 (82e1608df 2023-12-21) (Homebrew)
  Profile: release

shell:
  /opt/homebrew/bin/fish
  fish, version 3.7.0

mise data directory:
  /Users/del-boy/.local/share/mise

mise environment variables:
  MISE_SHELL=fish
  MISE_USE_TOML=1

settings:
  {
    "experimental": false,
    "color": true,
    "always_keep_download": false,
    "always_keep_install": false,
    "legacy_version_file": true,
    "legacy_version_file_disable_tools": [],
    "plugin_autoupdate_last_check_duration": "7d",
    "trusted_config_paths": [],
    "log_level": "info",
    "trace": false,
    "debug": false,
    "verbose": false,
    "quiet": false,
    "asdf_compat": false,
    "jobs": 4,
    "shorthands_file": null,
    "disable_default_shorthands": false,
    "disable_tools": [],
    "raw": false,
    "yes": false,
    "task_output": null,
    "not_found_auto_install": true,
    "ci": false,
    "env_file": null,
    "cd": null
  }

config files:
  /Users/del-boy/.config/mise/config.toml
  /private/tmp/mise-venv/.mise.toml

plugins:
  awscli          https://github.com/MetricMike/asdf-awscli.git#c645552
  bun             (core)
  deno            https://github.com/asdf-community/asdf-deno.git#87442fe
  erlang          (core)
  go              (core)
  helm            https://github.com/Antiarchitect/asdf-helm.git#a39e17b
  httpie-go       https://github.com/abatilo/asdf-httpie-go.git#9832bfe
  hugo            https://github.com/NeoHsu/asdf-hugo.git#125ce37
  java            (core)
  kubectl         https://github.com/asdf-community/asdf-kubectl.git#cbe6df4
  legacy-python   https://github.com/danhper/asdf-python.git#8505457
  mongosh         https://github.com/itspngu/asdf-mongosh.git#1b24902
  node            https://github.com/asdf-vm/asdf-nodejs.git#644ada3
  poetry          https://github.com/rtx-plugins/rtx-poetry.git#6e1231e
  python          (core)
  ruby            (core)
  rust            https://github.com/code-lever/asdf-rust.git#0c88f99
  shellcheck      https://github.com/luizm/asdf-shellcheck.git#b160a52
  sqlite          https://github.com/cLupus/asdf-sqlite.git#299c0a4
  terraform       https://github.com/asdf-community/asdf-hashicorp.git#c44c314

toolset:
  python@3.12, go@latest, sqlite@3.40.1, httpie-go@latest, awscli@2.13.31, ruby@2.7.8, terraform@1.3.7, deno@1.30.0, shellcheck@0.9.0, helm@3.8.1, kubectl@1.26.1, mongosh@latest, rust@1.73.0, hugo@extended_0.110.0, node@18.13.0

No problems found

Additional context Add any other context about the problem here.

AlexCzar commented 8 months ago

The woes of auto-upgrade :D Came back from lunch and greeted with broken workflow all over :) Temporary workaround unti this is fixed is to activate the venv manually: source <venv_dir>/bin/activate (Linux/MacOS, bash-compatible) See the official python documentation for other OS/shell versions and details.

delicb commented 8 months ago

Yea, rename broke bunch of things, it was a fun morning for me :). I have learned not to use rtx (or mise) for everything (e.g. all of my virtualenvs were broken due to broken symlinks, all of python and ruby installations were broken because python was looking for libpython at the old location, to recreate virtualenvs I need login to CodeArtifact to configure PIP, but - you guessed it - some of needed internal tools are installed via pipx that used rtx installed python, and so on).

After solving all of these - I am left with broken virtualenv activation. not sure why. I am manually activating python, as you mentioned, there is no issue there, but this should work.

Btw, I see now in issue report that mise doctor reported experimental = false, which is not true, I have it set to true and mise settings get experimental confirms that, since it returns true (and venv is being created, just not activated).

joshuataylor commented 8 months ago

It looks like export is ran twice?

With:

export RTX_DEBUG=1
export RTX_LOG_LEVEL=trace
set -x

(set -x enables more verbose output with zsh)

First time into directory: cd /tmp/mise-venv

+-zsh:6> cd /tmp/mise-venv
+_mise_hook:1> mise hook-env -s zsh
+mise:1> local command
+mise:2> command=hook-env
+mise:3> [ 3 '=' 0 ']'
+mise:7> shift
+mise:9> case hook-env (deactivate | s | shell)
+mise:18> mise hook-env -s zsh
mise setting up virtualenv at: /tmp/mise-venv/.venv
+_mise_hook:1> eval $'export PATH=\':/home/josh/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/rustup/bin\'\nexport VIRTUAL_ENV=/tmp/mise-venv/.venv\nexport PATH=\'/home/josh/.local/share/mise/installs/python/3.12/bin::/home/josh/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/rustup/bin\'\nexport __MISE_DIFF=eAEBaQCW/4Ojb2xkgKNuZXeBq1ZJUlRVQUxfRU5WtC90bXAvbWlzZS12ZW52Ly52ZW52pHBhdGiR2TUvaG9tZS9qb3NoLy5sb2NhbC9zaGFyZS9taXNlL2luc3RhbGxzL3B5dGhvbi8zLjEyL2JpbriFKH4\nexport __MISE_WATCH=eAGVjjEOAUEUhm/gBDq1eXZROIDELcZk9q0ZmZm32bfZlqwz6CQqnWKVEhfQ6PVKh8BWJBS6P3/yffmqXWod8uraAUMeYU5sQGgKqZ2Bt4ygmy0K8q6qGTVLtkGjxIy0ueA6TA9BBfq8u+Pl5vRudKSVAzYqx0b7h6o1uR2h8FnDdUsMJYhXmfidtPiS1N7ez/snLEuVS6PY1Djs9ZNBjDEmURKNogegr29K'
+(eval):1> export PATH=:/home/josh/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/rustup/bin
+(eval):2> export VIRTUAL_ENV=/tmp/mise-venv/.venv
+(eval):3> export PATH=/home/josh/.local/share/mise/installs/python/3.12/bin::/home/josh/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/rustup/bin
+(eval):4> export __MISE_DIFF=eAEBaQCW/4Ojb2xkgKNuZXeBq1ZJUlRVQUxfRU5WtC90bXAvbWlzZS12ZW52Ly52ZW52pHBhdGiR2TUvaG9tZS9qb3NoLy5sb2NhbC9zaGFyZS9taXNlL2luc3RhbGxzL3B5dGhvbi8zLjEyL2JpbriFKH4
+(eval):5> export __MISE_WATCH=eAGVjjEOAUEUhm/gBDq1eXZROIDELcZk9q0ZmZm32bfZlqwz6CQqnWKVEhfQ6PVKh8BWJBS6P3/yffmqXWod8uraAUMeYU5sQGgKqZ2Bt4ygmy0K8q6qGTVLtkGjxIy0ueA6TA9BBfq8u+Pl5vRudKSVAzYqx0b7h6o1uR2h8FnDdUsMJYhXmfidtPiS1N7ez/snLEuVS6PY1Djs9ZNBjDEmURKNogegr29K
+_mise_hook:1> mise hook-env -s zsh
+mise:1> local command
+mise:2> command=hook-env
+mise:3> [ 3 '=' 0 ']'
+mise:7> shift
+mise:9> case hook-env (deactivate | s | shell)
+mise:18> mise hook-env -s zsh
+_mise_hook:1> eval ''

which python /home/josh/.local/share/mise/installs/python/3.12/bin/python

cd out, back in:

+-zsh:3> cd /tmp/mise-venv
+_mise_hook:1> mise hook-env -s zsh
+mise:1> local command
+mise:2> command=hook-env
+mise:3> [ 3 '=' 0 ']'
+mise:7> shift
+mise:9> case hook-env (deactivate | s | shell)
+mise:18> mise hook-env -s zsh
+_mise_hook:1> eval $'export PATH=\':/home/josh/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/rustup/bin\'\nexport VIRTUAL_ENV=/tmp/mise-venv/.venv\nexport PATH=\'/home/josh/.local/share/mise/installs/python/3.12/bin::/home/josh/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/rustup/bin\'\nexport __MISE_DIFF=eAEBaQCW/4Ojb2xkgKNuZXeBq1ZJUlRVQUxfRU5WtC90bXAvbWlzZS12ZW52Ly52ZW52pHBhdGiR2TUvaG9tZS9qb3NoLy5sb2NhbC9zaGFyZS9taXNlL2luc3RhbGxzL3B5dGhvbi8zLjEyL2JpbriFKH4\nexport __MISE_WATCH=eAGVjjEOAUEUhm/gBDq1eXZROIDELcZk9q0ZmZm32bfZlqwz6CQqnWKVEhfQ6PVKh8BWJBS6P3/yffmqXWod8uraAUMeYU5sQGgKqZ2Bt4ygmy0K8q6qGTVLtkGjxIy0ueA6TA9BBfq8u+Pl5vRudKSVAzYqx0b7h6o1uR2h8FnDdUsMJYhXmfidtPiS1N7ez/snLEuVS6PY1Djs9ZNBjDEmURKNogegr29K'
+(eval):1> export PATH=:/home/josh/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/rustup/bin
+(eval):2> export VIRTUAL_ENV=/tmp/mise-venv/.venv
+(eval):3> export PATH=/home/josh/.local/share/mise/installs/python/3.12/bin::/home/josh/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/rustup/bin
+(eval):4> export __MISE_DIFF=eAEBaQCW/4Ojb2xkgKNuZXeBq1ZJUlRVQUxfRU5WtC90bXAvbWlzZS12ZW52Ly52ZW52pHBhdGiR2TUvaG9tZS9qb3NoLy5sb2NhbC9zaGFyZS9taXNlL2luc3RhbGxzL3B5dGhvbi8zLjEyL2JpbriFKH4
+(eval):5> export __MISE_WATCH=eAGVjjEOAUEUhm/gBDq1eXZROIDELcZk9q0ZmZm32bfZlqwz6CQqnWKVEhfQ6PVKh8BWJBS6P3/yffmqXWod8uraAUMeYU5sQGgKqZ2Bt4ygmy0K8q6qGTVLtkGjxIy0ueA6TA9BBfq8u+Pl5vRudKSVAzYqx0b7h6o1uR2h8FnDdUsMJYhXmfidtPiS1N7ez/snLEuVS6PY1Djs9ZNBjDEmURKNogegr29K
+_mise_hook:1> mise hook-env -s zsh
+mise:1> local command
+mise:2> command=hook-env
+mise:3> [ 3 '=' 0 ']'
+mise:7> shift
+mise:9> case hook-env (deactivate | s | shell)
+mise:18> mise hook-env -s zsh
+_mise_hook:1> eval ''
jdx commented 8 months ago

Huh I tested this yesterday and it worked. Will do a little digging this morning to see what's up

jdx commented 8 months ago

I just put a patch in for the mise doctor issue

delicb commented 8 months ago

Huh I tested this yesterday and it worked. Will do a little digging this morning to see what's up

Thanks. If I can provide more info, reproduce something or help anyhow, please let me know.

jdx commented 8 months ago

the export PATH being in there twice is just a quirk of how things work, should be fixed but not really likely to cause a problem. It looks like in @joshuataylor's output it is enabling the venv just fine?

I'm testing this myself right now.

jdx commented 8 months ago

hmm if I run mise env I see the virtualenv:

mise  main ❯ mise env
mise setting up virtualenv at: /Users/jdx/.cache/venv
set -gx VIRTUAL_ENV /Users/jdx/.cache/venv

can you try that to make sure it is outputting the env var?

jdx commented 8 months ago

I did notice I needed to delete the rtx created venv, but it sounds like you were able to get mise to create the venv

jdx commented 8 months ago

yeah I'm seeing it activate/create venvs using mise activate zsh just fine

jdx commented 8 months ago

oh I see what you're saying, it's that PATH isn't showing the python bin, I was looking at the VIRTUAL_ENV env var. I don't think this is related to the name change but investigating.

jdx commented 8 months ago

oh it is related, I found the issue

joshuataylor commented 8 months ago

Can confirm, all works as expected with mise-v2024-1.1!

Thanks so much!

jdx commented 8 months ago

people in this thread: please weigh in on this poll: https://github.com/jdx/mise/discussions/1357