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 removes $VIRTUAL_ENV in zsh/bash #2571

Open
teaVeloper opened this issue Sep 12, 2024 · 0 comments
Open

mise removes $VIRTUAL_ENV in zsh/bash #2571

teaVeloper opened this issue Sep 12, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@teaVeloper
Copy link

Describe the bug

When I am using zsh and 'initialize' mise (eval "$(mise activate zsh)") whenever I cd in or out of a folder with a .mise.toml or .tools-version file my $VIRTUAL_ENV varible is removed. It happens even on the 'eval' command as well.

I tried it with bash too, seems to do the same.

To Reproduce

my config files:
.mise.toml

[tools]
python = ['3.9', '3.10', '3.11']

~/.config/mise/config.toml

[tools]
python = ["3.10", "3.9", "3.11", "3.12"]
poetry = "1.6.1"
spark = "3.3.3"
java = "adoptopenjdk-11.0.16+8"
nodej = "20.6.0"
pipx = "1.6.0"

source any virtualenvironment
source path/to/venv/bin/activate

echo $VIRTUAL_ENV

path/to/venv

either have mise activated and be in a folder with the given .mise.toml:
cd ..
echo $VIRTUAL_ENV

``

or run:
eval "$(mise activate zsh)"
echo $VIRTUAL_ENV

``

while when I do
cd .. - now I am in a folder without .mise.toml
source path/to/venv/bin/activate
echo $VIRTUAL_ENV

path/to/venv

cd .. - again a folder without .mise.toml
echo $VIRTUAL_ENV

path/to/venv

A more detailed dump of me exploring is on the bottom.

Expected behavior
If not configured to automatically 'activate' or 'deactivate' virtual environments in 'python' to not touch the environment variable.
I guess $PATH modification in both cases is to be expected, as this is what 'mise' does when not using 'shims', maybe though, the modification should take into account if $VIRTUAL_ENV is set? (But I guess that would be more a feature request than this bug report?).

Maybe this is also intended behaviour, to not confuse having $VIRTUAL_ENV set, but pointing with $PATH to another python-interpreter?
The current behaviour definitely avoids somewhat problems for this case and if a the prompt shows the current virtual env by using the variable, at least one sees it immediately.
I would expect to still keep my sourced virtual env active, when traversing the file system.

mise doctor output

version: 2024.9.2 linux-x64 (2024-09-11)
activated: yes
shims_on_path: no

build_info: 
  Target: x86_64-unknown-linux-gnu
  Features: DEFAULT, NATIVE_TLS
  Built: Wed, 11 Sep 2024 23:13:29 +0000
  Rust Version: rustc 1.81.0 (eeb90cda1 2024-09-04) (Homebrew)
  Profile: release

shell: 
  /usr/bin/zsh
  zsh 5.8.1 (x86_64-ubuntu-linux-gnu)

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

config_files: 
  ~/.config/mise/config.toml
  ~/path/to/****/libraries/my-project/.mise.toml

backends: 
  cargo
  core
  go
  npm
  pipx
  spm
  ubi
  vfox

plugins: 
  poetry  https://github.com/mise-plugins/mise-poetry.git#431c335
  usage   https://github.com/jdx/mise-usage.git#fe3888a

toolset: 
  python@3.9.20         
  python@3.10.12        
  python@3.11.10        
  poetry@1.6.1          
  spark@3.3.3           (missing)
  java@adoptopenjdk-11.0.16+8  
  nodej@20.6.0          (missing)
  pipx@1.6.0            (missing)

env_vars: 
  MISE_SHELL=zsh

settings: 
  activate_aggressive = false
  all_compile = false
  always_keep_download = false
  always_keep_install = false
  asdf = true
  asdf_compat = false
  cargo_binstall = true
  color = true
  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
  node_compile = false
  not_found_auto_install = true
  paranoid = 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"
  raw = false
  trusted_config_paths = []
  quiet = false
  use_versions_host = true
  verbose = false
  vfox = 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

Additional context
I tried it with an older version, there was the same behavior, then I updated mise and the behavior was still the same.
For comparison I started a bash to see if things are different there, and they are.

I tried with both .tools-versions and .mise.toml as config files locally.

Here a dump from my environment, with some censoring

mise was not initialized in this shell, to show it better:

# no mise initializedecho $PATH
/home/*****/.cache/antidote/https-COLON--SLASH--SLASH-github.51.al-SLASH-romkatv-SLASH-zsh-bench:/home/*****/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/home/linuxbrew/.linuxbrew/bin:/home/*****/.local/share/go/bin:/home/*****/.local/share/cargo/bin:/usr/local:/home/*****/.poetry/bin:/home/*****/.local/bin:/home/*****/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/*****/.rye/shims:/home/*****/.cargo/bin:/home/*****/.local/bin:/home/*****/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/bin:/home/*****/.fzf/bin

