Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 72 additions & 7 deletions crates/uv-resolver/src/lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::str::FromStr;
use std::sync::{Arc, LazyLock};

use itertools::Itertools;
use jiff::Timestamp;
use owo_colors::OwoColorize;
use petgraph::graph::NodeIndex;
use petgraph::visit::EdgeRef;
Expand Down Expand Up @@ -69,7 +70,7 @@ mod tree;
pub const VERSION: u32 = 1;

/// The current revision of the lockfile format.
const REVISION: u32 = 1;
const REVISION: u32 = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\o/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need any process around rolling out a new revision?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait it looks like upload time is optional? Do we need to bump the revision number here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the bumped revision means we can tell if the optional field is expected to be available.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(REVISION != VERSION)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay!


static LINUX_MARKERS: LazyLock<UniversalMarker> = LazyLock::new(|| {
let pep508 = MarkerTree::from_str("os_name == 'posix' and sys_platform == 'linux'").unwrap();
Expand Down Expand Up @@ -2507,7 +2508,7 @@ impl Package {
}),
requires_python: None,
size: sdist.size(),
upload_time_utc_ms: None,
upload_time_utc_ms: sdist.upload_time().map(Timestamp::as_millisecond),
url: FileLocation::AbsoluteUrl(file_url.clone()),
yanked: None,
});
Expand Down Expand Up @@ -2558,7 +2559,7 @@ impl Package {
}),
requires_python: None,
size: sdist.size(),
upload_time_utc_ms: None,
upload_time_utc_ms: sdist.upload_time().map(Timestamp::as_millisecond),
url: FileLocation::AbsoluteUrl(UrlString::from(file_url)),
yanked: None,
});
Expand Down Expand Up @@ -3630,6 +3631,8 @@ struct SourceDistMetadata {
///
/// This is only present for source distributions that come from registries.
size: Option<u64>,
/// The upload time of the source distribution.
upload_time: Option<Timestamp>,
}

/// A URL or file path where the source dist that was
Expand Down Expand Up @@ -3697,6 +3700,14 @@ impl SourceDist {
SourceDist::Path { metadata, .. } => metadata.size,
}
}

pub(crate) fn upload_time(&self) -> Option<Timestamp> {
match &self {
SourceDist::Metadata { metadata } => metadata.upload_time,
SourceDist::Url { metadata, .. } => metadata.upload_time,
SourceDist::Path { metadata, .. } => metadata.upload_time,
}
}
}

