jdx / mise

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

`_.python.venv` does not correctly prepend the venv path if a virtualenv is active (fish shell) #2718

Open albireox opened 3 weeks ago

albireox commented 3 weeks ago

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 like

/Users/gallegoj/.local/share/virtualenv/gallegoj/bin /Users/gallegoj/.cargo/bin /usr/local/bin /Users/gallegoj/.local/bin /usr/bin /bin

where /Users/gallegoj/.local/share/virtualenv/gallegoj/bin is an activated environment, and cd to a directory with a .mise.toml

[env]
_.python.venv = ".venv"

the resulting $PATH will be

/Users/gallegoj/.local/share/virtualenv/gallegoj/bin /Users/gallegoj/Documents/Code/sdss5/sdss-sep/.venv/bin /Users/gallegoj/.cargo/bin /usr/local/bin /Users/gallegoj/.local/bin /usr/bin /bin

instead of the expected

/Users/gallegoj/Documents/Code/sdss5/sdss-sep/.venv/bin /Users/gallegoj/.local/share/virtualenv/gallegoj/bin /Users/gallegoj/.cargo/bin /usr/local/bin /Users/gallegoj/.local/bin /usr/bin /bin

I've only tested this in fish.

mise doctor output

version: 2024.10.1 macos-x64 (7184e60 2024-10-07)
activated: yes
shims_on_path: no

build_info:
  Target: x86_64-apple-darwin
  Features: DEFAULT, NATIVE_TLS, OPENSSL
  Built: Mon, 7 Oct 2024 19:08:40 +0000
  Rust Version: rustc 1.81.0 (eeb90cda1 2024-09-04)
  Profile: release

shell:
  /usr/local/bin/fish
  fish, version 3.7.1-2332-g4c43819d3

dirs:
  data: ~/.local/share/mise
  config: ~/.config/mise
  cache: ~/Library/Caches/mise
  state: ~/.local/state/mise
  shims: ~/.local/share/mise/shims

config_files:
  ~/Documents/Code/sdss5/sdss-sep/.python-version
  ~/Documents/Code/sdss5/sdss-sep/.mise.toml

backends:
  cargo
  core
  go
  npm
  pipx
  spm
  ubi
  vfox

plugins:

toolset:
  python@sdss-sep  (missing)

env_vars:
  MISE_SHELL=fish

settings:
  activate_aggressive = false
  all_compile = false
  always_keep_download = false
  always_keep_install = false
  asdf = true
  asdf_compat = false
  cache_prune_age = "30d"
  cargo_binstall = true
  ci = false
  color = true
  debug = false
  disable_default_shorthands = false
  disable_hints = []
  disable_tools = []
  experimental = false
  go_default_packages_file = "~/.default-go-packages"
  go_download_mirror = "https://dl.google.com/go"
  go_repo = "https://github.com/golang/go"
  go_set_gopath = false
  go_set_goroot = true
  go_skip_checksum = false
  http_timeout = 30
  jobs = 4
  legacy_version_file = true
  legacy_version_file_disable_tools = []
  libgit2 = true
  log_level = "info"
  not_found_auto_install = true
  paranoid = false
  pin = false
  pipx_uvx = false
  plugin_autoupdate_last_check_duration = "7d"
  python_default_packages_file = "~/.default-python-packages"
  python_pyenv_repo = "https://github.com/pyenv/pyenv.git"
  python_venv_auto_create = false
  quiet = false
  raw = false
  trace = false
  trusted_config_paths = []
  use_versions_host = true
  verbose = false
  vfox = false
  yes = false

  [node]

  [ruby]
  default_packages_file = "~/.default-gems"
  ruby_build_repo = "https://github.com/rbenv/ruby-build.git"
  ruby_install = false
  ruby_install_repo = "https://github.com/postmodern/ruby-install.git"

  [status]
  missing_tools = "if_other_versions_installed"
  show_env = false
  show_tools = false
No warnings found
No problems found
hxii commented 5 days ago

Seconding this issue:

Paul_Glushak@Paul ~> pwd
/Users/Paul_Glushak
Paul_Glushak@Paul ~> echo $PATH | sed 's/ /\n/g'
/Users/Paul_Glushak/dev/forter-dev-cli/.venv/bin
/Users/Paul_Glushak/.local/share/mise/installs/pipx/latest/bin
/Users/Paul_Glushak/.local/share/mise/installs/python/latest/bin
/Users/Paul_Glushak/.local/share/mise/installs/poetry/latest/bin
/Users/Paul_Glushak/.local/share/mise/installs/usage/latest/bin
/Users/Paul_Glushak/.local/bin
/opt/homebrew/bin
...

Then cd somewhere else

Paul_Glushak@Paul ~> z boku
Paul_Glushak@Paul ~/d/boku (main)> cat .mise.toml
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: .mise.toml
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ [tools]
   2   │ python = "latest"
   3   │
   4   │ [env]
   5   │ _.python.venv = { path = ".venv", create = true }
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Paul_Glushak@Paul ~/d/boku (main)> echo $PATH | sed 's/ /\n/g'
/Users/Paul_Glushak/dev/forter-dev-cli/.venv/bin
/Users/Paul_Glushak/dev/boku/.venv/bin
/Users/Paul_Glushak/.local/share/mise/installs/python/latest/bin
/Users/Paul_Glushak/.local/share/mise/installs/pipx/latest/bin
/Users/Paul_Glushak/.local/share/mise/installs/poetry/latest/bin
/Users/Paul_Glushak/.local/share/mise/installs/usage/latest/bin
/Users/Paul_Glushak/.local/bin
/opt/homebrew/bin
...
Paul_Glushak@Paul ~/d/boku (main)>

It looks like the incorrect path value exists in both $PATH as well as $MISE_SHELL:

MISE_SHELL=fish set -gx __MISE_ORIG_PATH /Users/Paul_Glushak/dev/forter-dev-cli/.venv/bin /Users/Paul_Glushak/.local/share/mise/installs/pipx/latest/bin ...
jdx commented 3 days ago

this is by design, mise doesn't modify PATH to override things after it was activated to prevent it from aggressively modifying PATH. The activate_aggressive setting modifies this behavior.