Skip to content

Commit

Permalink
docs: env var doc improvements (#8777)
Browse files Browse the repository at this point in the history
## 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">
  • Loading branch information
samypr100 authored Nov 3, 2024
1 parent f52814e commit 647494b
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 131 deletions.
4 changes: 3 additions & 1 deletion crates/uv-dev/src/generate_env_vars_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ fn generate() -> String {
})
.collect::<Vec<_>>()
.join("\n");
output.push_str(&format!("- `{var}`: {doc}\n"));
output.push_str(&format!(
"- <a id=\"{var}\"></a> [`{var}`](#{var}): {doc}\n"
));
}

output
Expand Down
21 changes: 18 additions & 3 deletions crates/uv-static/src/env_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ impl EnvVars {
/// packages.
pub const UV_CONCURRENT_INSTALLS: &'static str = "UV_CONCURRENT_INSTALLS";

/// Disables all progress output. For example, spinners and progress bars.
pub const UV_NO_PROGRESS: &'static str = "UV_NO_PROGRESS";

/// Specifies the directory where uv stores managed tools.
pub const UV_TOOL_DIR: &'static str = "UV_TOOL_DIR";

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

/// Disables all progress output. For example, spinners and progress bars.
pub const UV_NO_PROGRESS: &'static str = "UV_NO_PROGRESS";

/// Forces colored output regardless of terminal support.
///
/// See [force-color.org](https://force-color.org).
Expand All @@ -397,18 +397,23 @@ impl EnvVars {
pub const LOCALAPPDATA: &'static str = "LOCALAPPDATA";

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

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

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

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

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

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

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

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

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

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

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

/// Used in tests to enforce a consistent locale setting.
#[attr_hidden]
pub const LC_ALL: &'static str = "LC_ALL";

/// Typically set by CI runners, used to detect a CI runner.
#[attr_hidden]
pub const CI: &'static str = "CI";

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

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

/// Use to create the tracing durations file via the `tracing-durations-export` feature.
Expand Down
9 changes: 4 additions & 5 deletions crates/uv/tests/it/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ impl TestContext {

if cfg!(unix) {
// Avoid locale issues in tests
command.env("LC_ALL", "C");
command.env(EnvVars::LC_ALL, "C");
}

if cfg!(all(windows, debug_assertions)) {
Expand Down Expand Up @@ -663,10 +663,9 @@ impl TestContext {
.env(EnvVars::UV_PYTHON_BIN_DIR, bin.as_os_str())
.env(
EnvVars::PATH,
std::env::join_paths(
std::iter::once(bin)
.chain(std::env::split_paths(&env::var("PATH").unwrap_or_default())),
)
std::env::join_paths(std::iter::once(bin).chain(std::env::split_paths(
&env::var(EnvVars::PATH).unwrap_or_default(),
)))
.unwrap(),
)
.current_dir(&self.temp_dir);
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/tests/it/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6819,7 +6819,7 @@ fn add_index_credentials() -> Result<()> {
"#})?;

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

// Preserve the comment on the index URL, despite replacing it.
uv_snapshot!(context.filters(), context.add().arg("iniconfig==2.0.0").env("UV_DEFAULT_INDEX", "https://pypi.org/simple"), @r###"
uv_snapshot!(context.filters(), context.add().arg("iniconfig==2.0.0").env(EnvVars::UV_DEFAULT_INDEX, "https://pypi.org/simple"), @r###"
success: true
exit_code: 0
----- stdout -----
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/tests/it/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2416,7 +2416,7 @@ fn init_application_package_flit() -> Result<()> {
);
});

uv_snapshot!(context.filters(), context.run().current_dir(&child).env_remove("VIRTUAL_ENV").arg("foo"), @r###"
uv_snapshot!(context.filters(), context.run().current_dir(&child).env_remove(EnvVars::VIRTUAL_ENV).arg("foo"), @r###"
success: true
exit_code: 0
----- stdout -----
Expand Down Expand Up @@ -2497,7 +2497,7 @@ fn init_library_flit() -> Result<()> {
);
});

uv_snapshot!(context.filters(), context.run().current_dir(&child).env_remove("VIRTUAL_ENV").arg("python").arg("-c").arg("import foo; print(foo.hello())"), @r###"
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###"
success: true
exit_code: 0
----- stdout -----
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/tests/it/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13435,7 +13435,7 @@ fn lock_named_index_cli() -> Result<()> {
)?;

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

// But it's fine if it comes from the CLI.
uv_snapshot!(context.filters(), context.lock().arg("--index").arg("pytorch=https://download.pytorch.org/whl/cu121").env_remove("UV_EXCLUDE_NEWER"), @r###"
uv_snapshot!(context.filters(), context.lock().arg("--index").arg("pytorch=https://download.pytorch.org/whl/cu121").env_remove(EnvVars::UV_EXCLUDE_NEWER), @r###"
success: true
exit_code: 0
----- stdout -----
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/tests/it/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5508,7 +5508,7 @@ fn emit_index_urls() -> Result<()> {
.arg("https://test.pypi.org/simple/")
.arg("--extra-index-url")
.arg("https://pypi.org/simple")
.env("UV_EXTRA_INDEX_URL", "https://pypi.org/simple"), @r###"
.env(EnvVars::UV_EXTRA_INDEX_URL, "https://pypi.org/simple"), @r###"
success: true
exit_code: 0
----- stdout -----
Expand Down
Loading

0 comments on commit 647494b

Please sign in to comment.