Repository: servo/servo
File: components/servo/build.rs (Rust)

Code before:
                "`{} {:?}` failed with {}",
                program,
                args,
                String::from_utf8_lossy(&output.stderr)
            ))
        };
    }
    Err(format!(
        "`{} {:?}` failed to run (is it installed?)",
        program, args
    ))
}

/// Tries to find a suitable python, which in Servo is always `uv run python`.
///
/// To be accommodating to different environments, which may manage python differently, we fallback
/// to `python3` and `python` in that order.
///
/// Note: This function should be kept in sync with the version in `components/script_bindings/build.rs`
fn find_python() -> Command {
    // Test uv first - if it works, create a FRESH command to return
    let uv_result = try_python_command("uv", &["run", "--frozen", "python"])
        .inspect_err(|e| println!("cargo:warning={e}"));
    if uv_result.is_ok() {
        let mut cmd = Command::new("uv");
        cmd.args(["run", "python"]);
        return cmd;
    }

    println!(
        "cargo:warning=`uv` not found - Falling back to the default python! \
        If the build fails, please install uv and make sure it is in your PATH or make sure \
        to provision a python environment >= python 3.11."
    );

    let python3_result = try_python_command("python3", &[]);
    if python3_result.is_ok() {
        return Command::new("python3");
    }

    let python_result = try_python_command("python", &[]);
    if python_result.is_ok() {
        return Command::new("python");
    }

    // We first try `python` before printing an error for `python3`, since python3 is often missing
    // provided via python on Windows (but not necessarily on linux).
    println!("cargo:warning={}", python3_result.unwrap_err());
    println!("cargo:warning={}", python_result.unwrap_err());

    panic!("No suitable python found! Tried: `uv run python`, `python3`, `python`.");

Review comment (suggestion):
https://github.com/servo/servo/actions/runs/21902078794/job/63232762891?pr=42532#step:10:52

Added `--frozen` to Python testing command, which fixed the early return. But I think we need it for real command too? Right now the real command has problem.
```suggestion
        cmd.args(["run", "--frozen", "python"]);
```

Code after:
                "`{} {:?}` failed with {}",
                program,
                args,
                String::from_utf8_lossy(&output.stderr)
            ))
        };
    }
    Err(format!(
        "`{} {:?}` failed to run (is it installed?)",
        program, args
    ))
}

/// Tries to find a suitable python, which in Servo is always `uv run python`.
///
/// To be accommodating to different environments, which may manage python differently, we fallback
/// to `python3` and `python` in that order.
///
/// Note: This function should be kept in sync with the version in `components/script_bindings/build.rs`
fn find_python() -> Command {
    // Test uv first - if it works, create a FRESH command to return
    let uv_result = try_python_command("uv", &["run", "--frozen", "python"])
        .inspect_err(|e| println!("cargo:warning={e}"));
    if uv_result.is_ok() {
        let mut cmd = Command::new("uv");
        cmd.args(["run", "--frozen", "python"]);
        return cmd;
    }

    println!(
        "cargo:warning=`uv` not found - Falling back to the default python! \
        If the build fails, please install uv and make sure it is in your PATH or make sure \
        to provision a python environment >= python 3.11."
    );

    let python3_result = try_python_command("python3", &[]);
    if python3_result.is_ok() {
        return Command::new("python3");
    }

    let python_result = try_python_command("python", &[]);
    if python_result.is_ok() {
        return Command::new("python");
    }

    // We first try `python` before printing an error for `python3`, since python3 is often missing
    // provided via python on Windows (but not necessarily on linux).
    println!("cargo:warning={}", python3_result.unwrap_err());
    println!("cargo:warning={}", python_result.unwrap_err());

    panic!("No suitable python found! Tried: `uv run python`, `python3`, `python`.");