Skip to content

Commit e65a273

Browse files
authored
Sync env vars with uv-static crate 🧹 (#10016)
## Summary Updates some env vars references to use `EnvVars` accordingly.
1 parent 1d8dac1 commit e65a273

File tree

7 files changed

+20
-10
lines changed

7 files changed

+20
-10
lines changed

crates/uv-cli/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4300,7 +4300,7 @@ pub struct PythonInstallArgs {
43004300
///
43014301
/// See `uv python dir` to view the current Python installation directory. Defaults to
43024302
/// `~/.local/share/uv/python`.
4303-
#[arg(long, short, env = "UV_PYTHON_INSTALL_DIR")]
4303+
#[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR)]
43044304
pub install_dir: Option<PathBuf>,
43054305

43064306
/// The Python version(s) to install.
@@ -4363,7 +4363,7 @@ pub struct PythonInstallArgs {
43634363
#[allow(clippy::struct_excessive_bools)]
43644364
pub struct PythonUninstallArgs {
43654365
/// The directory where the Python was installed.
4366-
#[arg(long, short, env = "UV_PYTHON_INSTALL_DIR")]
4366+
#[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR)]
43674367
pub install_dir: Option<PathBuf>,
43684368

43694369
/// The Python version(s) to uninstall.

crates/uv-static/src/env_vars.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,14 @@ impl EnvVars {
539539
#[attr_hidden]
540540
pub const KEYRING_TEST_CREDENTIALS: &'static str = "KEYRING_TEST_CREDENTIALS";
541541

542+
/// Used to set the vendor links url for tests.
543+
#[attr_hidden]
544+
pub const UV_TEST_VENDOR_LINKS_URL: &'static str = "UV_TEST_VENDOR_LINKS_URL";
545+
546+
/// Used to set an index url for tests.
547+
#[attr_hidden]
548+
pub const UV_TEST_INDEX_URL: &'static str = "UV_TEST_INDEX_URL";
549+
542550
/// `.env` files from which to load environment variables when executing `uv run` commands.
543551
pub const UV_ENV_FILE: &'static str = "UV_ENV_FILE";
544552

crates/uv/tests/it/common/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ pub const PACKSE_VERSION: &str = "0.3.42";
3737
/// Using a find links url allows using `--index-url` instead of `--extra-index-url` in tests
3838
/// to prevent dependency confusion attacks against our test suite.
3939
pub fn build_vendor_links_url() -> String {
40-
env::var("UV_TEST_VENDOR_LINKS_URL").ok().unwrap_or(format!(
41-
"https://raw.githubusercontent.com/astral-sh/packse/{PACKSE_VERSION}/vendor/links.html"
42-
))
40+
env::var(EnvVars::UV_TEST_VENDOR_LINKS_URL)
41+
.ok()
42+
.unwrap_or(format!(
43+
"https://raw.githubusercontent.com/astral-sh/packse/{PACKSE_VERSION}/vendor/links.html"
44+
))
4345
}
4446

4547
pub fn packse_index_url() -> String {
46-
env::var("UV_TEST_INDEX_URL").ok().unwrap_or(format!(
48+
env::var(EnvVars::UV_TEST_INDEX_URL).ok().unwrap_or(format!(
4749
"https://astral-sh.github.io/packse/{PACKSE_VERSION}/simple-html/"
4850
))
4951
}

crates/uv/tests/it/python_find.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ fn python_find_venv_invalid() {
593593
"###);
594594

595595
// Unless the virtual environment is not active
596-
uv_snapshot!(context.filters(), context.python_find().env_remove("VIRTUAL_ENV"), @r###"
596+
uv_snapshot!(context.filters(), context.python_find().env_remove(EnvVars::VIRTUAL_ENV), @r###"
597597
success: true
598598
exit_code: 0
599599
----- stdout -----

crates/uv/tests/it/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3173,7 +3173,7 @@ fn run_with_multiple_env_files() -> Result<()> {
31733173
----- stderr -----
31743174
"###);
31753175

3176-
uv_snapshot!(context.filters(), context.run().arg("test.py").env("UV_ENV_FILE", ".env1 .env2"), @r###"
3176+
uv_snapshot!(context.filters(), context.run().arg("test.py").env(EnvVars::UV_ENV_FILE, ".env1 .env2"), @r###"
31773177
success: false
31783178
exit_code: 2
31793179
----- stdout -----

crates/uv/tests/it/show_settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5556,7 +5556,7 @@ fn verify_hashes() -> anyhow::Result<()> {
55565556
uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path())
55575557
.arg("-r")
55585558
.arg("requirements.in")
5559-
.env("UV_NO_VERIFY_HASHES", "1")
5559+
.env(EnvVars::UV_NO_VERIFY_HASHES, "1")
55605560
.arg("--show-settings"), @r###"
55615561
success: true
55625562
exit_code: 0

crates/uv/tests/it/venv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ fn create_venv_apostrophe() {
11171117

11181118
// One of them should be commonly available on a linux developer machine, if not, we have to
11191119
// extend the fallbacks.
1120-
let shell = env::var_os("SHELL").unwrap_or(OsString::from("bash"));
1120+
let shell = env::var_os(EnvVars::SHELL).unwrap_or(OsString::from("bash"));
11211121
let mut child = Command::new(shell)
11221122
.stdin(Stdio::piped())
11231123
.stdout(Stdio::piped())

0 commit comments

Comments
 (0)