From 4caa1586fd6f66ca4fbcc09abacfc4e5ce36b279 Mon Sep 17 00:00:00 2001 From: Tim Chan Date: Sun, 27 Oct 2024 12:14:12 -0700 Subject: [PATCH] feat: add environment variable to disable progress output (#8600) 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. --- crates/uv-cli/src/lib.rs | 2 +- crates/uv-static/src/env_vars.rs | 3 +++ crates/uv/tests/it/help.rs | 26 ++++++++++++--------- docs/configuration/environment.md | 1 + docs/reference/cli.md | 39 +++++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 12 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index 84f270f14922..c3498965f2b9 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -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. diff --git a/crates/uv-static/src/env_vars.rs b/crates/uv-static/src/env_vars.rs index fa5eb8de45e6..8e59f6de1eb7 100644 --- a/crates/uv-static/src/env_vars.rs +++ b/crates/uv-static/src/env_vars.rs @@ -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"; diff --git a/crates/uv/tests/it/help.rs b/crates/uv/tests/it/help.rs index ee9bf082660c..e996ddeaf159 100644 --- a/crates/uv/tests/it/help.rs +++ b/crates/uv/tests/it/help.rs @@ -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 Change to the given directory prior to running the command --project Run the command within the given project directory --config-file The path to a `uv.toml` file to use for configuration [env: @@ -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 Change to the given directory prior to running the command --project Run the command within the given project directory --config-file The path to a `uv.toml` file to use for configuration [env: @@ -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 Change to the given directory prior to running the command --project Run the command within the given project directory --config-file The path to a `uv.toml` file to use for configuration [env: @@ -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 ----- @@ -344,6 +344,8 @@ fn help_subcommand() { Hide all progress outputs. For example, spinners or progress bars. + + [env: UV_NO_PROGRESS=] --directory Change to the given directory prior to running the command. @@ -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 ----- @@ -514,6 +516,8 @@ fn help_subsubcommand() { Hide all progress outputs. For example, spinners or progress bars. + + [env: UV_NO_PROGRESS=] --directory Change to the given directory prior to running the command. @@ -560,7 +564,7 @@ fn help_subsubcommand() { ----- stderr ----- - "##); + "###); } #[test] @@ -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 Change to the given directory prior to running the command --project Run the command within the given project directory --config-file The path to a `uv.toml` file to use for configuration [env: @@ -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 Change to the given directory prior to running the command --project Run the command within the given project directory --config-file The path to a `uv.toml` file to use for configuration [env: @@ -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 Change to the given directory prior to running the command --project Run the command within the given project directory --config-file The path to a `uv.toml` file to use for configuration [env: @@ -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 Change to the given directory prior to running the command --project Run the command within the given project directory --config-file The path to a `uv.toml` file to use for configuration [env: diff --git a/docs/configuration/environment.md b/docs/configuration/environment.md index dff73ce5e13c..f6c9178c1e1e 100644 --- a/docs/configuration/environment.md +++ b/docs/configuration/environment.md @@ -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). diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 811b1c161af7..763a16f37611 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -298,6 +298,7 @@ uv run [OPTIONS] [COMMAND]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-project

Avoid discovering the project or workspace.

Instead of searching for projects in the current directory and parent directories, run in an isolated, ephemeral environment populated by the --with requirements.

@@ -575,6 +576,7 @@ uv init [OPTIONS] [PATH]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--no-readme

Do not create a README.md file

@@ -887,6 +889,7 @@ uv add [OPTIONS] >

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--no-sources

Ignore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any local or Git sources

@@ -1225,6 +1228,7 @@ uv remove [OPTIONS] ...

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--no-sources

Ignore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any local or Git sources

@@ -1577,6 +1581,7 @@ uv sync [OPTIONS]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--no-sources

Ignore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any local or Git sources

@@ -1889,6 +1894,7 @@ uv lock [OPTIONS]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--no-sources

Ignore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any local or Git sources

@@ -2227,6 +2233,7 @@ uv export [OPTIONS]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--no-sources

Ignore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any local or Git sources

@@ -2548,6 +2555,7 @@ uv tree [OPTIONS]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--no-sources

Ignore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any local or Git sources

@@ -2938,6 +2946,7 @@ uv tool run [OPTIONS] [COMMAND]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--no-sources

Ignore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any local or Git sources

@@ -3239,6 +3248,7 @@ uv tool install [OPTIONS]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--no-sources

Ignore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any local or Git sources

@@ -3536,6 +3546,7 @@ uv tool upgrade [OPTIONS] ...

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--no-sources

Ignore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any local or Git sources

@@ -3686,6 +3697,7 @@ uv tool list [OPTIONS]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--offline

Disable network access.

When disabled, uv will only use locally cached data and locally available files.

@@ -3783,6 +3795,7 @@ uv tool uninstall [OPTIONS] ...

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.

@@ -3892,6 +3905,7 @@ uv tool update-shell [OPTIONS]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.

@@ -4019,6 +4033,7 @@ uv tool dir [OPTIONS]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.

@@ -4202,6 +4217,7 @@ uv python list [OPTIONS]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.

@@ -4329,6 +4345,7 @@ uv python install [OPTIONS] [TARGETS]...

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.

@@ -4448,6 +4465,7 @@ uv python find [OPTIONS] [REQUEST]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-project

Avoid discovering a project or workspace.

Otherwise, when no request is provided, the Python requirement of a project in the current directory or parent directories will be used.

@@ -4576,6 +4594,7 @@ uv python pin [OPTIONS] [REQUEST]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-project

Avoid validating the Python pin is compatible with the project or workspace.

By default, a project or workspace is discovered in the current directory or any parent directory. If a workspace is found, the Python pin is validated against the workspace’s requires-python constraint.

@@ -4693,6 +4712,7 @@ uv python dir [OPTIONS]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.

@@ -4806,6 +4826,7 @@ uv python uninstall [OPTIONS] ...

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.

@@ -5122,6 +5143,7 @@ uv pip compile [OPTIONS] ...

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--no-sources

Ignore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any local or Git sources

@@ -5509,6 +5531,7 @@ uv pip sync [OPTIONS] ...

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--no-sources

Ignore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any local or Git sources

@@ -5881,6 +5904,7 @@ uv pip install [OPTIONS] |--editable For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--no-sources

Ignore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any local or Git sources

@@ -6168,6 +6192,7 @@ uv pip uninstall [OPTIONS] >

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.

@@ -6293,6 +6318,7 @@ uv pip freeze [OPTIONS]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.

@@ -6430,6 +6456,7 @@ uv pip list [OPTIONS]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.

@@ -6557,6 +6584,7 @@ uv pip show [OPTIONS] [PACKAGE]...

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.

@@ -6683,6 +6711,7 @@ uv pip tree [OPTIONS]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--no-system
--offline

Disable network access.

@@ -6808,6 +6837,7 @@ uv pip check [OPTIONS]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.

@@ -7046,6 +7076,7 @@ uv venv [OPTIONS] [PATH]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-project

Avoid discovering a project or workspace.

By default, uv searches for projects in the current directory or any parent directory to determine the default path of the virtual environment and check for Python version constraints, if any.

@@ -7329,6 +7360,7 @@ uv build [OPTIONS] [SRC]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--no-sources

Ignore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any local or Git sources

@@ -7542,6 +7574,7 @@ uv publish [OPTIONS] [FILES]...

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.

@@ -7702,6 +7735,7 @@ uv cache clean [OPTIONS] [PACKAGE]...

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.

@@ -7811,6 +7845,7 @@ uv cache prune [OPTIONS]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.

@@ -7922,6 +7957,7 @@ uv cache dir [OPTIONS]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.

@@ -8047,6 +8083,7 @@ uv self update [OPTIONS] [TARGET_VERSION]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.

@@ -8153,6 +8190,7 @@ uv version [OPTIONS]

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.

@@ -8298,6 +8336,7 @@ uv help [OPTIONS] [COMMAND]...

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

--offline

Disable network access.