Skip to content

Commit

Permalink
feat: add environment variable to disable progress output (#8600)
Browse files Browse the repository at this point in the history
The changes in this commit introduce the `UV_NO_PROGRESS` environment
variable as an alternative way to control progress output suppression in
uv-cli, equivalent to using the `--no-progress` flag. This enhancement
simplifies configuration in CI environments and automated scripts by
eliminating the need to detect whether the script is running in a CI
environment.

Previously, disabling progress output required either passing the
`--no-progress` flag directly or implementing script logic to detect CI
environments and conditionally add the flag. With this change, users can
now simply set `UV_NO_PROGRESS=true` in their environment to achieve the
same effect.

The changes include:

- Adding the `UV_NO_PROGRESS` environment variable to the `EnvVars`
struct in `crates/uv-static/src/env_vars.rs`.
- Updating the `GlobalArgs` struct in `crates/uv-cli/src/lib.rs` to
include a new `no_progress` field that is bound to the `UV_NO_PROGRESS`
environment variable.
- Adding documentation for the new `UV_NO_PROGRESS` environment variable
in `docs/configuration/environment.md`.
## Test Plan

After creating a uv project using `uv init` in a temp directory in this
project:
```
cargo run cache clean && cargo run venv && UV_NO_PROGRESS=false cargo run sync 
cargo run cache clean && cargo run venv && cargo run sync  
```
produce the expected default behavior 

```
cargo run cache clean && cargo run venv && UV_NO_PROGRESS=false cargo run sync  
```
produces the same behavior as having the `--no-progress` flag.
  • Loading branch information
zzztimbo authored Oct 27, 2024
1 parent 1e1b6ce commit 4caa158
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 12 deletions.
2 changes: 1 addition & 1 deletion crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ pub struct GlobalArgs {
/// Hide all progress outputs.
///
/// For example, spinners or progress bars.
#[arg(global = true, long)]
#[arg(global = true, long, env = EnvVars::UV_NO_PROGRESS, value_parser = clap::builder::BoolishValueParser::new())]
pub no_progress: bool,

/// Change to the given directory prior to running the command.
Expand Down
3 changes: 3 additions & 0 deletions crates/uv-static/src/env_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ impl EnvVars {
/// Disables colored output (takes precedence over `FORCE_COLOR`).
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.
pub const FORCE_COLOR: &'static str = "FORCE_COLOR";

Expand Down
26 changes: 15 additions & 11 deletions crates/uv/tests/it/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn help() {
--native-tls Whether to load TLS certificates from the platform's native
certificate store [env: UV_NATIVE_TLS=]
--offline Disable network access
--no-progress Hide all progress outputs
--no-progress Hide all progress outputs [env: UV_NO_PROGRESS=]
--directory <DIRECTORY> Change to the given directory prior to running the command
--project <PROJECT> Run the command within the given project directory
--config-file <CONFIG_FILE> The path to a `uv.toml` file to use for configuration [env:
Expand Down Expand Up @@ -123,7 +123,7 @@ fn help_flag() {
--native-tls Whether to load TLS certificates from the platform's native
certificate store [env: UV_NATIVE_TLS=]
--offline Disable network access
--no-progress Hide all progress outputs
--no-progress Hide all progress outputs [env: UV_NO_PROGRESS=]
--directory <DIRECTORY> Change to the given directory prior to running the command
--project <PROJECT> Run the command within the given project directory
--config-file <CONFIG_FILE> The path to a `uv.toml` file to use for configuration [env:
Expand Down Expand Up @@ -191,7 +191,7 @@ fn help_short_flag() {
--native-tls Whether to load TLS certificates from the platform's native
certificate store [env: UV_NATIVE_TLS=]
--offline Disable network access
--no-progress Hide all progress outputs
--no-progress Hide all progress outputs [env: UV_NO_PROGRESS=]
--directory <DIRECTORY> Change to the given directory prior to running the command
--project <PROJECT> Run the command within the given project directory
--config-file <CONFIG_FILE> The path to a `uv.toml` file to use for configuration [env:
Expand All @@ -211,7 +211,7 @@ fn help_short_flag() {
fn help_subcommand() {
let context = TestContext::new_with_versions(&[]);

uv_snapshot!(context.filters(), context.help().arg("python"), @r##"
uv_snapshot!(context.filters(), context.help().arg("python"), @r###"
success: true
exit_code: 0
----- stdout -----
Expand Down Expand Up @@ -344,6 +344,8 @@ fn help_subcommand() {
Hide all progress outputs.
For example, spinners or progress bars.
[env: UV_NO_PROGRESS=]
--directory <DIRECTORY>
Change to the given directory prior to running the command.
Expand Down Expand Up @@ -392,14 +394,14 @@ fn help_subcommand() {
----- stderr -----
"##);
"###);
}

#[test]
fn help_subsubcommand() {
let context = TestContext::new_with_versions(&[]);

uv_snapshot!(context.filters(), context.help().arg("python").arg("install"), @r##"
uv_snapshot!(context.filters(), context.help().arg("python").arg("install"), @r###"
success: true
exit_code: 0
----- stdout -----
Expand Down Expand Up @@ -514,6 +516,8 @@ fn help_subsubcommand() {
Hide all progress outputs.
For example, spinners or progress bars.
[env: UV_NO_PROGRESS=]
--directory <DIRECTORY>
Change to the given directory prior to running the command.
Expand Down Expand Up @@ -560,7 +564,7 @@ fn help_subsubcommand() {
----- stderr -----
"##);
"###);
}

#[test]
Expand Down Expand Up @@ -603,7 +607,7 @@ fn help_flag_subcommand() {
--native-tls Whether to load TLS certificates from the platform's native
certificate store [env: UV_NATIVE_TLS=]
--offline Disable network access
--no-progress Hide all progress outputs
--no-progress Hide all progress outputs [env: UV_NO_PROGRESS=]
--directory <DIRECTORY> Change to the given directory prior to running the command
--project <PROJECT> Run the command within the given project directory
--config-file <CONFIG_FILE> The path to a `uv.toml` file to use for configuration [env:
Expand Down Expand Up @@ -657,7 +661,7 @@ fn help_flag_subsubcommand() {
--native-tls Whether to load TLS certificates from the platform's native
certificate store [env: UV_NATIVE_TLS=]
--offline Disable network access
--no-progress Hide all progress outputs
--no-progress Hide all progress outputs [env: UV_NO_PROGRESS=]
--directory <DIRECTORY> Change to the given directory prior to running the command
--project <PROJECT> Run the command within the given project directory
--config-file <CONFIG_FILE> The path to a `uv.toml` file to use for configuration [env:
Expand Down Expand Up @@ -803,7 +807,7 @@ fn help_with_global_option() {
--native-tls Whether to load TLS certificates from the platform's native
certificate store [env: UV_NATIVE_TLS=]
--offline Disable network access
--no-progress Hide all progress outputs
--no-progress Hide all progress outputs [env: UV_NO_PROGRESS=]
--directory <DIRECTORY> Change to the given directory prior to running the command
--project <PROJECT> Run the command within the given project directory
--config-file <CONFIG_FILE> The path to a `uv.toml` file to use for configuration [env:
Expand Down Expand Up @@ -908,7 +912,7 @@ fn help_with_no_pager() {
--native-tls Whether to load TLS certificates from the platform's native
certificate store [env: UV_NATIVE_TLS=]
--offline Disable network access
--no-progress Hide all progress outputs
--no-progress Hide all progress outputs [env: UV_NO_PROGRESS=]
--directory <DIRECTORY> Change to the given directory prior to running the command
--project <PROJECT> Run the command within the given project directory
--config-file <CONFIG_FILE> The path to a `uv.toml` file to use for configuration [env:
Expand Down
1 change: 1 addition & 0 deletions docs/configuration/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@ In addition, uv respects the following environment variables:
least-recent non-EOL macOS version at time of writing.
- `NO_COLOR`: Disable colors. Takes precedence over `FORCE_COLOR`. See
[no-color.org](https://no-color.org).
- `UV_NO_PROGRESS`: Disable progress indicators like spinners and progress bars.
- `FORCE_COLOR`: Enforce colors regardless of TTY support. See
[force-color.org](https://force-color.org).
Loading

0 comments on commit 4caa158

Please sign in to comment.