chore(uv): update env vars map to include newly added ones (#8233)

## Summary

Add some new env var mappings

## Test Plan

Existing tests
This commit is contained in:
samypr100 2024-10-16 01:40:09 +00:00 committed by GitHub
parent 98d049407f
commit b4dca669b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 38 additions and 7 deletions

1
Cargo.lock generated
View file

@ -4206,6 +4206,7 @@ dependencies = [
"url",
"urlencoding",
"uv-once-map",
"uv-static",
"wiremock",
]

View file

@ -26,6 +26,8 @@ tracing = { workspace = true }
url = { workspace = true }
urlencoding = { workspace = true }
uv-static = { workspace = true }
[dev-dependencies]
tempfile = { workspace = true }
tokio = { workspace = true }

View file

@ -9,6 +9,8 @@ use std::io::Read;
use std::io::Write;
use url::Url;
use uv_static::EnvVars;
#[derive(Clone, Debug, PartialEq)]
pub struct Credentials {
/// The name of the user for authentication.
@ -145,8 +147,8 @@ impl Credentials {
/// `UV_HTTP_BASIC_PYTORCH_PASSWORD`.
pub fn from_env(name: &str) -> Option<Self> {
let name = name.to_uppercase();
let username = std::env::var(format!("UV_HTTP_BASIC_{name}_USERNAME")).ok();
let password = std::env::var(format!("UV_HTTP_BASIC_{name}_PASSWORD")).ok();
let username = std::env::var(EnvVars::http_basic_username(&name)).ok();
let password = std::env::var(EnvVars::http_basic_password(&name)).ok();
if username.is_none() && password.is_none() {
None
} else {

View file

@ -3880,7 +3880,7 @@ pub struct IndexArgs {
/// All indexes provided via this flag take priority over the index specified by
/// `--default-index` (which defaults to PyPI). When multiple `--index` flags are
/// provided, earlier values take priority.
#[arg(long, env = "UV_INDEX", value_delimiter = ' ', value_parser = parse_index, help_heading = "Index options")]
#[arg(long, env = EnvVars::UV_INDEX, value_delimiter = ' ', value_parser = parse_index, help_heading = "Index options")]
pub index: Option<Vec<Maybe<Index>>>,
/// The URL of the default package index (by default: <https://pypi.org/simple>).
@ -3890,7 +3890,7 @@ pub struct IndexArgs {
///
/// The index given by this flag is given lower priority than all other indexes specified via
/// the `--index` flag.
#[arg(long, env = "UV_DEFAULT_INDEX", value_parser = parse_default_index, help_heading = "Index options")]
#[arg(long, env = EnvVars::UV_DEFAULT_INDEX, value_parser = parse_default_index, help_heading = "Index options")]
pub default_index: Option<Maybe<Index>>,
/// (Deprecated: use `--default-index` instead) The URL of the Python package index (by default: <https://pypi.org/simple>).

View file

@ -2,10 +2,20 @@
pub struct EnvVars;
impl EnvVars {
/// Equivalent to the `--default-index` argument. Base index URL for searching packages.
pub const UV_DEFAULT_INDEX: &'static str = "UV_DEFAULT_INDEX";
/// Equivalent to the `--index` argument. Additional indexes for searching packages.
pub const UV_INDEX: &'static str = "UV_INDEX";
/// Equivalent to the `--index-url` argument. Base index URL for searching packages.
///
/// Deprecated: use `UV_DEFAULT_INDEX` instead.
pub const UV_INDEX_URL: &'static str = "UV_INDEX_URL";
/// Equivalent to the `--extra-index-url` argument. Additional indexes for searching packages.
///
/// Deprecated: use `UV_INDEX` instead.
pub const UV_EXTRA_INDEX_URL: &'static str = "UV_EXTRA_INDEX_URL";
/// Equivalent to the `--find-links` argument. Additional package search locations.
@ -149,6 +159,16 @@ impl EnvVars {
/// Use to control the stack size used by uv. Typically more relevant for Windows in debug mode.
pub const UV_STACK_SIZE: &'static str = "UV_STACK_SIZE";
/// Generates the environment variable key for the HTTP Basic authentication username.
pub fn http_basic_username(name: &str) -> String {
format!("UV_HTTP_BASIC_{name}_USERNAME")
}
/// Generates the environment variable key for the HTTP Basic authentication password.
pub fn http_basic_password(name: &str) -> String {
format!("UV_HTTP_BASIC_{name}_PASSWORD")
}
/// Used to set the uv commit hash at build time via `build.rs`.
pub const UV_COMMIT_HASH: &'static str = "UV_COMMIT_HASH";
@ -164,6 +184,12 @@ impl EnvVars {
/// Used to set the uv tag distance from head at build time via `build.rs`.
pub const UV_LAST_TAG_DISTANCE: &'static str = "UV_LAST_TAG_DISTANCE";
/// Used in tests for testing providing credentials via environment variables.
pub const UV_HTTP_BASIC_PROXY_USERNAME: &'static str = "UV_HTTP_BASIC_PROXY_USERNAME";
/// Used in tests for testing providing credentials via environment variables.
pub const UV_HTTP_BASIC_PROXY_PASSWORD: &'static str = "UV_HTTP_BASIC_PROXY_PASSWORD";
/// Used to set the spawning/parent interpreter when using --system in the test suite.
pub const UV_INTERNAL__PARENT_INTERPRETER: &'static str = "UV_INTERNAL__PARENT_INTERPRETER";

View file

@ -6475,8 +6475,8 @@ fn lock_env_credentials() -> Result<()> {
// Provide credentials via environment variables.
uv_snapshot!(context.filters(), context.lock()
.env("UV_HTTP_BASIC_PROXY_USERNAME", "public")
.env("UV_HTTP_BASIC_PROXY_PASSWORD", "heron"), @r###"
.env(EnvVars::UV_HTTP_BASIC_PROXY_USERNAME, "public")
.env(EnvVars::UV_HTTP_BASIC_PROXY_PASSWORD, "heron"), @r###"
success: true
exit_code: 0
----- stdout -----

View file

@ -2327,7 +2327,7 @@ fn no_prerelease_hint_source_builds() -> Result<()> {
build-backend = "setuptools.build_meta"
"#})?;
uv_snapshot!(context.filters(), context.pip_install().arg(".").env("UV_EXCLUDE_NEWER", "2018-10-08"), @r###"
uv_snapshot!(context.filters(), context.pip_install().arg(".").env(EnvVars::UV_EXCLUDE_NEWER, "2018-10-08"), @r###"
success: false
exit_code: 2
----- stdout -----