From 28559292109c0e162b441d1f0e420786d086ec1b Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Tue, 10 Dec 2024 18:46:29 -0600 Subject: [PATCH] Add support for `UV_OFFLINE` --- crates/uv-cli/src/lib.rs | 2 +- crates/uv-static/src/env_vars.rs | 3 +++ crates/uv/tests/it/help.rs | 18 ++++++++------ docs/configuration/environment.md | 4 ++++ docs/reference/cli.md | 39 +++++++++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 8 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index 6378977fb913..c27343231ca9 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -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)] diff --git a/crates/uv-static/src/env_vars.rs b/crates/uv-static/src/env_vars.rs index ec58be134096..1960024ce244 100644 --- a/crates/uv-static/src/env_vars.rs +++ b/crates/uv-static/src/env_vars.rs @@ -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"; diff --git a/crates/uv/tests/it/help.rs b/crates/uv/tests/it/help.rs index de2ed24b0356..55d23572702c 100644 --- a/crates/uv/tests/it/help.rs +++ b/crates/uv/tests/it/help.rs @@ -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 connections to a host [env: UV_INSECURE_HOST=] --no-progress @@ -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 connections to a host [env: UV_INSECURE_HOST=] --no-progress @@ -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 connections to a host [env: UV_INSECURE_HOST=] --no-progress @@ -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 connections to a host. @@ -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 connections to a host. @@ -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 connections to a host [env: UV_INSECURE_HOST=] --no-progress @@ -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 connections to a host [env: UV_INSECURE_HOST=] --no-progress @@ -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 connections to a host [env: UV_INSECURE_HOST=] --no-progress @@ -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 connections to a host [env: UV_INSECURE_HOST=] --no-progress diff --git a/docs/configuration/environment.md b/docs/configuration/environment.md index 064a406ec3f5..245bdf08c66e 100644 --- a/docs/configuration/environment.md +++ b/docs/configuration/environment.md @@ -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 diff --git a/docs/reference/cli.md b/docs/reference/cli.md index bafb2cdc0558..afafe6416b74 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -346,6 +346,7 @@ uv run [OPTIONS] [COMMAND]

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

+

May also be set with the UV_OFFLINE environment variable.

--only-dev

Only include the development dependency group.

Omit other dependencies. The project itself will also be omitted.

@@ -628,6 +629,7 @@ uv init [OPTIONS] [PATH]

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

+

May also be set with the UV_OFFLINE environment variable.

--package

Set up the project to be built as a Python package.

Defines a [build-system] for the project.

@@ -942,6 +944,7 @@ uv add [OPTIONS] >

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

+

May also be set with the UV_OFFLINE environment variable.

--optional optional

Add the requirements to the package’s optional dependencies for the specified extra.

The group may then be activated when installing the project with the --extra flag.

@@ -1283,6 +1286,7 @@ uv remove [OPTIONS] ...

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

+

May also be set with the UV_OFFLINE environment variable.

--optional optional

Remove the packages from the project’s optional dependencies for the specified extra

--package package

Remove the dependencies from a specific package in the workspace

@@ -1655,6 +1659,7 @@ uv sync [OPTIONS]

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

+

May also be set with the UV_OFFLINE environment variable.

--only-dev

Only include the development dependency group.

Omit other dependencies. The project itself will also be omitted.

@@ -1974,6 +1979,7 @@ uv lock [OPTIONS]

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

+

May also be set with the UV_OFFLINE environment variable.

--prerelease prerelease

The strategy to use when considering pre-release versions.

By default, uv will accept pre-releases for packages that only publish pre-releases, along with first-party requirements that contain an explicit pre-release marker in the declared specifiers (if-necessary-or-explicit).

@@ -2329,6 +2335,7 @@ uv export [OPTIONS]

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

+

May also be set with the UV_OFFLINE environment variable.

--only-dev

Only include the development dependency group.

Omit other dependencies. The project itself will also be omitted.

@@ -2661,6 +2668,7 @@ uv tree [OPTIONS]

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

+

May also be set with the UV_OFFLINE environment variable.

--only-dev

Only include the development dependency group.

Omit other dependencies. The project itself will also be omitted.

@@ -3092,6 +3100,7 @@ uv tool run [OPTIONS] [COMMAND]

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

+

May also be set with the UV_OFFLINE environment variable.

--prerelease prerelease

The strategy to use when considering pre-release versions.

By default, uv will accept pre-releases for packages that only publish pre-releases, along with first-party requirements that contain an explicit pre-release marker in the declared specifiers (if-necessary-or-explicit).

@@ -3403,6 +3412,7 @@ uv tool install [OPTIONS]

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

+

May also be set with the UV_OFFLINE environment variable.

--overrides overrides

Override versions using the given requirements files.

Overrides files are requirements.txt-like files that force a specific version of a requirement to be installed, regardless of the requirements declared by any constituent package, and regardless of whether this would be considered an invalid resolution.

@@ -3710,6 +3720,7 @@ uv tool upgrade [OPTIONS] ...

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

+

