Skip to content

Commit 647494b

Browse files
authored
docs: env var doc improvements (#8777)
## Summary * Env docs now support anchors, which allows sending a link to someone with a direct reference to an env var or cross-reference them in the docs. * Marked additional env vars as hidden from the docs due to their internal use * Updates some tests still using literals to use the static env vars ## Test Plan <img width="1370" alt="env_var_anchors" src="https://github.com/user-attachments/assets/52ae1caa-5199-4798-9eb5-81b8f5b57c24">
1 parent f52814e commit 647494b

File tree

8 files changed

+130
-131
lines changed

8 files changed

+130
-131
lines changed

crates/uv-dev/src/generate_env_vars_reference.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ fn generate() -> String {
8888
})
8989
.collect::<Vec<_>>()
9090
.join("\n");
91-
output.push_str(&format!("- `{var}`: {doc}\n"));
91+
output.push_str(&format!(
92+
"- <a id=\"{var}\"></a> [`{var}`](#{var}): {doc}\n"
93+
));
9294
}
9395

9496
output

crates/uv-static/src/env_vars.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ impl EnvVars {
185185
/// packages.
186186
pub const UV_CONCURRENT_INSTALLS: &'static str = "UV_CONCURRENT_INSTALLS";
187187

188+
/// Disables all progress output. For example, spinners and progress bars.
189+
pub const UV_NO_PROGRESS: &'static str = "UV_NO_PROGRESS";
190+
188191
/// Specifies the directory where uv stores managed tools.
189192
pub const UV_TOOL_DIR: &'static str = "UV_TOOL_DIR";
190193

@@ -370,9 +373,6 @@ impl EnvVars {
370373
/// See [no-color.org](https://no-color.org).
371374
pub const NO_COLOR: &'static str = "NO_COLOR";
372375

373-
/// Disables all progress output. For example, spinners and progress bars.
374-
pub const UV_NO_PROGRESS: &'static str = "UV_NO_PROGRESS";
375-
376376
/// Forces colored output regardless of terminal support.
377377
///
378378
/// See [force-color.org](https://force-color.org).
@@ -397,18 +397,23 @@ impl EnvVars {
397397
pub const LOCALAPPDATA: &'static str = "LOCALAPPDATA";
398398

399399
/// Path to the `.git` directory. Ignored by `uv` when performing fetch.
400+
#[attr_hidden]
400401
pub const GIT_DIR: &'static str = "GIT_DIR";
401402

402403
/// Path to the git working tree. Ignored by `uv` when performing fetch.
404+
#[attr_hidden]
403405
pub const GIT_WORK_TREE: &'static str = "GIT_WORK_TREE";
404406

405407
/// Path to the index file for staged changes. Ignored by `uv` when performing fetch.
408+
#[attr_hidden]
406409
pub const GIT_INDEX_FILE: &'static str = "GIT_INDEX_FILE";
407410

408411
/// Path to where git object files are located. Ignored by `uv` when performing fetch.
412+
#[attr_hidden]
409413
pub const GIT_OBJECT_DIRECTORY: &'static str = "GIT_OBJECT_DIRECTORY";
410414

411415
/// Alternate locations for git objects. Ignored by `uv` when performing fetch.
416+
#[attr_hidden]
412417
pub const GIT_ALTERNATE_OBJECT_DIRECTORIES: &'static str = "GIT_ALTERNATE_OBJECT_DIRECTORIES";
413418

414419
/// Used in tests for better git isolation.
@@ -419,6 +424,7 @@ impl EnvVars {
419424
/// `GIT_CEILING_DIRECTORIES=/home/andrew/.local/share/uv/tests` will
420425
/// prevent git from crawling up the directory tree past that point to find
421426
/// parent git repositories.
427+
#[attr_hidden]
422428
pub const GIT_CEILING_DIRECTORIES: &'static str = "GIT_CEILING_DIRECTORIES";
423429

424430
/// Used for trusted publishing via `uv publish`.
@@ -431,18 +437,26 @@ impl EnvVars {
431437
pub const ACTIONS_ID_TOKEN_REQUEST_TOKEN: &'static str = "ACTIONS_ID_TOKEN_REQUEST_TOKEN";
432438

433439
/// Sets the encoding for standard I/O streams (e.g., PYTHONIOENCODING=utf-8).
440+
#[attr_hidden]
434441
pub const PYTHONIOENCODING: &'static str = "PYTHONIOENCODING";
435442

436443
/// Forces unbuffered I/O streams, equivalent to `-u` in Python.
444+
#[attr_hidden]
437445
pub const PYTHONUNBUFFERED: &'static str = "PYTHONUNBUFFERED";
438446

439447
/// Enables UTF-8 mode for Python, equivalent to `-X utf8`.
448+
#[attr_hidden]
440449
pub const PYTHONUTF8: &'static str = "PYTHONUTF8";
441450

442451
/// Adds directories to Python module search path (e.g., PYTHONPATH=/path/to/modules).
443452
pub const PYTHONPATH: &'static str = "PYTHONPATH";
444453

454+
/// Used in tests to enforce a consistent locale setting.
455+
#[attr_hidden]
456+
pub const LC_ALL: &'static str = "LC_ALL";
457+
445458
/// Typically set by CI runners, used to detect a CI runner.
459+
#[attr_hidden]
446460
pub const CI: &'static str = "CI";
447461

448462
/// Use to set the .netrc file location.
@@ -455,6 +469,7 @@ impl EnvVars {
455469
pub const JPY_SESSION_NAME: &'static str = "JPY_SESSION_NAME";
456470

457471
/// Use to create the tracing root directory via the `tracing-durations-export` feature.
472+
#[attr_hidden]
458473
pub const TRACING_DURATIONS_TEST_ROOT: &'static str = "TRACING_DURATIONS_TEST_ROOT";
459474

460475
/// Use to create the tracing durations file via the `tracing-durations-export` feature.

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ impl TestContext {
478478

479479
if cfg!(unix) {
480480
// Avoid locale issues in tests
481-
command.env("LC_ALL", "C");
481+
command.env(EnvVars::LC_ALL, "C");
482482
}
483483

484484
if cfg!(all(windows, debug_assertions)) {
@@ -663,10 +663,9 @@ impl TestContext {
663663
.env(EnvVars::UV_PYTHON_BIN_DIR, bin.as_os_str())
664664
.env(
665665
EnvVars::PATH,
666-
std::env::join_paths(
667-
std::iter::once(bin)
668-
.chain(std::env::split_paths(&env::var("PATH").unwrap_or_default())),
669-
)
666+
std::env::join_paths(std::iter::once(bin).chain(std::env::split_paths(
667+
&env::var(EnvVars::PATH).unwrap_or_default(),
668+
)))
670669
.unwrap(),
671670
)
672671
.current_dir(&self.temp_dir);

crates/uv/tests/it/edit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6819,7 +6819,7 @@ fn add_index_credentials() -> Result<()> {
68196819
"#})?;
68206820

68216821
// Provide credentials for the index via the environment variable.
6822-
uv_snapshot!(context.filters(), context.add().arg("iniconfig==2.0.0").env("UV_DEFAULT_INDEX", "https://public:[email protected]/basic-auth/simple"), @r###"
6822+
uv_snapshot!(context.filters(), context.add().arg("iniconfig==2.0.0").env(EnvVars::UV_DEFAULT_INDEX, "https://public:[email protected]/basic-auth/simple"), @r###"
68236823
success: true
68246824
exit_code: 0
68256825
----- stdout -----
@@ -6913,7 +6913,7 @@ fn add_index_comments() -> Result<()> {
69136913
"#})?;
69146914

69156915
// Preserve the comment on the index URL, despite replacing it.
6916-
uv_snapshot!(context.filters(), context.add().arg("iniconfig==2.0.0").env("UV_DEFAULT_INDEX", "https://pypi.org/simple"), @r###"
6916+
uv_snapshot!(context.filters(), context.add().arg("iniconfig==2.0.0").env(EnvVars::UV_DEFAULT_INDEX, "https://pypi.org/simple"), @r###"
69176917
success: true
69186918
exit_code: 0
69196919
----- stdout -----

crates/uv/tests/it/init.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2416,7 +2416,7 @@ fn init_application_package_flit() -> Result<()> {
24162416
);
24172417
});
24182418

2419-
uv_snapshot!(context.filters(), context.run().current_dir(&child).env_remove("VIRTUAL_ENV").arg("foo"), @r###"
2419+
uv_snapshot!(context.filters(), context.run().current_dir(&child).env_remove(EnvVars::VIRTUAL_ENV).arg("foo"), @r###"
24202420
success: true
24212421
exit_code: 0
24222422
----- stdout -----
@@ -2497,7 +2497,7 @@ fn init_library_flit() -> Result<()> {
24972497
);
24982498
});
24992499

2500-
uv_snapshot!(context.filters(), context.run().current_dir(&child).env_remove("VIRTUAL_ENV").arg("python").arg("-c").arg("import foo; print(foo.hello())"), @r###"
2500+
uv_snapshot!(context.filters(), context.run().current_dir(&child).env_remove(EnvVars::VIRTUAL_ENV).arg("python").arg("-c").arg("import foo; print(foo.hello())"), @r###"
25012501
success: true
25022502
exit_code: 0
25032503
----- stdout -----

crates/uv/tests/it/lock.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13435,7 +13435,7 @@ fn lock_named_index_cli() -> Result<()> {
1343513435
)?;
1343613436

1343713437
// The package references a non-existent index.
13438-
uv_snapshot!(context.filters(), context.lock().env_remove("UV_EXCLUDE_NEWER"), @r###"
13438+
uv_snapshot!(context.filters(), context.lock().env_remove(EnvVars::UV_EXCLUDE_NEWER), @r###"
1343913439
success: false
1344013440
exit_code: 2
1344113441
----- stdout -----
@@ -13447,7 +13447,7 @@ fn lock_named_index_cli() -> Result<()> {
1344713447
"###);
1344813448

1344913449
// But it's fine if it comes from the CLI.
13450-
uv_snapshot!(context.filters(), context.lock().arg("--index").arg("pytorch=https://download.pytorch.org/whl/cu121").env_remove("UV_EXCLUDE_NEWER"), @r###"
13450+
uv_snapshot!(context.filters(), context.lock().arg("--index").arg("pytorch=https://download.pytorch.org/whl/cu121").env_remove(EnvVars::UV_EXCLUDE_NEWER), @r###"
1345113451
success: true
1345213452
exit_code: 0
1345313453
----- stdout -----

crates/uv/tests/it/pip_compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5508,7 +5508,7 @@ fn emit_index_urls() -> Result<()> {
55085508
.arg("https://test.pypi.org/simple/")
55095509
.arg("--extra-index-url")
55105510
.arg("https://pypi.org/simple")
5511-
.env("UV_EXTRA_INDEX_URL", "https://pypi.org/simple"), @r###"
5511+
.env(EnvVars::UV_EXTRA_INDEX_URL, "https://pypi.org/simple"), @r###"
55125512
success: true
55135513
exit_code: 0
55145514
----- stdout -----

0 commit comments

Comments
 (0)