Skip to content

Commit 38884da

Browse files
authored
make uv version lock and sync (astral-sh#13317)
This adopts the logic from `uv remove` for locking and syncing, as the scope of the changes made are ultimately similar. Unlike `uv remove` there is no support for modifying PEP723 scripts, as these are not versioned. In doing this the `version` command gains a truckload of args for configuring lock/sync behaviour. Presumably most of these are passed via settings or env files, and not of particular concern. The most interesting additions are: * `--frozen`: makes `uv version` work ~exactly as it did before this PR * `--locked`: errors if the lockfile is out of date * `--no-sync`: updates the lockfile, but doesn't run the equivalent of `uv sync` * `--package name`: a convenience for referring to a package in the workspace Note that the existing `--dry-run` flag effectively implies `--frozen` for sets and bumps. Fixes astral-sh#13254 Fixes astral-sh#13548
1 parent cf27c07 commit 38884da

File tree

9 files changed

+1776
-182
lines changed

9 files changed

+1776
-182
lines changed

crates/uv-cli/src/lib.rs

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,6 @@ pub enum Commands {
493493
/// Clear the cache, removing all entries or those linked to specific packages.
494494
#[command(hide = true)]
495495
Clean(CleanArgs),
496-
/// Read or update the project's version.
497-
Version(VersionArgs),
498496
/// Generate shell completion
499497
#[command(alias = "--generate-shell-completion", hide = true)]
500498
GenerateShellCompletion(GenerateShellCompletionArgs),
@@ -525,29 +523,91 @@ pub struct HelpArgs {
525523
pub command: Option<Vec<String>>,
526524
}
527525

528-
#[derive(Args, Debug)]
526+
#[derive(Args)]
529527
#[command(group = clap::ArgGroup::new("operation"))]
528+
#[allow(clippy::struct_excessive_bools)]
530529
pub struct VersionArgs {
531530
/// Set the project version to this value
532531
///
533532
/// To update the project using semantic versioning components instead, use `--bump`.
534533
#[arg(group = "operation")]
535534
pub value: Option<String>,
535+
536536
/// Update the project version using the given semantics
537537
#[arg(group = "operation", long)]
538538
pub bump: Option<VersionBump>,
539+
539540
/// Don't write a new version to the `pyproject.toml`
540541
///
541542
/// Instead, the version will be displayed.
542543
#[arg(long)]
543544
pub dry_run: bool,
545+
544546
/// Only show the version
545547
///
546548
/// By default, uv will show the project name before the version.
547549
#[arg(long)]
548550
pub short: bool,
551+
552+
/// The format of the output
549553
#[arg(long, value_enum, default_value = "text")]
550554
pub output_format: VersionFormat,
555+
556+
/// Avoid syncing the virtual environment after re-locking the project.
557+
#[arg(long, env = EnvVars::UV_NO_SYNC, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")]
558+
pub no_sync: bool,
559+
560+
/// Prefer the active virtual environment over the project's virtual environment.
561+
///
562+
/// If the project virtual environment is active or no virtual environment is active, this has
563+
/// no effect.
564+
#[arg(long, overrides_with = "no_active")]
565+
pub active: bool,
566+
567+
/// Prefer project's virtual environment over an active environment.
568+
///
569+
/// This is the default behavior.
570+
#[arg(long, overrides_with = "active", hide = true)]
571+
pub no_active: bool,
572+
573+
/// Assert that the `uv.lock` will remain unchanged.
574+
///
575+
/// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
576+
/// uv will exit with an error.
577+
#[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["frozen", "upgrade"])]
578+
pub locked: bool,
579+
580+
/// Update the version without re-locking the project.
581+
///
582+
/// The project environment will not be synced.
583+
#[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["locked", "upgrade", "no_sources"])]
584+
pub frozen: bool,
585+
586+
#[command(flatten)]
587+
pub installer: ResolverInstallerArgs,
588+
589+
#[command(flatten)]
590+
pub build: BuildOptionsArgs,
591+
592+
#[command(flatten)]
593+
pub refresh: RefreshArgs,
594+
595+
/// Update the version of a specific package in the workspace.
596+
#[arg(long, conflicts_with = "isolated")]
597+
pub package: Option<PackageName>,
598+
599+
/// The Python interpreter to use for resolving and syncing.
600+
///
601+
/// See `uv help python` for details on Python discovery and supported request formats.
602+
#[arg(
603+
long,
604+
short,
605+
env = EnvVars::UV_PYTHON,
606+
verbatim_doc_comment,
607+
help_heading = "Python options",
608+
value_parser = parse_maybe_string,
609+
)]
610+
pub python: Option<Maybe<String>>,
551611
}
552612

553613
#[derive(Debug, Copy, Clone, PartialEq, clap::ValueEnum)]
@@ -819,6 +879,8 @@ pub enum ProjectCommand {
819879
after_long_help = ""
820880
)]
821881
Remove(RemoveArgs),
882+
/// Read or update the project's version.
883+
Version(VersionArgs),
822884
/// Update the project's environment.
823885
///
824886
/// Syncing ensures that all project dependencies are installed and up-to-date with the

crates/uv/src/commands/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub(crate) use project::remove::remove;
2929
pub(crate) use project::run::{RunCommand, run};
3030
pub(crate) use project::sync::sync;
3131
pub(crate) use project::tree::tree;
32+
pub(crate) use project::version::{project_version, self_version};
3233
pub(crate) use publish::publish;
3334
pub(crate) use python::dir::dir as python_dir;
3435
pub(crate) use python::find::find as python_find;
@@ -56,7 +57,6 @@ use uv_normalize::PackageName;
5657
use uv_python::PythonEnvironment;
5758
use uv_scripts::Pep723Script;
5859
pub(crate) use venv::venv;
59-
pub(crate) use version::{project_version, self_version};
6060

6161
use crate::printer::Printer;
6262

@@ -77,7 +77,6 @@ mod run;
7777
mod self_update;
7878
mod tool;
7979
mod venv;
80-
mod version;
8180

8281
#[derive(Copy, Clone)]
8382
pub(crate) enum ExitStatus {

crates/uv/src/commands/project/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub(crate) mod remove;
6767
pub(crate) mod run;
6868
pub(crate) mod sync;
6969
pub(crate) mod tree;
70+
pub(crate) mod version;
7071

7172
#[derive(thiserror::Error, Debug)]
7273
pub(crate) enum ProjectError {

0 commit comments

Comments
 (0)