May also be set with the UV_OFFLINE environment variable.

--prerelease prerelease

The strategy to use when considering pre-release versions.

By default, uv will accept pre-releases for packages that only publish pre-releases, along with first-party requirements that contain an explicit pre-release marker in the declared specifiers (if-necessary-or-explicit).

@@ -3864,6 +3875,7 @@ uv tool list [OPTIONS]

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

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).

@@ -3975,6 +3987,7 @@ uv tool uninstall [OPTIONS] ...

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

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).

@@ -4096,6 +4109,7 @@ uv tool update-shell [OPTIONS]

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

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).

@@ -4235,6 +4249,7 @@ uv tool dir [OPTIONS]

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

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).

@@ -4434,6 +4449,7 @@ uv python list [OPTIONS]

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

+

May also be set with the UV_OFFLINE environment variable.

--only-downloads

Only show Python downloads, exclude installed distributions.

By default, available downloads for the current platform are shown.

@@ -4609,6 +4625,7 @@ uv python install [OPTIONS] [TARGETS]...

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

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).

@@ -4751,6 +4768,7 @@ uv python find [OPTIONS] [REQUEST]

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

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).

@@ -4895,6 +4913,7 @@ uv python pin [OPTIONS] [REQUEST]

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

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).

@@ -5038,6 +5057,7 @@ uv python dir [OPTIONS]

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

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).

@@ -5166,6 +5186,7 @@ uv python uninstall [OPTIONS] ...

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

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).

@@ -5495,6 +5516,7 @@ uv pip compile [OPTIONS] ...

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

+

May also be set with the UV_OFFLINE environment variable.

--only-binary only-binary

Only use pre-built wheels; don’t build source distributions.

When enabled, resolving will not run code from the given packages. The cached wheels of already-built source distributions will be reused, but operations that require building distributions will exit with an error.

@@ -5918,6 +5940,7 @@ uv pip sync [OPTIONS] ...

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

+

May also be set with the UV_OFFLINE environment variable.

--only-binary only-binary

Only use pre-built wheels; don’t build source distributions.

When enabled, resolving will not run code from the given packages. The cached wheels of already-built source distributions will be reused, but operations that require building distributions will exit with an error.

@@ -6331,6 +6354,7 @@ uv pip install [OPTIONS] |--editable When disabled, uv will only use locally cached data and locally available files.

+

May also be set with the UV_OFFLINE environment variable.

--only-binary only-binary

Only use pre-built wheels; don’t build source distributions.

When enabled, resolving will not run code from the given packages. The cached wheels of already-built source distributions will be reused, but operations that require building distributions will exit with an error.

@@ -6654,6 +6678,7 @@ uv pip uninstall [OPTIONS] >

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

+

May also be set with the UV_OFFLINE environment variable.

--prefix prefix

Uninstall packages from the specified --prefix directory

--project project

Run the command within the given project directory.

@@ -6791,6 +6816,7 @@ uv pip freeze [OPTIONS]

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

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).

@@ -7010,6 +7036,7 @@ uv pip list [OPTIONS]

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

+

May also be set with the UV_OFFLINE environment variable.

--outdated

List outdated packages.

The latest version of each package will be shown alongside the installed version. Up-to-date packages will be omitted from the output.

@@ -7153,6 +7180,7 @@ uv pip show [OPTIONS] [PACKAGE]...

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

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).

@@ -7291,6 +7319,7 @@ uv pip tree [OPTIONS]

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

+

May also be set with the UV_OFFLINE environment variable.

--outdated

Show the latest available version of each package in the tree

--package package

Display only the specified packages

@@ -7430,6 +7459,7 @@ uv pip check [OPTIONS]

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

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).

@@ -7675,6 +7705,7 @@ uv venv [OPTIONS] [PATH]

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

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).

@@ -7970,6 +8001,7 @@ uv build [OPTIONS] [SRC]

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

+

May also be set with the UV_OFFLINE environment variable.

--out-dir, -o out-dir

The output directory to which distributions should be written.

Defaults to the dist subdirectory within the source directory, or the directory containing the source distribution archive.

@@ -8201,6 +8233,7 @@ With these settings, the following two calls are equivalent:

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

+

May also be set with the UV_OFFLINE environment variable.

--password, -p password

The password for the upload

May also be set with the UV_PUBLISH_PASSWORD environment variable.

@@ -8373,6 +8406,7 @@ uv cache clean [OPTIONS] [PACKAGE]...

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

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).

@@ -8494,6 +8528,7 @@ uv cache prune [OPTIONS]

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

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).

@@ -8617,6 +8652,7 @@ uv cache dir [OPTIONS]

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

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).

@@ -8754,6 +8790,7 @@ uv self update [OPTIONS] [TARGET_VERSION]

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

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).

@@ -8872,6 +8909,7 @@ uv version [OPTIONS]

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

+

May also be set with the UV_OFFLINE environment variable.

--output-format output-format
--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).

@@ -9038,6 +9076,7 @@ uv help [OPTIONS] [COMMAND]...

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

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project’s virtual environment (.venv).