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

fix: create venv uses absolute tool paths #3698

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion registry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ concourse.backends = [
"asdf:mattysweeps/asdf-concourse"
]
conduit.backends = ["ubi:ConduitIO/conduit", "asdf:gmcabrita/asdf-conduit"]
conduit.test = ["conduit --version", "v{{version}}"]
conduit.test = ["conduit --version", "v{{version}}"]
conform.backends = ["aqua:siderolabs/conform", "asdf:skyzyx/asdf-conform"]
conform.os = ["linux", "macos"]
conform.test = ["conform version", "conform version v{{version}}"]
Expand Down
66 changes: 43 additions & 23 deletions src/config/env_directive/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,24 @@ impl EnvResults {
let config = Config::get();
let ts = ToolsetBuilder::new().build(&config)?;
let ba = BackendArg::from("python");
let installed = ts
.versions
.get(&ba)
.and_then(|tv| {
// if a python version is specified, check if that version is installed
// otherwise use the first since that's what `python3` will refer to
if let Some(v) = &python {
tv.versions.iter().find(|t| t.version.starts_with(v))
} else {
tv.versions.first()
}
})
.map(|tv| {
let tv = ts.versions.get(&ba).and_then(|tv| {
// if a python version is specified, check if that version is installed
// otherwise use the first since that's what `python3` will refer to
if let Some(v) = &python {
tv.versions.iter().find(|t| t.version.starts_with(v))
} else {
tv.versions.first()
}
});
let python_path = tv.map(|tv| {
tv.install_path()
.join("bin")
.join("python")
.to_string_lossy()
.to_string()
});
let installed = tv
.map(|tv: &crate::toolset::ToolVersion| {
let backend = backend::get(&ba).unwrap();
backend.is_version_installed(tv, false)
})
Expand All @@ -59,12 +64,12 @@ impl EnvResults {
.unwrap_or(true);
if !installed {
warn!(
"no venv found at: {p}\n\n\
mise will automatically create the venv once all requested python versions are installed.\n\
To install the missing python versions and create the venv, please run:\n\
mise install",
p = display_path(&venv)
);
"no venv found at: {p}\n\n\
mise will automatically create the venv once all requested python versions are installed.\n\
To install the missing python versions and create the venv, please run:\n\
mise install",
p = display_path(&venv)
);
} else {
let has_uv_bin = ts.which("uv").is_some() || which_non_pristine("uv").is_some();
let use_uv = !SETTINGS.python.venv_stdlib && has_uv_bin;
Expand All @@ -84,9 +89,15 @@ impl EnvResults {
.or(uv_create_args)
.unwrap_or_default();
let mut cmd = CmdLineRunner::new("uv").args(["venv", &venv.to_string_lossy()]);
if let Some(python) = python {
cmd = cmd.args(["--python", &python]);
}

cmd = match (python_path, python) {
// The selected mise managed python tool path from env._.python.venv.python or first in list
(Some(python_path), _) => cmd.args(["--python", &python_path]),
// User specified in env._.python.venv.python but it's not in mise tools, so pass version number to uv
(_, Some(python)) => cmd.args(["--python", &python]),
// Default to whatever uv wants to use
_ => cmd,
};
cmd.args(extra)
} else {
info!("creating venv with stdlib at: {}", display_path(&venv));
Expand All @@ -103,7 +114,16 @@ impl EnvResults {
})
.or(python_create_args)
.unwrap_or_default();
let bin = format!("python{}", python.unwrap_or("3".into()));

let bin = match (python_path, python) {
// The selected mise managed python tool path from env._.python.venv.python or first in list
(Some(python_path), _) => python_path,
// User specified in env._.python.venv.python but it's not in mise tools, so try to find it on path
(_, Some(python)) => format!("python{}", python),
// Default to whatever python3 points to on path
_ => "python3".to_string(),
};

CmdLineRunner::new(bin)
.args(["-m", "venv", &venv.to_string_lossy()])
.args(extra)
Expand Down
32 changes: 0 additions & 32 deletions tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,6 @@

- **Usage**: `clean`

## `docker:cargo`

- **Usage**: `docker:cargo`

run cargo inside of development docker container

## `docker:e2e`

- **Usage**: `docker:e2e`

run e2e tests inside of development docker container

## `docker:image`

- **Usage**: `docker:image`

build docker image from Dockerfile

## `docker:mise`

- **Usage**: `docker:mise`

run mise inside of development docker container

## `docker:run`

- Depends: docker:image

- **Usage**: `docker:run`

run a command inside of development docker container

## `docs`

- Depends: docs:setup
Expand Down
10 changes: 5 additions & 5 deletions tasks.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,28 @@ run = "cargo test --all-features"
env = { CARGO_TERM_COLOR = "always", "RUST_TEST_THREADS" = "1" }

["docker:image"]
hide = true # docker stuff is not working correctly right now
hide = true # docker stuff is not working correctly right now
description = "build docker image from Dockerfile"
run = 'docker build --build-arg GITHUB_TOKEN=$GITHUB_API_TOKEN $root -f $root/packaging/dev/Dockerfile -t ghcr.io/jdx/mise:dev'

["docker:run"]
hide = true # docker stuff is not working correctly right now
hide = true # docker stuff is not working correctly right now
description = "run a command inside of development docker container"
run = 'docker run -ti --rm -e GITHUB_API_TOKEN -e TEST_ALL -v $root:/mise -v /tmp/mise/target:/tmp/mise/target -v /tmp/mise/registry:/tmp/mise/registry -w /mise ghcr.io/jdx/mise:dev'
depends = ["docker:image"]

["docker:cargo"]
hide = true # docker stuff is not working correctly right now
hide = true # docker stuff is not working correctly right now
description = "run cargo inside of development docker container"
run = 'mise tasks run docker:run cargo'

["docker:mise"]
hide = true # docker stuff is not working correctly right now
hide = true # docker stuff is not working correctly right now
description = "run mise inside of development docker container"
run = "mise tasks run -- docker:cargo run --"

["docker:e2e"]
hide = true # docker stuff is not working correctly right now
hide = true # docker stuff is not working correctly right now
description = "run e2e tests inside of development docker container"
run = "mise tasks run docker:mise run test:e2e"

Expand Down
Loading