diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index ee5328f01392..5c0be05a4485 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -4300,7 +4300,7 @@ pub struct PythonInstallArgs { /// /// See `uv python dir` to view the current Python installation directory. Defaults to /// `~/.local/share/uv/python`. - #[arg(long, short, env = "UV_PYTHON_INSTALL_DIR")] + #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR)] pub install_dir: Option, /// The Python version(s) to install. @@ -4363,7 +4363,7 @@ pub struct PythonInstallArgs { #[allow(clippy::struct_excessive_bools)] pub struct PythonUninstallArgs { /// The directory where the Python was installed. - #[arg(long, short, env = "UV_PYTHON_INSTALL_DIR")] + #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR)] pub install_dir: Option, /// The Python version(s) to uninstall. diff --git a/crates/uv-static/src/env_vars.rs b/crates/uv-static/src/env_vars.rs index 667739bb5753..7f69489678d5 100644 --- a/crates/uv-static/src/env_vars.rs +++ b/crates/uv-static/src/env_vars.rs @@ -539,6 +539,14 @@ impl EnvVars { #[attr_hidden] pub const KEYRING_TEST_CREDENTIALS: &'static str = "KEYRING_TEST_CREDENTIALS"; + /// Used to set the vendor links url for tests. + #[attr_hidden] + pub const UV_TEST_VENDOR_LINKS_URL: &'static str = "UV_TEST_VENDOR_LINKS_URL"; + + /// Used to set an index url for tests. + #[attr_hidden] + pub const UV_TEST_INDEX_URL: &'static str = "UV_TEST_INDEX_URL"; + /// `.env` files from which to load environment variables when executing `uv run` commands. pub const UV_ENV_FILE: &'static str = "UV_ENV_FILE"; diff --git a/crates/uv/tests/it/common/mod.rs b/crates/uv/tests/it/common/mod.rs index 7f3d70925450..7d653a1ab38c 100644 --- a/crates/uv/tests/it/common/mod.rs +++ b/crates/uv/tests/it/common/mod.rs @@ -37,13 +37,15 @@ pub const PACKSE_VERSION: &str = "0.3.42"; /// Using a find links url allows using `--index-url` instead of `--extra-index-url` in tests /// to prevent dependency confusion attacks against our test suite. pub fn build_vendor_links_url() -> String { - env::var("UV_TEST_VENDOR_LINKS_URL").ok().unwrap_or(format!( - "https://raw.githubusercontent.com/astral-sh/packse/{PACKSE_VERSION}/vendor/links.html" - )) + env::var(EnvVars::UV_TEST_VENDOR_LINKS_URL) + .ok() + .unwrap_or(format!( + "https://raw.githubusercontent.com/astral-sh/packse/{PACKSE_VERSION}/vendor/links.html" + )) } pub fn packse_index_url() -> String { - env::var("UV_TEST_INDEX_URL").ok().unwrap_or(format!( + env::var(EnvVars::UV_TEST_INDEX_URL).ok().unwrap_or(format!( "https://astral-sh.github.io/packse/{PACKSE_VERSION}/simple-html/" )) } diff --git a/crates/uv/tests/it/python_find.rs b/crates/uv/tests/it/python_find.rs index 6aeb5f25b469..5a194dfc21ab 100644 --- a/crates/uv/tests/it/python_find.rs +++ b/crates/uv/tests/it/python_find.rs @@ -593,7 +593,7 @@ fn python_find_venv_invalid() { "###); // Unless the virtual environment is not active - uv_snapshot!(context.filters(), context.python_find().env_remove("VIRTUAL_ENV"), @r###" + uv_snapshot!(context.filters(), context.python_find().env_remove(EnvVars::VIRTUAL_ENV), @r###" success: true exit_code: 0 ----- stdout ----- diff --git a/crates/uv/tests/it/run.rs b/crates/uv/tests/it/run.rs index 8feecd781944..bab0afa9f14c 100644 --- a/crates/uv/tests/it/run.rs +++ b/crates/uv/tests/it/run.rs @@ -3173,7 +3173,7 @@ fn run_with_multiple_env_files() -> Result<()> { ----- stderr ----- "###); - uv_snapshot!(context.filters(), context.run().arg("test.py").env("UV_ENV_FILE", ".env1 .env2"), @r###" + uv_snapshot!(context.filters(), context.run().arg("test.py").env(EnvVars::UV_ENV_FILE, ".env1 .env2"), @r###" success: false exit_code: 2 ----- stdout ----- diff --git a/crates/uv/tests/it/show_settings.rs b/crates/uv/tests/it/show_settings.rs index 0a9a01d03e65..fb8ea039f9ef 100644 --- a/crates/uv/tests/it/show_settings.rs +++ b/crates/uv/tests/it/show_settings.rs @@ -5556,7 +5556,7 @@ fn verify_hashes() -> anyhow::Result<()> { uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path()) .arg("-r") .arg("requirements.in") - .env("UV_NO_VERIFY_HASHES", "1") + .env(EnvVars::UV_NO_VERIFY_HASHES, "1") .arg("--show-settings"), @r###" success: true exit_code: 0 diff --git a/crates/uv/tests/it/venv.rs b/crates/uv/tests/it/venv.rs index cac2d79a2338..127b52907b8d 100644 --- a/crates/uv/tests/it/venv.rs +++ b/crates/uv/tests/it/venv.rs @@ -1117,7 +1117,7 @@ fn create_venv_apostrophe() { // One of them should be commonly available on a linux developer machine, if not, we have to // extend the fallbacks. - let shell = env::var_os("SHELL").unwrap_or(OsString::from("bash")); + let shell = env::var_os(EnvVars::SHELL).unwrap_or(OsString::from("bash")); let mut child = Command::new(shell) .stdin(Stdio::piped()) .stdout(Stdio::piped())