Reframe `--locked` and `--frozen` as `--check` operations for `uv lock` (#9662)

Closes https://github.com/astral-sh/uv/issues/7639
This commit is contained in:
Zanie Blue 2024-12-08 10:02:00 -06:00 committed by GitHub
parent 00a4adfc46
commit 84285b69e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 37 additions and 21 deletions

View File

@ -3042,22 +3042,26 @@ pub struct SyncArgs {
#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub struct LockArgs {
/// Assert that the `uv.lock` will remain unchanged.
/// Check if the lockfile is up-to-date.
///
/// 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, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")]
pub locked: bool,
/// Asserts that the `uv.lock` would remain unchanged after a resolution. If the lockfile is
/// missing or needs to be updated, uv will exit with an error.
///
/// Equivalent to `--locked`.
#[arg(long, alias = "locked", env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "check_exists")]
pub check: bool,
/// Assert that a `uv.lock` exists, without updating it.
#[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "locked")]
pub frozen: bool,
/// Assert that a `uv.lock` exists without checking if it is up-to-date.
///
/// Equivalent to `--frozen`.
#[arg(long, alias = "frozen", env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "check")]
pub check_exists: bool,
/// Perform a dry run, without writing the lockfile.
///
/// In dry-run mode, uv will resolve the project's dependencies and report on the resulting
/// changes, but will not write the lockfile to disk.
#[arg(long, conflicts_with = "frozen", conflicts_with = "locked")]
#[arg(long, conflicts_with = "check_exists", conflicts_with = "check")]
pub dry_run: bool,
#[command(flatten)]

View File

@ -990,8 +990,8 @@ impl LockSettings {
#[allow(clippy::needless_pass_by_value)]
pub(crate) fn resolve(args: LockArgs, filesystem: Option<FilesystemOptions>) -> Self {
let LockArgs {
locked,
frozen,
check,
check_exists,
dry_run,
resolver,
build,
@ -1005,8 +1005,8 @@ impl LockSettings {
.unwrap_or_default();
Self {
locked,
frozen,
locked: check,
frozen: check_exists,
dry_run,
python: python.and_then(Maybe::into_option),
refresh: Refresh::from(refresh),

View File

@ -27,6 +27,14 @@ To avoid updating the environment during `uv run` invocations, use the `--no-syn
To assert the lockfile matches the project metadata, use the `--locked` flag. If the lockfile is not
up-to-date, an error will be raised instead of updating the lockfile.
You can also check if the lockfile is up-to-date by passing the `--check` flag to `uv lock`:
```console
$ uv lock --check
```
This is equivalent to the `--locked` flag for other commands.
### Upgrading locked package versions
By default, uv will prefer the locked versions of packages when running `uv sync` and `uv lock`.

View File

@ -1790,6 +1790,18 @@ uv lock [OPTIONS]
<p>To view the location of the cache directory, run <code>uv cache dir</code>.</p>
<p>May also be set with the <code>UV_CACHE_DIR</code> environment variable.</p>
</dd><dt><code>--check</code></dt><dd><p>Check if the lockfile is up-to-date.</p>
<p>Asserts that the <code>uv.lock</code> would remain unchanged after a resolution. If the lockfile is missing or needs to be updated, uv will exit with an error.</p>
<p>Equivalent to <code>--locked</code>.</p>
<p>May also be set with the <code>UV_LOCKED</code> environment variable.</p>
</dd><dt><code>--check-exists</code></dt><dd><p>Assert that a <code>uv.lock</code> exists without checking if it is up-to-date.</p>
<p>Equivalent to <code>--frozen</code>.</p>
<p>May also be set with the <code>UV_FROZEN</code> environment variable.</p>
</dd><dt><code>--color</code> <i>color-choice</i></dt><dd><p>Control colors in output</p>
<p>[default: auto]</p>
@ -1845,9 +1857,6 @@ uv lock [OPTIONS]
<p>If a URL, the page must contain a flat list of links to package files adhering to the formats described above.</p>
<p>May also be set with the <code>UV_FIND_LINKS</code> environment variable.</p>
</dd><dt><code>--frozen</code></dt><dd><p>Assert that a <code>uv.lock</code> exists, without updating it</p>
<p>May also be set with the <code>UV_FROZEN</code> environment variable.</p>
</dd><dt><code>--help</code>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>
</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>
@ -1910,11 +1919,6 @@ uv lock [OPTIONS]
<li><code>symlink</code>: Symbolically link packages from the wheel into the <code>site-packages</code> directory</li>
</ul>
</dd><dt><code>--locked</code></dt><dd><p>Assert that the <code>uv.lock</code> will remain unchanged.</p>
<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>
<p>May also be set with the <code>UV_LOCKED</code> environment variable.</p>
</dd><dt><code>--native-tls</code></dt><dd><p>Whether to load TLS certificates from the platform&#8217;s native certificate store.</p>
<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>