Skip to content

Commit 34fbc06

Browse files
Gankrax0rwzaniebjtfmumm
authored
Add experimental uv sync --output-format json (#13689)
This is a continuation of the work in * #12405 I have: * moved to an architecture where the human output is derived from the json structs to centralize more of the printing state/logic * cleaned up some of the names/types * added tests * removed the restriction that this output is --dry-run only I have not yet added package info, which was TBD in their design. --------- Co-authored-by: x0rw <[email protected]> Co-authored-by: Zanie Blue <[email protected]> Co-authored-by: John Mumm <[email protected]>
1 parent df44199 commit 34fbc06

File tree

9 files changed

+1389
-604
lines changed

9 files changed

+1389
-604
lines changed

crates/uv-cli/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ pub enum PythonListFormat {
4646
Json,
4747
}
4848

49+
#[derive(Debug, Default, Clone, Copy, clap::ValueEnum)]
50+
pub enum SyncFormat {
51+
/// Display the result in a human-readable format.
52+
#[default]
53+
Text,
54+
/// Display the result in JSON format.
55+
Json,
56+
}
57+
4958
#[derive(Debug, Default, Clone, clap::ValueEnum)]
5059
pub enum ListFormat {
5160
/// Display the list of packages in a human-readable table.
@@ -3207,6 +3216,10 @@ pub struct SyncArgs {
32073216
#[arg(long, conflicts_with = "all_extras", value_parser = extra_name_with_clap_error)]
32083217
pub extra: Option<Vec<ExtraName>>,
32093218

3219+
/// Select the output format.
3220+
#[arg(long, value_enum, default_value_t = SyncFormat::default())]
3221+
pub output_format: SyncFormat,
3222+
32103223
/// Include all optional dependencies.
32113224
///
32123225
/// When two or more extras are declared as conflicting in `tool.uv.conflicts`, using this flag

crates/uv-fs/src/path.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,12 @@ impl From<Box<Path>> for PortablePathBuf {
398398
}
399399
}
400400

401+
impl<'a> From<&'a Path> for PortablePathBuf {
402+
fn from(path: &'a Path) -> Self {
403+
Box::<Path>::from(path).into()
404+
}
405+
}
406+
401407
#[cfg(feature = "serde")]
402408
impl serde::Serialize for PortablePathBuf {
403409
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,14 @@ impl ProjectEnvironment {
14081408
Self::WouldCreate(..) => Err(ProjectError::DroppedEnvironment),
14091409
}
14101410
}
1411+
1412+
/// Return the path to the actual target, if this was a dry run environment.
1413+
pub(crate) fn dry_run_target(&self) -> Option<&Path> {
1414+
match self {
1415+
Self::WouldReplace(path, _, _) | Self::WouldCreate(path, _, _) => Some(path),
1416+
Self::Created(_) | Self::Existing(_) | Self::Replaced(_) => None,
1417+
}
1418+
}
14111419
}
14121420

14131421
impl std::ops::Deref for ProjectEnvironment {
@@ -1588,6 +1596,14 @@ impl ScriptEnvironment {
15881596
Self::WouldCreate(..) => Err(ProjectError::DroppedEnvironment),
15891597
}
15901598
}
1599+
1600+
/// Return the path to the actual target, if this was a dry run environment.
1601+
pub(crate) fn dry_run_target(&self) -> Option<&Path> {
1602+
match self {
1603+
Self::WouldReplace(path, _, _) | Self::WouldCreate(path, _, _) => Some(path),
1604+
Self::Created(_) | Self::Existing(_) | Self::Replaced(_) => None,
1605+
}
1606+
}
15911607
}
15921608

15931609
impl std::ops::Deref for ScriptEnvironment {

0 commit comments

Comments
 (0)