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">
This commit is contained in:
samypr100 2024-11-03 18:56:17 +00:00 committed by GitHub
parent f52814e729
commit 647494b998
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 130 additions and 131 deletions

View file

@ -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

View file

@ -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";
@ -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).
@ -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.
@ -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`.
@ -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.
@ -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.

View file

@ -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)) {
@ -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);

View file

@ -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:heron@pypi-proxy.fly.dev/basic-auth/simple"), @r###"
uv_snapshot!(context.filters(), context.add().arg("iniconfig==2.0.0").env(EnvVars::UV_DEFAULT_INDEX, "https://public:heron@pypi-proxy.fly.dev/basic-auth/simple"), @r###"
success: true
exit_code: 0
----- stdout -----
@ -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 -----

View file

@ -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 -----
@ -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 -----

View file

@ -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 -----
@ -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 -----

View file

@ -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 -----