jdx / mise

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

Using shims with IDE #2235

Open kenahoo opened 1 month ago

kenahoo commented 1 month ago

I'm trying to get mise working with my IDE, which is IntelliJ IDEA (commercial version). I'm following the instructions at https://mise.jdx.dev/ide-integration.html but I'm having some problems.

  1. I have put eval "$(mise activate zsh --shims)" into my ~/.zprofile and restarted my shell, but this doesn't result in the shims directory being on the PATH. If I run mise activate zsh --shims directly, it looks like it produces no output at all, is that supposed to be the case? I'd have assumed it would spit out some text to modify PATH.

  2. Now I've set up a symlink for asdf and also added the shims directory to PATH:

% ls -l ~/.asdf 
lrwxr-xr-x  1 kwilliams  staff  34 May 31 16:06 /Users/kwilliams/.asdf@ -> /Users/kwilliams/.local/share/mise

% cat ~/.zprofile
path[1,0]="/opt/homebrew/bin"  # Prepend
eval "$(mise activate)"
eval "$(mise activate zsh --shims)"
path[1,0]="$HOME/.local/share/mise/shims"  # Prepend

But I can't seem to find any sign in IntelliJ that either asdf or mise has been detected. Where would I see something? What should be different? Is there a plugin necessary? If I go into Project Settings -> Project -> SDK for a Python project, I don't see any stuff that seems to have anything to do with mise, is it supposed to show up automatically? And environment variables that I've set locally in a project's .mise.toml file aren't getting set in IDE jobs, though they're working fine at a terminal.

Any help would be very appreciated, thanks.

**`mise doctor` output** ```text version: 2024.5.27 macos-arm64 (2024-05-31) activated: yes shims_on_path: yes build_info: Target: aarch64-apple-darwin Features: DEFAULT, NATIVE_TLS Built: Fri, 31 May 2024 02:31:10 +0000 Rust Version: rustc 1.78.0 (9b00956e5 2024-04-29) (Homebrew) Profile: release shell: /bin/zsh zsh 5.9 (x86_64-apple-darwin23.0) dirs: data: ~/.local/share/mise config: ~/.config/mise cache: ~/Library/Caches/mise state: ~/.local/state/mise shims: ~/.local/share/mise/shims config_files: ~/git/transmission/ey299-tft_view/.mise.toml backends: cargo core go npm pipx ubi plugins: bun (core) deno (core) erlang (core) go (core) java (core) node (core) python (core) ruby (core) toolset: python@3.11.9 env_vars: MISE_SHELL=zsh settings: activate_aggressive = false all_compile = false always_keep_download = false always_keep_install = false asdf_compat = false cargo_binstall = true color = true disable_default_shorthands = false 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 jobs = 4 legacy_version_file = true legacy_version_file_disable_tools = [] node_compile = false not_found_auto_install = true paranoid = false plugin_autoupdate_last_check_duration = "7d" python_default_packages_file = "/Users/kwilliams/.default-python-packages" python_pyenv_repo = "https://github.com/pyenv/pyenv.git" raw = false trusted_config_paths = [] quiet = false verbose = false yes = false ci = false debug = false trace = false log_level = "info" python_venv_auto_create = false [status] missing_tools = "if_other_versions_installed" show_env = false show_tools = false No warnings found No problems found ```
jdx commented 1 month ago

it doesn't do anything if it's already on PATH

kenahoo commented 1 month ago

Does the virtual env functionality not work with shims? In my .mise.toml I have

[env]
_.python.venv = { path = ".venv", create = true }

but python still shows that it's using $HOME/.local/share/mise/installs/python/3.11.9/lib/, not .venv/.

With eval "$(mise activate zsh --shims)" in my ~/.zprofile:

>>> for p in sys.path: print(p)
... 

/Users/kwilliams/.local/share/mise/installs/python/3.11.9/lib/python311.zip
/Users/kwilliams/.local/share/mise/installs/python/3.11.9/lib/python3.11
/Users/kwilliams/.local/share/mise/installs/python/3.11.9/lib/python3.11/lib-dynload
/Users/kwilliams/.local/share/mise/installs/python/3.11.9/lib/python3.11/site-packages    <- incorrect

With eval "$(mise activate)" in my ~/.zprofile:

>>> for p in sys.path: print(p)
... 

/Users/kwilliams/.local/share/mise/installs/python/3.11/lib/python311.zip
/Users/kwilliams/.local/share/mise/installs/python/3.11/lib/python3.11
/Users/kwilliams/.local/share/mise/installs/python/3.11/lib/python3.11/lib-dynload
/Users/kwilliams/<project location>/.venv/lib/python3.11/site-packages       <- correct

The only difference is changing that one line in the profile.

vrslev commented 3 weeks ago

Can you try adding mise hook-env instead? https://github.com/jdx/mise/issues/2270

kenahoo commented 3 weeks ago

Just tried it, but it still doesn't seem to honor the venv settings.

~/.zprofile:

path[1,0]="/opt/homebrew/bin"  # Prepend
eval "$(mise hook-env --shell zsh)"

.mise.toml:

[tools]
python = "3.11"
[env]
_.python.venv = { path = ".venv", create = true }

It's not using the local .venv/ directory:

% python -c 'import sys; [print(p) for p in sys.path]'         

/Users/kwilliams/.local/share/mise/installs/python/3.11.9/lib/python311.zip
/Users/kwilliams/.local/share/mise/installs/python/3.11.9/lib/python3.11
/Users/kwilliams/.local/share/mise/installs/python/3.11.9/lib/python3.11/lib-dynload
/Users/kwilliams/.local/share/mise/installs/python/3.11.9/lib/python3.11/site-packages
vrslev commented 3 weeks ago

Sadly, yes. mise hook-env is being called once at your IDE's startup.

kenahoo commented 3 weeks ago

But the above is just me trying setups in a fresh shell, not using an IDE at all. I thought it would be good to troubleshoot it in the shell to get that working first.

kenahoo commented 2 weeks ago

Were you able to confirm in your environment that shims aren't working with python venvs?