Skip to content

Commit

Permalink
Add support for UV_OFFLINE (#9795)
Browse files Browse the repository at this point in the history
Closes #9794
  • Loading branch information
zanieb authored Dec 11, 2024
1 parent cb3feff commit f64da9b
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 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 @@ -200,7 +200,7 @@ pub struct GlobalArgs {
/// Disable network access.
///
/// When disabled, uv will only use locally cached data and locally available files.
#[arg(global = true, long, overrides_with("no_offline"))]
#[arg(global = true, long, overrides_with("no_offline"), env = EnvVars::UV_OFFLINE, value_parser = clap::builder::BoolishValueParser::new())]
pub offline: bool,

#[arg(global = true, long, overrides_with("offline"), hide = true)]
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 @@ -5,6 +5,9 @@ pub struct EnvVars;

#[attribute_env_vars_metadata]
impl EnvVars {
/// Equivalent to the `--offline` command-line argument. If set, uv will disable network access.
pub const UV_OFFLINE: &'static str = "UV_OFFLINE";

/// Equivalent to the `--default-index` command-line argument. If set, uv will use
/// this URL as the default index when searching for packages.
pub const UV_DEFAULT_INDEX: &'static str = "UV_DEFAULT_INDEX";
Expand Down
18 changes: 11 additions & 7 deletions crates/uv/tests/it/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn help() {
Whether to load TLS certificates from the platform's native certificate store [env:
UV_NATIVE_TLS=]
--offline
Disable network access
Disable network access [env: UV_OFFLINE=]
--allow-insecure-host <ALLOW_INSECURE_HOST>
Allow insecure connections to a host [env: UV_INSECURE_HOST=]
--no-progress
Expand Down Expand Up @@ -137,7 +137,7 @@ fn help_flag() {
Whether to load TLS certificates from the platform's native certificate store [env:
UV_NATIVE_TLS=]
--offline
Disable network access
Disable network access [env: UV_OFFLINE=]
--allow-insecure-host <ALLOW_INSECURE_HOST>
Allow insecure connections to a host [env: UV_INSECURE_HOST=]
--no-progress
Expand Down Expand Up @@ -216,7 +216,7 @@ fn help_short_flag() {
Whether to load TLS certificates from the platform's native certificate store [env:
UV_NATIVE_TLS=]
--offline
Disable network access
Disable network access [env: UV_OFFLINE=]
--allow-insecure-host <ALLOW_INSECURE_HOST>
Allow insecure connections to a host [env: UV_INSECURE_HOST=]
--no-progress
Expand Down Expand Up @@ -374,6 +374,8 @@ fn help_subcommand() {
Disable network access.
When disabled, uv will only use locally cached data and locally available files.
[env: UV_OFFLINE=]
--allow-insecure-host <ALLOW_INSECURE_HOST>
Allow insecure connections to a host.
Expand Down Expand Up @@ -617,6 +619,8 @@ fn help_subsubcommand() {
Disable network access.
When disabled, uv will only use locally cached data and locally available files.
[env: UV_OFFLINE=]
--allow-insecure-host <ALLOW_INSECURE_HOST>
Allow insecure connections to a host.
Expand Down Expand Up @@ -730,7 +734,7 @@ fn help_flag_subcommand() {
Whether to load TLS certificates from the platform's native certificate store [env:
UV_NATIVE_TLS=]
--offline
Disable network access
Disable network access [env: UV_OFFLINE=]
--allow-insecure-host <ALLOW_INSECURE_HOST>
Allow insecure connections to a host [env: UV_INSECURE_HOST=]
--no-progress
Expand Down Expand Up @@ -803,7 +807,7 @@ fn help_flag_subsubcommand() {
Whether to load TLS certificates from the platform's native certificate store [env:
UV_NATIVE_TLS=]
--offline
Disable network access
Disable network access [env: UV_OFFLINE=]
--allow-insecure-host <ALLOW_INSECURE_HOST>
Allow insecure connections to a host [env: UV_INSECURE_HOST=]
--no-progress
Expand Down Expand Up @@ -960,7 +964,7 @@ fn help_with_global_option() {
Whether to load TLS certificates from the platform's native certificate store [env:
UV_NATIVE_TLS=]
--offline
Disable network access
Disable network access [env: UV_OFFLINE=]
--allow-insecure-host <ALLOW_INSECURE_HOST>
Allow insecure connections to a host [env: UV_INSECURE_HOST=]
--no-progress
Expand Down Expand Up @@ -1076,7 +1080,7 @@ fn help_with_no_pager() {
Whether to load TLS certificates from the platform's native certificate store [env:
UV_NATIVE_TLS=]
--offline
Disable network access
Disable network access [env: UV_OFFLINE=]
--allow-insecure-host <ALLOW_INSECURE_HOST>
Allow insecure connections to a host [env: UV_INSECURE_HOST=]
--no-progress
Expand Down
4 changes: 4 additions & 0 deletions docs/configuration/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ Equivalent to the `--no-verify-hashes` argument. Disables hash verification for

Use to disable line wrapping for diagnostics.

### `UV_OFFLINE`

Equivalent to the `--offline` command-line argument. If set, uv will disable network access.

### `UV_OVERRIDE`

Equivalent to the `--override` command-line argument. If set, uv will use this file
Expand Down
Loading

0 comments on commit f64da9b

Please sign in to comment.