Skip to content

Commit

Permalink
uv: add --unstable-uv-lock-file flag to uv pip compile
Browse files Browse the repository at this point in the history
This flag is hidden, and it is not meant to live forever. Its only
purpose is to provide a way to generate a `uv.lock` using our existing
CLI tooling.

We specifically avoid adding this to persistent configuration to
minimize where it can be used.
  • Loading branch information
BurntSushi committed Apr 29, 2024
1 parent 42392c7 commit b538042
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/uv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ tempfile = { workspace = true }
textwrap = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }
toml = { workspace = true }
tracing = { workspace = true }
tracing-durations-export = { workspace = true, features = ["plot"], optional = true }
tracing-subscriber = { workspace = true, features = ["json"] }
Expand Down
6 changes: 6 additions & 0 deletions crates/uv/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,12 @@ pub(crate) struct PipCompileArgs {
#[arg(long, overrides_with("emit_index_annotation"), hide = true)]
pub(crate) no_emit_index_annotation: bool,

#[arg(long, overrides_with("no_unstable_uv_lock_file"), hide = true)]
pub(crate) unstable_uv_lock_file: bool,

#[arg(long, overrides_with("unstable_uv_lock_file"), hide = true)]
pub(crate) no_unstable_uv_lock_file: bool,

#[command(flatten)]
pub(crate) compat_args: compat::PipCompileCompatArgs,
}
Expand Down
8 changes: 8 additions & 0 deletions crates/uv/src/commands/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::str::FromStr;

use anstream::{eprint, AutoStream, StripStream};
use anyhow::{anyhow, Context, Result};
use fs_err as fs;
use itertools::Itertools;
use owo_colors::OwoColorize;
use tempfile::tempdir_in;
Expand Down Expand Up @@ -84,6 +85,7 @@ pub(crate) async fn pip_compile(
link_mode: LinkMode,
python: Option<String>,
system: bool,
uv_lock: bool,
native_tls: bool,
quiet: bool,
cache: Cache,
Expand Down Expand Up @@ -525,6 +527,12 @@ pub(crate) async fn pip_compile(
writeln!(writer, "{}", format!("# {relevant_markers}").green())?;
}

if uv_lock {
let lock = resolution.lock()?;
let encoded = toml::to_string_pretty(&lock)?;
fs::tokio::write("uv.lock", encoded.as_bytes()).await?;
}

// Write the index locations to the output channel.
let mut wrote_index = false;

Expand Down
1 change: 1 addition & 0 deletions crates/uv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ async fn run() -> Result<ExitStatus> {
args.shared.link_mode,
args.shared.python,
args.shared.system,
args.uv_lock,
globals.native_tls,
globals.quiet,
cache,
Expand Down
4 changes: 4 additions & 0 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pub(crate) struct PipCompileSettings {
pub(crate) r#override: Vec<PathBuf>,
pub(crate) refresh: Refresh,
pub(crate) upgrade: Upgrade,
pub(crate) uv_lock: bool,

// Shared settings.
pub(crate) shared: PipSharedSettings,
Expand Down Expand Up @@ -194,6 +195,8 @@ impl PipCompileSettings {
no_emit_marker_expression,
emit_index_annotation,
no_emit_index_annotation,
unstable_uv_lock_file,
no_unstable_uv_lock_file,
compat_args: _,
} = args;

Expand All @@ -207,6 +210,7 @@ impl PipCompileSettings {
r#override,
refresh: Refresh::from_args(refresh, refresh_package),
upgrade: Upgrade::from_args(upgrade, upgrade_package),
uv_lock: flag(unstable_uv_lock_file, no_unstable_uv_lock_file).unwrap_or(false),

// Shared settings.
shared: PipSharedSettings::combine(
Expand Down

0 comments on commit b538042

Please sign in to comment.