Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow local date for inline exclude newer #6562

Closed
wants to merge 5 commits into from

Conversation

hauntsaninja
Copy link
Contributor

Resolves #6555

Copy link
Member

@zanieb zanieb left a comment

Choose a reason for hiding this comment

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

Thank you!

Comment on lines +62 to +70
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)
}
}
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?

@zanieb zanieb requested a review from BurntSushi August 23, 2024 23:41
@zanieb zanieb added documentation Improvements or additions to documentation enhancement New feature or request labels Aug 23, 2024
@zanieb
Copy link
Member

zanieb commented Aug 27, 2024

@hauntsaninja on further thought, isn't it wrong to allow a local date for exclude-newer in files that are intended to be version controlled and distributed? It seems like a bit of a correctness problem to have the script resolve to different dependencies depending on who is running it. It might make sense to require people to use a proper timestamp here that will be correct regardless of the execution timezone.

I think this notably differs from UV_EXCLUDE_NEWER which is configured on a single machine and not easily distributed.

@hauntsaninja
Copy link
Contributor Author

hauntsaninja commented Aug 27, 2024

It's a fair concern! The use case I'm thinking of is "I wrote a script a few years ago and I want it to mostly run the same, maximising convenience / bang for buck". My guess is this use case will be much more common than inter-timezone distribution. We could also resolve different dependencies for different people depending on arch or python version as well, it's why I phrased this as "improving" reproducibility.

@zanieb
Copy link
Member

zanieb commented Aug 27, 2024

I feel like if we want to maximize convenience we should allow emitting an exclude newer pin (in UTC) via a command or, even better, we should be able to write a lock to scripts. Hm.

If you're willing to separate the change from the docs, we can merge the docs right away. I think we'll wait for @BurntSushi to be back from vacation to make a decision on the local dates.

Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

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

I think this is making the serde::Deserialize trait implementation on ExcludeNewer consistent with its FromStr trait implementation.

I am still pretty iffy on supporting local dates here though. When I added support for it to ExcludeNewer, I was thinking about its use on the command line or in user-specific configuration files. But this seems to be expanding its scope to a point where I think it actually becomes problematic. If, for example, exclude-newer = "2023-10-16" is put into a script and then shared with someone else, that date may be interpreted as an entirely different instant than is intended. It might be better to just keep it restricted to RFC 3339 timestamps. Although, the difference in the Deserialize and FromStr trait implementation seems like a footgun.

@BurntSushi
Copy link
Member

For completeness, one alternative here is to parse an RFC 9557 timestamp (an extension to RFC 3339). So you could write something like 2024-08-28[America/New_York]. That would let you write something "local" that would still (almost certainly) translate to the same instant on anyone else's machine. But it's a bit of a heavier tool to leverage and technically relies on a time zone database and so on.

@BurntSushi
Copy link
Member

Related: #6820

@hauntsaninja
Copy link
Contributor Author

Actually one possibly silly thought, should we make the short form just be a UTC timestamp? In the short form I think it's arguably already a little unclear what the boundary semantics are (e.g. --exclude-newer 2024-08-28 does kind of read like 2024-08-28T23:59:59 to me).

This is also nice if you have a cloud machine on UTC time and you want to reproduce a command using the short form on your local machine. It's technically a breaking change, but it seems maybe saner, and I have a hard time thinking about the user profile who would be broken by it.

@hauntsaninja
Copy link
Contributor Author

hauntsaninja commented Aug 29, 2024

Anyway, sounds like I should split the PRs regardless: #6831 for docs!

zanieb pushed a commit that referenced this pull request Aug 29, 2024
@hauntsaninja hauntsaninja changed the title Add docs for inline exclude newer, allow local date Allow local date for inline exclude newer Aug 29, 2024
@BurntSushi
Copy link
Member

BurntSushi commented Aug 29, 2024

Actually one possibly silly thought, should we make the short form just be a UTC timestamp?

This is what it was originally, but I changed it. It's generally bad juju to just assume UTC for an unadorned date. I think we either don't support an unadorned date or we assume it's in the user's local time zone. But in this case, "user's local time zone" creates a configuration that isn't self-contained.

In terms of the time for a date without a time, it's common practice to interpret it as the first instant on that date (which, interestingly, may not be midnight).

It's probably best to just required an RFC 3339 timestamp here. 2024-08-28 verus 2024-08-28T00:00:00Z isn't too onerous for persistent configuration I think. On the CLI, it's nice to support 2024-08-28 since it's easier to type, and in that context, it's perhaps more justifiable to assume the user's system time zone (and which can even be overridden by setting the TZ environment variable).

@hauntsaninja hauntsaninja deleted the exclude-nwer branch August 30, 2024 03:16
@hauntsaninja
Copy link
Contributor Author

Sounds good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

An exclude newer extension for PEP 723
3 participants