This commit is contained in:
llama 2025-12-31 19:47:19 +01:00 committed by GitHub
commit 61dee280c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 7 deletions

View file

@ -3,6 +3,7 @@
use std::env;
use anki_io::read_file;
use anyhow::Result;
use camino::Utf8Path;
use maplit::hashmap;
@ -123,7 +124,7 @@ pub struct PythonEnvironment {
impl BuildAction for PythonEnvironment {
fn command(&self) -> &str {
if env::var("OFFLINE_BUILD").is_err() {
"$runner pyenv $uv_binary $builddir/$pyenv_folder -- $extra_args"
"$runner pyenv $uv_binary $builddir/$pyenv_folder $python -- $extra_args"
} else {
"echo 'OFFLINE_BUILD is set. Using the existing PythonEnvironment.'"
}
@ -145,12 +146,17 @@ impl BuildAction for PythonEnvironment {
if env::var("OFFLINE_BUILD").is_err() {
build.add_inputs("uv_binary", inputs![":uv_binary"]);
// Add --python flag to extra_args if PYTHON_BINARY is set
let mut args = self.extra_args.to_string();
if let Ok(python_binary) = env::var("PYTHON_BINARY") {
args = format!("--python {python_binary} {args}");
}
build.add_variable("extra_args", args);
// Set --python flag to .python-version (--no-config ignores it)
// override if PYTHON_BINARY is set
let python = env::var("PYTHON_BINARY").unwrap_or_else(|_| {
let python_version =
read_file(".python-version").expect("No .python-version in cwd");
let python_version_str =
String::from_utf8(python_version).expect("Invalid UTF-8 in .python-version");
python_version_str.trim().to_string()
});
build.add_variable("python", python);
build.add_variable("extra_args", self.extra_args);
}
build.add_outputs_ext("bin", bin_path("python"), true);

View file

@ -13,6 +13,7 @@ use crate::run::run_command;
pub struct PyenvArgs {
uv_bin: String,
pyenv_folder: String,
python: String,
#[arg(trailing_var_arg = true)]
extra_args: Vec<String>,
}
@ -45,6 +46,7 @@ pub fn setup_pyenv(args: PyenvArgs) {
command
.env("UV_PROJECT_ENVIRONMENT", args.pyenv_folder.clone())
.args(["sync", "--locked", "--no-config"])
.args(["--python", &args.python])
.args(args.extra_args),
);