Legacy version files interact weirdly with Python virtualenv creation
Describe the bug
I discovered this by accident, but it looks like when you have a relative path to a Python virtualenv specified in .mise.toml and then a legacy version file in a lower directory, mise wants to create the virtualenv relative to the lower directory and not the project root.
To Reproduce
.mise.toml:
[tools]
python = {version="3.11.5", virtualenv="project1/.ve"}
- This directory structure:
❯ tree
.
├── project1
└── project2
├── sub1
└── sub2
└── main.tf
cd project2/sub2:
❯ cd project2/sub2/
mise no venv found at: ~/tmp/mise-bug/project2/sub2/project1/.ve
To have mise automatically create virtualenvs, run:
mise settings set python_venv_auto_create true
To create a virtualenv manually, run:
python -m venv ~/tmp/mise-bug/project2/sub2/project1/.ve
Expected behavior
mise should not want to create a virtualenv at project2/sub2/project1/.ve; it should only create it at project1/.ve.
mise doctor output
mise version:
2024.1.14 macos-arm64 (2024-01-09)
build:
Target: aarch64-apple-darwin
Features: DEFAULT, NATIVE_TLS
Built: Tue, 9 Jan 2024 02:34:36 +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/andyfreeland/.local/share/mise
mise environment variables:
MISE_SHELL=fish
mise settings file:
~/.config/mise/settings.toml
settings:
{
"all_compile": false,
"always_keep_download": false,
"always_keep_install": false,
"asdf_compat": false,
"color": true,
"disable_default_shorthands": false,
"disable_tools": [],
"experimental": true,
"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_compile": false,
"python_venv_auto_create": false,
"raw": false,
"shorthands_file": null,
"task_output": null,
"trusted_config_paths": [],
"quiet": false,
"verbose": false,
"yes": false,
"ci": false,
"cd": null,
"debug": false,
"env_file": null,
"trace": false,
"log_level": "info"
}
config files:
~/.tool-versions
~/.config/mise/config.toml
~/tmp/mise-bug/.mise.toml
~/tmp/mise-bug/project2/sub2/main.tf
plugins:
bun (core)
deno (core)
erlang (core)
go (core)
java (core)
node (core)
python (core)
ruby (core)
terraform https://github.com/asdf-community/asdf-hashicorp.git#0346f5d
toolset:
[email protected], node@system
No problems found
hmm yeah, it sets the root to the "project root" but that is the root of the top config file, not the current one that the venv is defined in.
I think you might be able to work around this with the following:
[tools]
python = {version="3.12", virtualenv="{{config_root}}/.venv"}
not sure though. This should be fixed regardless.
Yeah for now I'm working around it by disabling legacy version files, since I don't actually use them in my projects.