Skip to content
Closed
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
12 changes: 11 additions & 1 deletion crates/uv-resolver/src/exclude_newer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::str::FromStr;
use jiff::{tz::TimeZone, Timestamp, ToSpan};

/// A timestamp that excludes files newer than it.
#[derive(Debug, Copy, Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, serde::Serialize)]
pub struct ExcludeNewer(Timestamp);

impl ExcludeNewer {
Expand Down Expand Up @@ -59,6 +59,16 @@ impl FromStr for ExcludeNewer {
}
}

impl<'de> serde::Deserialize<'de> for ExcludeNewer {
fn deserialize<D>(deserializer: D) -> Result<ExcludeNewer, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
FromStr::from_str(&s).map_err(serde::de::Error::custom)
}
}
Comment on lines +62 to +70
Copy link
Member

Choose a reason for hiding this comment

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

cc @BurntSushi I remember some recent discussion about local dates?


impl std::fmt::Display for ExcludeNewer {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
Expand Down
33 changes: 33 additions & 0 deletions crates/uv/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,39 @@ fn run_pep723_script_metadata() -> Result<()> {
Ok(())
}

#[test]
fn run_pep723_script_metadata_exclude_newer_local_date() -> Result<()> {
let context = TestContext::new("3.12");

let test_script = context.temp_dir.child("main.py");
test_script.write_str(indoc! { r#"
# /// script
# dependencies = ["sniffio"]
# [tool.uv]
# exclude-newer = "2020-01-01"
# ///
import sniffio
print(sniffio.__version__)
"#
})?;

uv_snapshot!(context.filters(), context.run().env_remove("UV_EXCLUDE_NEWER").arg("main.py"), @r###"
success: true
exit_code: 0
----- stdout -----
1.1.0

----- stderr -----
Reading inline script metadata from: main.py
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ sniffio==1.1.0
"###);

Ok(())
}

/// With `managed = false`, we should avoid installing the project itself.
#[test]
fn run_managed_false() -> Result<()> {
Expand Down
7 changes: 4 additions & 3 deletions docs/guides/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,17 @@ uv supports an `exclude-newer` field in the `tool.uv` section of inline script m
to only considering distributions released before a specific date. This is useful for improving the
reproducibility of your script when run at a later point in time.

The date must be specified as an [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339.html) timestamp
(e.g., `2006-12-02T02:07:43Z`).
The date may be specified as an [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339.html) timestamp
(e.g., `2006-12-02T02:07:43Z`) or a local date in the same format (e.g., `2006-12-02`) in your
system's configured time zone.

```python title="example.py"
# /// script
# dependencies = [
# "requests",
# ]
# [tool.uv]
# exclude-newer = "2023-10-16T00:00:00Z"
# exclude-newer = "2023-10-16"
# ///

import requests
Expand Down
Loading