Skip to content
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
45 changes: 33 additions & 12 deletions crates/uv-settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,12 +654,19 @@ impl EnvironmentOptions {
pub fn new() -> Result<Self, Error> {
// Timeout options, matching https://doc.rust-lang.org/nightly/cargo/reference/config.html#httptimeout
// `UV_REQUEST_TIMEOUT` is provided for backwards compatibility with v0.1.6
let http_timeout = parse_integer_environment_variable(EnvVars::UV_HTTP_TIMEOUT)?
.or(parse_integer_environment_variable(
EnvVars::UV_REQUEST_TIMEOUT,
)?)
.or(parse_integer_environment_variable(EnvVars::HTTP_TIMEOUT)?)
.map(Duration::from_secs);
let http_timeout = parse_integer_environment_variable(
EnvVars::UV_HTTP_TIMEOUT,
Some("value should be an integer number of seconds"),
)?
.or(parse_integer_environment_variable(
EnvVars::UV_REQUEST_TIMEOUT,
Some("value should be an integer number of seconds"),
)?)
.or(parse_integer_environment_variable(
EnvVars::HTTP_TIMEOUT,
Some("value should be an integer number of seconds"),
)?)
.map(Duration::from_secs);

Ok(Self {
skip_wheel_filename_check: parse_boolish_environment_variable(
Expand All @@ -671,9 +678,15 @@ impl EnvironmentOptions {
EnvVars::UV_PYTHON_INSTALL_REGISTRY,
)?,
concurrency: Concurrency {
downloads: parse_integer_environment_variable(EnvVars::UV_CONCURRENT_DOWNLOADS)?,
builds: parse_integer_environment_variable(EnvVars::UV_CONCURRENT_BUILDS)?,
installs: parse_integer_environment_variable(EnvVars::UV_CONCURRENT_INSTALLS)?,
downloads: parse_integer_environment_variable(
EnvVars::UV_CONCURRENT_DOWNLOADS,
None,
)?,
builds: parse_integer_environment_variable(EnvVars::UV_CONCURRENT_BUILDS, None)?,
installs: parse_integer_environment_variable(
EnvVars::UV_CONCURRENT_INSTALLS,
None,
)?,
},
install_mirrors: PythonInstallMirrors {
python_install_mirror: parse_string_environment_variable(
Expand All @@ -690,12 +703,13 @@ impl EnvironmentOptions {
lfs: parse_boolish_environment_variable(EnvVars::UV_GIT_LFS)?,
upload_http_timeout: parse_integer_environment_variable(
EnvVars::UV_UPLOAD_HTTP_TIMEOUT,
Some("value should be an integer number of seconds"),
)?
.map(Duration::from_secs)
.or(http_timeout)
.unwrap_or(Duration::from_mins(15)),
http_timeout: http_timeout.unwrap_or(Duration::from_secs(30)),
http_retries: parse_integer_environment_variable(EnvVars::UV_HTTP_RETRIES)?
http_retries: parse_integer_environment_variable(EnvVars::UV_HTTP_RETRIES, None)?
.unwrap_or(uv_client::DEFAULT_RETRIES),
#[cfg(feature = "tracing-durations-export")]
tracing_durations_file: parse_path_environment_variable(
Expand Down Expand Up @@ -746,7 +760,10 @@ fn parse_string_environment_variable(name: &'static str) -> Result<Option<String
}
}

fn parse_integer_environment_variable<T>(name: &'static str) -> Result<Option<T>, Error>
fn parse_integer_environment_variable<T>(
name: &'static str,
help: Option<&str>,
) -> Result<Option<T>, Error>
where
T: std::str::FromStr + Copy,
<T as std::str::FromStr>::Err: std::fmt::Display,
Expand Down Expand Up @@ -776,7 +793,11 @@ where
InvalidEnvironmentVariable {
name: name.to_string(),
value,
err: err.to_string(),
err: if let Some(help) = help {
format!("{err}; {help}")
} else {
err.to_string()
},
},
)),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/tests/it/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ fn create_venv_with_invalid_http_timeout() {
----- stdout -----

----- stderr -----
error: Failed to parse environment variable `UV_HTTP_TIMEOUT` with invalid value `not_a_number`: invalid digit found in string
error: Failed to parse environment variable `UV_HTTP_TIMEOUT` with invalid value `not_a_number`: invalid digit found in string; value should be an integer number of seconds
");
}

Expand Down
Loading