From a8b41aec4d47dca9432d2d4f868f10579cf2a98f Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Fri, 18 Oct 2024 13:24:35 -0400 Subject: [PATCH] Add support for UV_FROZEN and UV_LOCKED --- crates/uv-cli/src/lib.rs | 28 ++++++++++++++-------------- crates/uv-static/src/env_vars.rs | 6 ++++++ docs/reference/cli.md | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index 0177af3e75978..cf124a5bb281c 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -2683,7 +2683,7 @@ pub struct RunArgs { /// /// Requires that the lockfile is up-to-date. If the lockfile is missing or /// needs to be updated, uv will exit with an error. - #[arg(long, conflicts_with = "frozen")] + #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")] pub locked: bool, /// Run without updating the `uv.lock` file. @@ -2693,7 +2693,7 @@ pub struct RunArgs { /// exit with an error. If the `pyproject.toml` includes changes to /// dependencies that have not been included in the lockfile yet, they will /// not be present in the environment. - #[arg(long, conflicts_with = "locked")] + #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "locked")] pub frozen: bool, /// Run the given path as a Python script. @@ -2836,7 +2836,7 @@ pub struct SyncArgs { /// /// Requires that the lockfile is up-to-date. If the lockfile is missing or /// needs to be updated, uv will exit with an error. - #[arg(long, conflicts_with = "frozen")] + #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")] pub locked: bool, /// Sync without updating the `uv.lock` file. @@ -2846,7 +2846,7 @@ pub struct SyncArgs { /// exit with an error. If the `pyproject.toml` includes changes to dependencies /// that have not been included in the lockfile yet, they will not be /// present in the environment. - #[arg(long, conflicts_with = "locked")] + #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "locked")] pub frozen: bool, #[command(flatten)] @@ -2896,11 +2896,11 @@ pub struct LockArgs { /// /// Requires that the lockfile is up-to-date. If the lockfile is missing or /// needs to be updated, uv will exit with an error. - #[arg(long, conflicts_with = "frozen")] + #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")] pub locked: bool, /// Assert that a `uv.lock` exists, without updating it. - #[arg(long, conflicts_with = "locked")] + #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "locked")] pub frozen: bool, #[command(flatten)] @@ -3009,13 +3009,13 @@ pub struct AddArgs { /// /// Requires that the lockfile is up-to-date. If the lockfile is missing or /// needs to be updated, uv will exit with an error. - #[arg(long, conflicts_with = "frozen")] + #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")] pub locked: bool, /// Add dependencies without re-locking the project. /// /// The project environment will not be synced. - #[arg(long, conflicts_with = "locked")] + #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "locked")] pub frozen: bool, #[command(flatten)] @@ -3079,13 +3079,13 @@ pub struct RemoveArgs { /// /// Requires that the lockfile is up-to-date. If the lockfile is missing or /// needs to be updated, uv will exit with an error. - #[arg(long, conflicts_with = "frozen")] + #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")] pub locked: bool, /// Remove dependencies without re-locking the project. /// /// The project environment will not be synced. - #[arg(long, conflicts_with = "locked")] + #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "locked")] pub frozen: bool, #[command(flatten)] @@ -3154,13 +3154,13 @@ pub struct TreeArgs { /// /// Requires that the lockfile is up-to-date. If the lockfile is missing or /// needs to be updated, uv will exit with an error. - #[arg(long, conflicts_with = "frozen")] + #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")] pub locked: bool, /// Display the requirements without locking the project. /// /// If the lockfile is missing, uv will exit with an error. - #[arg(long, conflicts_with = "locked")] + #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "locked")] pub frozen: bool, #[command(flatten)] @@ -3302,13 +3302,13 @@ pub struct ExportArgs { /// /// Requires that the lockfile is up-to-date. If the lockfile is missing or /// needs to be updated, uv will exit with an error. - #[arg(long, conflicts_with = "frozen")] + #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")] pub locked: bool, /// Do not update the `uv.lock` before exporting. /// /// If a `uv.lock` does not exist, uv will exit with an error. - #[arg(long, conflicts_with = "locked")] + #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "locked")] pub frozen: bool, #[command(flatten)] diff --git a/crates/uv-static/src/env_vars.rs b/crates/uv-static/src/env_vars.rs index 788607c2727bf..7137d895d1d5d 100644 --- a/crates/uv-static/src/env_vars.rs +++ b/crates/uv-static/src/env_vars.rs @@ -105,6 +105,12 @@ impl EnvVars { /// Equivalent to the `--no-sync` argument. Skips syncing the environment. pub const UV_NO_SYNC: &'static str = "UV_NO_SYNC"; + /// Equivalent to the `--locked` argument. Assert that the `uv.lock` will remain unchanged. + pub const UV_LOCKED: &'static str = "UV_LOCKED"; + + /// Equivalent to the `--frozen` argument. Run without updating the `uv.lock` file. + pub const UV_FROZEN: &'static str = "UV_FROZEN"; + /// Equivalent to the `--preview` argument. Enables preview mode. pub const UV_PREVIEW: &'static str = "UV_PREVIEW"; diff --git a/docs/reference/cli.md b/docs/reference/cli.md index b4f4bc5f4870a..ee3e509371287 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -160,6 +160,7 @@ uv run [OPTIONS] [COMMAND]

Instead of checking if the lockfile is up-to-date, uses the versions in the lockfile as the source of truth. If the lockfile is missing, uv will exit with an error. If the pyproject.toml includes changes to dependencies that have not been included in the lockfile yet, they will not be present in the environment.

+

May also be set with the UV_FROZEN environment variable.

--help, -h

Display the concise help for this command

--index index

The URLs to use when resolving dependencies, in addition to the default index.

@@ -232,6 +233,7 @@ uv run [OPTIONS] [COMMAND]

Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated, uv will exit with an error.

+

May also be set with the UV_LOCKED environment variable.

--module, -m

Run a Python module.

Equivalent to python -m <module>.

@@ -749,6 +751,7 @@ uv add [OPTIONS] >

The project environment will not be synced.

+

May also be set with the UV_FROZEN environment variable.

--help, -h

Display the concise help for this command

--index index

The URLs to use when resolving dependencies, in addition to the default index.

@@ -813,6 +816,7 @@ uv add [OPTIONS] >

Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated, uv will exit with an error.

+

May also be set with the UV_LOCKED environment variable.

--native-tls

Whether to load TLS certificates from the platform’s native certificate store.

By default, uv loads certificates from the bundled webpki-roots crate. The webpki-roots are a reliable set of trust roots from Mozilla, and including them in uv improves portability and performance (especially on macOS).

@@ -1081,6 +1085,7 @@ uv remove [OPTIONS] ...

The project environment will not be synced.

+

May also be set with the UV_FROZEN environment variable.

--help, -h

Display the concise help for this command

--index index

The URLs to use when resolving dependencies, in addition to the default index.

@@ -1145,6 +1150,7 @@ uv remove [OPTIONS] ...

Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated, uv will exit with an error.

+

May also be set with the UV_LOCKED environment variable.

--native-tls

Whether to load TLS certificates from the platform’s native certificate store.

By default, uv loads certificates from the bundled webpki-roots crate. The webpki-roots are a reliable set of trust roots from Mozilla, and including them in uv improves portability and performance (especially on macOS).

@@ -1401,6 +1407,7 @@ uv sync [OPTIONS]

Instead of checking if the lockfile is up-to-date, uses the versions in the lockfile as the source of truth. If the lockfile is missing, uv will exit with an error. If the pyproject.toml includes changes to dependencies that have not been included in the lockfile yet, they will not be present in the environment.

+

May also be set with the UV_FROZEN environment variable.

--help, -h

Display the concise help for this command

--index index

The URLs to use when resolving dependencies, in addition to the default index.

@@ -1469,6 +1476,7 @@ uv sync [OPTIONS]

Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated, uv will exit with an error.

+

May also be set with the UV_LOCKED environment variable.

--native-tls

Whether to load TLS certificates from the platform’s native certificate store.

By default, uv loads certificates from the bundled webpki-roots crate. The webpki-roots are a reliable set of trust roots from Mozilla, and including them in uv improves portability and performance (especially on macOS).

@@ -1717,6 +1725,7 @@ uv lock [OPTIONS]

May also be set with the UV_FIND_LINKS environment variable.

--frozen

Assert that a uv.lock exists, without updating it

+

May also be set with the UV_FROZEN environment variable.

--help, -h

Display the concise help for this command

--index index

The URLs to use when resolving dependencies, in addition to the default index.

@@ -1783,6 +1792,7 @@ uv lock [OPTIONS]

Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated, uv will exit with an error.

+

May also be set with the UV_LOCKED environment variable.

--native-tls

Whether to load TLS certificates from the platform’s native certificate store.

By default, uv loads certificates from the bundled webpki-roots crate. The webpki-roots are a reliable set of trust roots from Mozilla, and including them in uv improves portability and performance (especially on macOS).

@@ -2023,6 +2033,7 @@ uv export [OPTIONS]

If a uv.lock does not exist, uv will exit with an error.

+

May also be set with the UV_FROZEN environment variable.

--help, -h

Display the concise help for this command

--index index

The URLs to use when resolving dependencies, in addition to the default index.

@@ -2089,6 +2100,7 @@ uv export [OPTIONS]

Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated, uv will exit with an error.

+

May also be set with the UV_LOCKED environment variable.

--native-tls

Whether to load TLS certificates from the platform’s native certificate store.

By default, uv loads certificates from the bundled webpki-roots crate. The webpki-roots are a reliable set of trust roots from Mozilla, and including them in uv improves portability and performance (especially on macOS).

@@ -2338,6 +2350,7 @@ uv tree [OPTIONS]

If the lockfile is missing, uv will exit with an error.

+

May also be set with the UV_FROZEN environment variable.

--help, -h

Display the concise help for this command

--index index

The URLs to use when resolving dependencies, in addition to the default index.

@@ -2406,6 +2419,7 @@ uv tree [OPTIONS]

Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated, uv will exit with an error.

+

May also be set with the UV_LOCKED environment variable.

--native-tls

Whether to load TLS certificates from the platform’s native certificate store.

By default, uv loads certificates from the bundled webpki-roots crate. The webpki-roots are a reliable set of trust roots from Mozilla, and including them in uv improves portability and performance (especially on macOS).