Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update format of environment variable reference #9018

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions crates/uv-dev/src/generate_env_vars_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use anyhow::bail;
use pretty_assertions::StrComparison;
use std::collections::BTreeSet;
use std::path::PathBuf;

use uv_static::EnvVars;
Expand Down Expand Up @@ -71,30 +72,32 @@ fn generate() -> String {
let mut output = String::new();

output.push_str("# Environment variables\n\n");
output.push_str("uv respects the following environment variables:\n\n");

for (var, doc) in EnvVars::metadata() {
// Remove empty lines and ddd two spaces to the beginning from the second line.
let doc = doc
.lines()
.enumerate()
.filter(|(_, line)| !line.trim().is_empty())
.map(|(i, line)| {
if i == 0 {
line.to_string()
} else {
format!(" {line}")
}
})
.collect::<Vec<_>>()
.join("\n");
output.push_str(&format!(
"- <a id=\"{var}\"></a> [`{var}`](#{var}): {doc}\n"
));

// Partition and sort environment variables into UV_ and external variables.
let (uv_vars, external_vars): (BTreeSet<_>, BTreeSet<_>) = EnvVars::metadata()
.iter()
.partition(|(var, _)| var.starts_with("UV_"));

output.push_str("uv defines and respects the following environment variables:\n\n");

for (var, doc) in uv_vars {
output.push_str(&render(var, doc));
}

output.push_str("\n\n## Externally defined variables\n\n");
output.push_str("uv also reads the following externally defined environment variables:\n\n");

for (var, doc) in external_vars {
output.push_str(&render(var, doc));
}

output
}

/// Render an environment variable and its documentation.
fn render(var: &str, doc: &str) -> String {
format!("### `{var}`\n\n{doc}\n\n")
}

#[cfg(test)]
mod tests;
Loading
Loading