Skip to content

Commit

Permalink
Sync env vars with uv-static crate 🧹 (#10016)
Browse files Browse the repository at this point in the history
## Summary

Updates some env vars references to use `EnvVars` accordingly.
  • Loading branch information
samypr100 authored Dec 19, 2024
1 parent 1d8dac1 commit e65a273
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,

/// The Python version(s) to install.
Expand Down Expand Up @@ -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<PathBuf>,

/// The Python version(s) to uninstall.
Expand Down
8 changes: 8 additions & 0 deletions crates/uv-static/src/env_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
10 changes: 6 additions & 4 deletions crates/uv/tests/it/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/tests/it/python_find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 -----
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/tests/it/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 -----
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/tests/it/show_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -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())
Expand Down

0 comments on commit e65a273

Please sign in to comment.