impl SourceDist {
Expand Down Expand Up @@ -3777,9 +3788,19 @@ impl SourceDist {
.map_err(LockError::from)?;
let hash = reg_dist.file.hashes.iter().max().cloned().map(Hash::from);
let size = reg_dist.file.size;
let upload_time = reg_dist
.file
.upload_time_utc_ms
.map(Timestamp::from_millisecond)
.transpose()
.map_err(LockErrorKind::InvalidTimestamp)?;
Ok(Some(SourceDist::Url {
url,
metadata: SourceDistMetadata { hash, size },
metadata: SourceDistMetadata {
hash,
size,
upload_time,
},
}))
}
IndexUrl::Path(path) => {
Expand All @@ -3797,9 +3818,19 @@ impl SourceDist {
.into_boxed_path();
let hash = reg_dist.file.hashes.iter().max().cloned().map(Hash::from);
let size = reg_dist.file.size;
let upload_time = reg_dist
.file
.upload_time_utc_ms
.map(Timestamp::from_millisecond)
.transpose()
.map_err(LockErrorKind::InvalidTimestamp)?;
Ok(Some(SourceDist::Path {
path,
metadata: SourceDistMetadata { hash, size },
metadata: SourceDistMetadata {
hash,
size,
upload_time,
},
}))
}
}
Expand All @@ -3818,6 +3849,7 @@ impl SourceDist {
metadata: SourceDistMetadata {
hash: Some(hash),
size: None,
upload_time: None,
},
})
}
Expand All @@ -3835,6 +3867,7 @@ impl SourceDist {
metadata: SourceDistMetadata {
hash: Some(hash),
size: None,
upload_time: None,
},
})
}
Expand Down Expand Up @@ -3881,6 +3914,9 @@ impl SourceDist {
toml_edit::ser::ValueSerializer::new().serialize_u64(size)?,
);
}
if let Some(upload_time) = self.upload_time() {
table.insert("upload_time", Value::from(upload_time.to_string()));
}
Ok(table)
}
}
Expand Down Expand Up @@ -3995,6 +4031,10 @@ struct Wheel {
///
/// This is only present for wheels that come from registries.
size: Option<u64>,
/// The upload time of the built distribution.
///
/// This is only present for wheels that come from registries.
upload_time: Option<Timestamp>,
/// The filename of the wheel.
///
/// This isn't part of the wire format since it's redundant with the
Expand Down Expand Up @@ -4079,11 +4119,18 @@ impl Wheel {
.map_err(LockError::from)?;
let hash = wheel.file.hashes.iter().max().cloned().map(Hash::from);
let size = wheel.file.size;
let upload_time = wheel
.file
.upload_time_utc_ms
.map(Timestamp::from_millisecond)
.transpose()
.map_err(LockErrorKind::InvalidTimestamp)?;
Ok(Wheel {
url: WheelWireSource::Url { url },
hash,
size,
filename,
upload_time,
})
}
IndexUrl::Path(path) => {
Expand All @@ -4103,6 +4150,7 @@ impl Wheel {
url: WheelWireSource::Path { path },
hash: None,
size: None,
upload_time: None,
filename,
})
}
Expand All @@ -4116,6 +4164,7 @@ impl Wheel {
},
hash: hashes.iter().max().cloned().map(Hash::from),
size: None,
upload_time: None,
filename: direct_dist.filename.clone(),
}
}
Expand All @@ -4127,6 +4176,7 @@ impl Wheel {
},
hash: hashes.iter().max().cloned().map(Hash::from),
size: None,
upload_time: None,
filename: path_dist.filename.clone(),
}
}
Expand Down Expand Up @@ -4156,7 +4206,7 @@ impl Wheel {
hashes: self.hash.iter().map(|h| h.0.clone()).collect(),
requires_python: None,
size: self.size,
upload_time_utc_ms: None,
upload_time_utc_ms: self.upload_time.map(Timestamp::as_millisecond),
url: FileLocation::AbsoluteUrl(file_url.clone()),
yanked: None,
});
Expand Down Expand Up @@ -4188,7 +4238,7 @@ impl Wheel {
hashes: self.hash.iter().map(|h| h.0.clone()).collect(),
requires_python: None,
size: self.size,
upload_time_utc_ms: None,
upload_time_utc_ms: self.upload_time.map(Timestamp::as_millisecond),
url: FileLocation::AbsoluteUrl(UrlString::from(file_url)),
yanked: None,
});
Expand Down Expand Up @@ -4220,6 +4270,10 @@ struct WheelWire {
///
/// This is only present for wheels that come from registries.
size: Option<u64>,
/// The upload time of the built distribution.
///
/// This is only present for wheels that come from registries.
upload_time: Option<Timestamp>,
}

#[derive(Clone, Debug, serde::Deserialize, PartialEq, Eq)]
Expand Down Expand Up @@ -4272,6 +4326,9 @@ impl Wheel {
toml_edit::ser::ValueSerializer::new().serialize_u64(size)?,
);
}
if let Some(upload_time) = self.upload_time {
table.insert("upload_time", Value::from(upload_time.to_string()));
}
Ok(table)
}
}
Expand Down Expand Up @@ -4305,6 +4362,7 @@ impl TryFrom<WheelWire> for Wheel {
url: wire.url,
hash: wire.hash,
size: wire.size,
upload_time: wire.upload_time,
filename,
})
}
Expand Down Expand Up @@ -5036,6 +5094,13 @@ enum LockErrorKind {
#[source]
SourceParseError,
),
#[error("Failed to parse timestamp")]
InvalidTimestamp(
/// The underlying error that occurred. This includes the
/// errant timestamp in the message.
#[source]
jiff::Error,
),
/// An error that occurs when there's an unrecognized dependency.
///
/// That is, a dependency for a package that isn't in the lockfile.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Ok(
},
hash: None,
size: None,
upload_time: None,
filename: WheelFilename {
name: PackageName(
"anyio",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Ok(
),
),
size: None,
upload_time: None,
filename: WheelFilename {
name: PackageName(
"anyio",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Ok(
),
),
size: None,
upload_time: None,
filename: WheelFilename {
name: PackageName(
"anyio",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Ok(
size: Some(
0,
),
upload_time: None,
},
},
),
Expand Down Expand Up @@ -119,6 +120,7 @@ Ok(
size: Some(
0,
),
upload_time: None,
},
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Ok(
size: Some(
0,
),
upload_time: None,
},
},
),
Expand Down Expand Up @@ -119,6 +120,7 @@ Ok(
size: Some(
0,
),
upload_time: None,
},
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Ok(
size: Some(
0,
),
upload_time: None,
},
},
),
Expand Down Expand Up @@ -141,6 +142,7 @@ Ok(
size: Some(
0,
),
upload_time: None,
},
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Ok(
size: Some(
0,
),
upload_time: None,
},
},
),
Expand Down Expand Up @@ -119,6 +120,7 @@ Ok(
size: Some(
0,
),
upload_time: None,
},
},
),
Expand Down
Loading
Loading