Repository: astral-sh/uv
File: crates/uv-installer/src/compile.rs (Rust)

Code before:
) -> Result<usize, CompileError> {
    debug_assert!(
        dir.is_absolute(),
        "compileall doesn't work with relative paths: `{}`",
        dir.display()
    );
    let worker_count = concurrency.installs;

    // A larger buffer is significantly faster than just 1 or the worker count.
    let (sender, receiver) = async_channel::bounded::<PathBuf>(worker_count * 10);

    // Running Python with an actual file will produce better error messages.
    let tempdir = tempdir_in(cache).map_err(CompileError::TempFile)?;
    let pip_compileall_py = tempdir.path().join("pip_compileall.py");

    let timeout: Option<Duration> = env::var(EnvVars::UV_COMPILE_BYTECODE_TIMEOUT)
        .map(|value| {
            // 0 indicates no timeout
            if value == "0" {
                None
            } else {
                Some(value.parse::<u64>()
                    .map(Duration::from_secs)
                    .or_else(|_| {
                        // On parse error, warn and use the default timeout
                        warn_user_once!("Ignoring invalid value from environment for `UV_COMPILE_BYTECODE_TIMEOUT`. Expected an integer number of seconds, got \"{value}\".");
                        Ok::<Duration, ParseIntError>(DEFAULT_COMPILE_TIMEOUT)
                    })
                    .unwrap_or(DEFAULT_COMPILE_TIMEOUT))
            }
        })
        .unwrap_or(Some(DEFAULT_COMPILE_TIMEOUT));
    if let Some(duration) = timeout {
        debug!(
            "Using bytecode compilation timeout of {}s",
            duration.as_secs()
        );
    } else {
        debug!("Disabling bytecode compilation timeout");
    }

    debug!("Starting {} bytecode compilation workers", worker_count);
    let mut worker_handles = Vec::new();
    for _ in 0..worker_count {
        let (tx, rx) = oneshot::channel();

        let worker = worker(
            dir.to_path_buf(),
            python_executable.to_path_buf(),
            pip_compileall_py.clone(),
            receiver.clone(),

Review comment (bug):
We should probably error here though, I don't think we have much precedent for warning on invalid options.

Code after:
    cache: &Path,
) -> Result<usize, CompileError> {
    debug_assert!(
        dir.is_absolute(),
        "compileall doesn't work with relative paths: `{}`",
        dir.display()
    );
    let worker_count = concurrency.installs;

    // A larger buffer is significantly faster than just 1 or the worker count.
    let (sender, receiver) = async_channel::bounded::<PathBuf>(worker_count * 10);

    // Running Python with an actual file will produce better error messages.
    let tempdir = tempdir_in(cache).map_err(CompileError::TempFile)?;
    let pip_compileall_py = tempdir.path().join("pip_compileall.py");

    let timeout: Option<Duration> = match env::var(EnvVars::UV_COMPILE_BYTECODE_TIMEOUT) {
        Ok(value) => {
            if value == "0" {
                debug!("Disabling bytecode compilation timeout");
                None
            } else {
                if let Ok(duration) = value.parse::<u64>().map(Duration::from_secs) {
                    debug!(
                        "Using bytecode compilation timeout of {}s",
                        duration.as_secs()
                    );
                    Some(duration)
                } else {
                    return Err(CompileError::EnvironmentError {
                        var: "UV_COMPILE_BYTECODE_TIMEOUT",
                        message: format!("Expected an integer number of seconds, got \"{value}\""),
                    });
                }
            }
        }
        Err(_) => Some(DEFAULT_COMPILE_TIMEOUT),
    };

    debug!("Starting {} bytecode compilation workers", worker_count);
    let mut worker_handles = Vec::new();
    for _ in 0..worker_count {
        let (tx, rx) = oneshot::channel();

        let worker = worker(
            dir.to_path_buf(),
            python_executable.to_path_buf(),
            pip_compileall_py.clone(),
            receiver.clone(),
            timeout,
        );