Skip to content

Commit d53d580

Browse files
Add support for UV_FROZEN and UV_LOCKED (#8340)
## Summary Closes #8321.
1 parent 69d5e08 commit d53d580

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
lines changed

crates/uv-cli/src/lib.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,7 @@ pub struct RunArgs {
26832683
///
26842684
/// Requires that the lockfile is up-to-date. If the lockfile is missing or
26852685
/// needs to be updated, uv will exit with an error.
2686-
#[arg(long, conflicts_with = "frozen")]
2686+
#[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")]
26872687
pub locked: bool,
26882688

26892689
/// Run without updating the `uv.lock` file.
@@ -2693,7 +2693,7 @@ pub struct RunArgs {
26932693
/// exit with an error. If the `pyproject.toml` includes changes to
26942694
/// dependencies that have not been included in the lockfile yet, they will
26952695
/// not be present in the environment.
2696-
#[arg(long, conflicts_with = "locked")]
2696+
#[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "locked")]
26972697
pub frozen: bool,
26982698

26992699
/// Run the given path as a Python script.
@@ -2836,7 +2836,7 @@ pub struct SyncArgs {
28362836
///
28372837
/// Requires that the lockfile is up-to-date. If the lockfile is missing or
28382838
/// needs to be updated, uv will exit with an error.
2839-
#[arg(long, conflicts_with = "frozen")]
2839+
#[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")]
28402840
pub locked: bool,
28412841

28422842
/// Sync without updating the `uv.lock` file.
@@ -2846,7 +2846,7 @@ pub struct SyncArgs {
28462846
/// exit with an error. If the `pyproject.toml` includes changes to dependencies
28472847
/// that have not been included in the lockfile yet, they will not be
28482848
/// present in the environment.
2849-
#[arg(long, conflicts_with = "locked")]
2849+
#[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "locked")]
28502850
pub frozen: bool,
28512851

28522852
#[command(flatten)]
@@ -2896,11 +2896,11 @@ pub struct LockArgs {
28962896
///
28972897
/// Requires that the lockfile is up-to-date. If the lockfile is missing or
28982898
/// needs to be updated, uv will exit with an error.
2899-
#[arg(long, conflicts_with = "frozen")]
2899+
#[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")]
29002900
pub locked: bool,
29012901

29022902
/// Assert that a `uv.lock` exists, without updating it.
2903-
#[arg(long, conflicts_with = "locked")]
2903+
#[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "locked")]
29042904
pub frozen: bool,
29052905

29062906
#[command(flatten)]
@@ -3009,13 +3009,13 @@ pub struct AddArgs {
30093009
///
30103010
/// Requires that the lockfile is up-to-date. If the lockfile is missing or
30113011
/// needs to be updated, uv will exit with an error.
3012-
#[arg(long, conflicts_with = "frozen")]
3012+
#[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")]
30133013
pub locked: bool,
30143014

30153015
/// Add dependencies without re-locking the project.
30163016
///
30173017
/// The project environment will not be synced.
3018-
#[arg(long, conflicts_with = "locked")]
3018+
#[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "locked")]
30193019
pub frozen: bool,
30203020

30213021
#[command(flatten)]
@@ -3079,13 +3079,13 @@ pub struct RemoveArgs {
30793079
///
30803080
/// Requires that the lockfile is up-to-date. If the lockfile is missing or
30813081
/// needs to be updated, uv will exit with an error.
3082-
#[arg(long, conflicts_with = "frozen")]
3082+
#[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")]
30833083
pub locked: bool,
30843084

30853085
/// Remove dependencies without re-locking the project.
30863086
///
30873087
/// The project environment will not be synced.
3088-
#[arg(long, conflicts_with = "locked")]
3088+
#[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "locked")]
30893089
pub frozen: bool,
30903090

30913091
#[command(flatten)]
@@ -3154,13 +3154,13 @@ pub struct TreeArgs {
31543154
///
31553155
/// Requires that the lockfile is up-to-date. If the lockfile is missing or
31563156
/// needs to be updated, uv will exit with an error.
3157-
#[arg(long, conflicts_with = "frozen")]
3157+
#[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")]
31583158
pub locked: bool,
31593159

31603160
/// Display the requirements without locking the project.
31613161
///
31623162
/// If the lockfile is missing, uv will exit with an error.
3163-
#[arg(long, conflicts_with = "locked")]
3163+
#[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "locked")]
31643164
pub frozen: bool,
31653165

31663166
#[command(flatten)]
@@ -3302,13 +3302,13 @@ pub struct ExportArgs {
33023302
///
33033303
/// Requires that the lockfile is up-to-date. If the lockfile is missing or
33043304
/// needs to be updated, uv will exit with an error.
3305-
#[arg(long, conflicts_with = "frozen")]
3305+
#[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")]
33063306
pub locked: bool,
33073307

33083308
/// Do not update the `uv.lock` before exporting.
33093309
///
33103310
/// If a `uv.lock` does not exist, uv will exit with an error.
3311-
#[arg(long, conflicts_with = "locked")]
3311+
#[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "locked")]
33123312
pub frozen: bool,
33133313

33143314
#[command(flatten)]

crates/uv-static/src/env_vars.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ impl EnvVars {
105105
/// Equivalent to the `--no-sync` argument. Skips syncing the environment.
106106
pub const UV_NO_SYNC: &'static str = "UV_NO_SYNC";
107107

108+
/// Equivalent to the `--locked` argument. Assert that the `uv.lock` will remain unchanged.
109+
pub const UV_LOCKED: &'static str = "UV_LOCKED";
110+
111+
/// Equivalent to the `--frozen` argument. Run without updating the `uv.lock` file.
112+
pub const UV_FROZEN: &'static str = "UV_FROZEN";
113+
108114
/// Equivalent to the `--preview` argument. Enables preview mode.
109115
pub const UV_PREVIEW: &'static str = "UV_PREVIEW";
110116

docs/configuration/environment.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ uv accepts the following command-line arguments as environment variables:
8181
set, uv will use this password for publishing.
8282
- `UV_NO_SYNC`: Equivalent to the `--no-sync` command-line argument. If set, uv will skip updating
8383
the environment.
84+
- `UV_LOCKED`: Equivalent to the `--locked` command-line argument. If set, uv will assert that the
85+
`uv.lock` remains unchanged.
86+
- `UV_FROZEN`: Equivalent to the `--frozen` command-line argument. If set, uv will run without
87+
updating the `uv.lock` file.
8488

8589
In each case, the corresponding command-line argument takes precedence over an environment variable.
8690

docs/reference/cli.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ uv run [OPTIONS] [COMMAND]
160160

161161
<p>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 <code>pyproject.toml</code> includes changes to dependencies that have not been included in the lockfile yet, they will not be present in the environment.</p>
162162

163+
<p>May also be set with the <code>UV_FROZEN</code> environment variable.</p>
163164
</dd><dt><code>--help</code>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>
164165

165166
</dd><dt><code>--index</code> <i>index</i></dt><dd><p>The URLs to use when resolving dependencies, in addition to the default index.</p>
@@ -232,6 +233,7 @@ uv run [OPTIONS] [COMMAND]
232233

233234
<p>Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated, uv will exit with an error.</p>
234235

236+
<p>May also be set with the <code>UV_LOCKED</code> environment variable.</p>
235237
</dd><dt><code>--module</code>, <code>-m</code></dt><dd><p>Run a Python module.</p>
236238

237239
<p>Equivalent to <code>python -m &lt;module&gt;</code>.</p>
@@ -749,6 +751,7 @@ uv add [OPTIONS] <PACKAGES|--requirements <REQUIREMENTS>>
749751

750752
<p>The project environment will not be synced.</p>
751753

754+
<p>May also be set with the <code>UV_FROZEN</code> environment variable.</p>
752755
</dd><dt><code>--help</code>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>
753756

754757
</dd><dt><code>--index</code> <i>index</i></dt><dd><p>The URLs to use when resolving dependencies, in addition to the default index.</p>
@@ -813,6 +816,7 @@ uv add [OPTIONS] <PACKAGES|--requirements <REQUIREMENTS>>
813816

814817
<p>Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated, uv will exit with an error.</p>
815818

819+
<p>May also be set with the <code>UV_LOCKED</code> environment variable.</p>
816820
</dd><dt><code>--native-tls</code></dt><dd><p>Whether to load TLS certificates from the platform&#8217;s native certificate store.</p>
817821

818822
<p>By default, uv loads certificates from the bundled <code>webpki-roots</code> crate. The <code>webpki-roots</code> are a reliable set of trust roots from Mozilla, and including them in uv improves portability and performance (especially on macOS).</p>
@@ -1081,6 +1085,7 @@ uv remove [OPTIONS] <PACKAGES>...
10811085

10821086
<p>The project environment will not be synced.</p>
10831087

1088+
<p>May also be set with the <code>UV_FROZEN</code> environment variable.</p>
10841089
</dd><dt><code>--help</code>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>
10851090

10861091
</dd><dt><code>--index</code> <i>index</i></dt><dd><p>The URLs to use when resolving dependencies, in addition to the default index.</p>
@@ -1145,6 +1150,7 @@ uv remove [OPTIONS] <PACKAGES>...
11451150

11461151
<p>Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated, uv will exit with an error.</p>
11471152

1153+
<p>May also be set with the <code>UV_LOCKED</code> environment variable.</p>
11481154
</dd><dt><code>--native-tls</code></dt><dd><p>Whether to load TLS certificates from the platform&#8217;s native certificate store.</p>
11491155

11501156
<p>By default, uv loads certificates from the bundled <code>webpki-roots</code> crate. The <code>webpki-roots</code> are a reliable set of trust roots from Mozilla, and including them in uv improves portability and performance (especially on macOS).</p>
@@ -1401,6 +1407,7 @@ uv sync [OPTIONS]
14011407

14021408
<p>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 <code>pyproject.toml</code> includes changes to dependencies that have not been included in the lockfile yet, they will not be present in the environment.</p>
14031409

1410+
<p>May also be set with the <code>UV_FROZEN</code> environment variable.</p>
14041411
</dd><dt><code>--help</code>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>
14051412

14061413
</dd><dt><code>--index</code> <i>index</i></dt><dd><p>The URLs to use when resolving dependencies, in addition to the default index.</p>
@@ -1469,6 +1476,7 @@ uv sync [OPTIONS]
14691476

14701477
<p>Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated, uv will exit with an error.</p>
14711478

1479+
<p>May also be set with the <code>UV_LOCKED</code> environment variable.</p>
14721480
</dd><dt><code>--native-tls</code></dt><dd><p>Whether to load TLS certificates from the platform&#8217;s native certificate store.</p>
14731481

14741482
<p>By default, uv loads certificates from the bundled <code>webpki-roots</code> crate. The <code>webpki-roots</code> are a reliable set of trust roots from Mozilla, and including them in uv improves portability and performance (especially on macOS).</p>
@@ -1717,6 +1725,7 @@ uv lock [OPTIONS]
17171725
<p>May also be set with the <code>UV_FIND_LINKS</code> environment variable.</p>
17181726
</dd><dt><code>--frozen</code></dt><dd><p>Assert that a <code>uv.lock</code> exists, without updating it</p>
17191727

1728+
<p>May also be set with the <code>UV_FROZEN</code> environment variable.</p>
17201729
</dd><dt><code>--help</code>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>
17211730

17221731
</dd><dt><code>--index</code> <i>index</i></dt><dd><p>The URLs to use when resolving dependencies, in addition to the default index.</p>
@@ -1783,6 +1792,7 @@ uv lock [OPTIONS]
17831792

17841793
<p>Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated, uv will exit with an error.</p>
17851794

1795+
<p>May also be set with the <code>UV_LOCKED</code> environment variable.</p>
17861796
</dd><dt><code>--native-tls</code></dt><dd><p>Whether to load TLS certificates from the platform&#8217;s native certificate store.</p>
17871797

17881798
<p>By default, uv loads certificates from the bundled <code>webpki-roots</code> crate. The <code>webpki-roots</code> are a reliable set of trust roots from Mozilla, and including them in uv improves portability and performance (especially on macOS).</p>
@@ -2023,6 +2033,7 @@ uv export [OPTIONS]
20232033

20242034
<p>If a <code>uv.lock</code> does not exist, uv will exit with an error.</p>
20252035

2036+
<p>May also be set with the <code>UV_FROZEN</code> environment variable.</p>
20262037
</dd><dt><code>--help</code>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>
20272038

20282039
</dd><dt><code>--index</code> <i>index</i></dt><dd><p>The URLs to use when resolving dependencies, in addition to the default index.</p>
@@ -2089,6 +2100,7 @@ uv export [OPTIONS]
20892100

20902101
<p>Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated, uv will exit with an error.</p>
20912102

2103+
<p>May also be set with the <code>UV_LOCKED</code> environment variable.</p>
20922104
</dd><dt><code>--native-tls</code></dt><dd><p>Whether to load TLS certificates from the platform&#8217;s native certificate store.</p>
20932105

20942106
<p>By default, uv loads certificates from the bundled <code>webpki-roots</code> crate. The <code>webpki-roots</code> are a reliable set of trust roots from Mozilla, and including them in uv improves portability and performance (especially on macOS).</p>
@@ -2338,6 +2350,7 @@ uv tree [OPTIONS]
23382350

23392351
<p>If the lockfile is missing, uv will exit with an error.</p>
23402352

2353+
<p>May also be set with the <code>UV_FROZEN</code> environment variable.</p>
23412354
</dd><dt><code>--help</code>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>
23422355

23432356
</dd><dt><code>--index</code> <i>index</i></dt><dd><p>The URLs to use when resolving dependencies, in addition to the default index.</p>
@@ -2406,6 +2419,7 @@ uv tree [OPTIONS]
24062419

24072420
<p>Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated, uv will exit with an error.</p>
24082421

2422+
<p>May also be set with the <code>UV_LOCKED</code> environment variable.</p>
24092423
</dd><dt><code>--native-tls</code></dt><dd><p>Whether to load TLS certificates from the platform&#8217;s native certificate store.</p>
24102424

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

0 commit comments

Comments
 (0)