❯ which python
/home/*****/.rye/shims/python
# here I have ryes python version

❯ z html
# I jump into my project

~/path/to/****/libraries/my-project ****-***
❯ ls .mise.toml
.mise.toml

~/path/to/****/libraries/my-project ****-***source /home/*****/.local/share/virtualenvs/my-project/bin/activate

~/path/to/****/libraries/my-project ****-***
❯ which python
/home/*****/.local/share/virtualenvs/my-project/bin/python
# Now we have my venvs python

~/path/to/****/libraries/my-project ****-***echo $PATH
/home/*****/.local/share/virtualenvs/my-project/bin:/home/*****/.cache/antidote/https-COLON--SLASH--SLASH-github.51.al-SLASH-romkatv-SLASH-zsh-bench:/home/*****/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/home/linuxbrew/.linuxbrew/bin:/home/*****/.local/share/go/bin:/home/*****/.local/share/cargo/bin:/usr/local:/home/*****/.poetry/bin:/home/*****/.local/bin:/home/*****/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/*****/.rye/shims:/home/*****/.cargo/bin:/home/*****/.local/bin:/home/*****/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/bin:/home/*****/.fzf/bin

~/path/to/****/libraries/my-project ****-***echo $VIRTUAL_ENV
/home/*****/.local/share/virtualenvs/my-project
# The venv works

~/path/to/****/libraries/my-project ****-***cd ..

~/path/to/****/libraries
❯ ls .mise.toml
ls: cannot access '.mise.toml': No such file or directory

~/path/to/****/libraries
❯ echo $VIRTUAL_ENV
/home/*****/.local/share/virtualenvs/my-project
# Nothing changed by changing dir 

~/path/to/****/libraries
❯ eval "$(mise activate zsh)"
# Mise is activated

~/path/to/****/libraries 
❯ echo $VIRTUAL_ENV

# My venv is deleted

~/path/to/****/libraries
❯ echo $PATH       
/home/*****/.local/share/mise/installs/python/3.10/bin:/home/*****/.local/share/mise/installs/python/3.9/bin:/home/*****/.local/share/mise/installs/python/3.11/bin:/home/*****/.local/share/mise/installs/python/3.12/bin:/home/*****/.local/share/mise/installs/poetry/1.6.1/bin:/home/*****/.local/share/mise/installs/java/adoptopenjdk-11.0.16+8/bin:/home/*****/.local/share/virtualenvs/my-project/bin:/home/*****/.cache/antidote/https-COLON--SLASH--SLASH-github.51.al-SLASH-romkatv-SLASH-zsh-bench:/home/*****/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/home/linuxbrew/.linuxbrew/bin:/home/*****/.local/share/go/bin:/home/*****/.local/share/cargo/bin:/usr/local:/home/*****/.poetry/bin:/home/*****/.local/bin:/home/*****/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/home/*****/.rye/shims:/home/*****/.cargo/bin:/home/*****/.local/bin:/home/*****/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/bin:/home/*****/.fzf/bin
# My path is changed

~/path/to/****/libraries
❯ source /home/*****/.local/share/virtualenvs/my-project/bin/activate
# I activate my venv again


~/path/to/****/libraries
❯ echo $VIRTUAL_ENV
/home/*****/.local/share/virtualenvs/my-project

~/path/to/****/libraries
❯ cd -
~/path/to/****/libraries/my-project

~/path/to/****/libraries/my-project ****-***echo $VIRTUAL_ENV


# After changing dir, my virtual env is modified

~/path/to/****/libraries/my-project ****-***cd ..

~/path/to/****/libraries
❯ ls .mise.toml
ls: cannot access '.mise.toml': No such file or directory

# now I am in a folder with no mise config file
~/path/to/****/libraries
❯ source /home/*****/.local/share/virtualenvs/my-project/bin/activate


~/path/to/****/libraries
❯ echo $VIRTUAL_ENV
/home/*****/.local/share/virtualenvs/my-project

~/path/to/****/libraries
❮ cd ..

~/path/to/****
❯ ls .mise.toml
ls: cannot access '.mise.toml': No such file or directory

~/path/to/****echo $VIRTUAL_ENV
/home/*****/.local/share/virtualenvs/my-project

# Traversing the filesystem in between folders with no mise config file does not break venv
@teaVeloper teaVeloper added the bug Something isn't working label Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant