Respect PEP 723 script lockfiles in uv run (#10136)

## Summary

If a script has a lockfile, then `uv run` will now reuse it.

Closes https://github.com/astral-sh/uv/issues/7483.

Closes https://github.com/astral-sh/uv/issues/9688.
This commit is contained in:
Charlie Marsh 2025-01-08 15:34:45 -05:00 committed by GitHub
parent 391ab757b8
commit e22b728e3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 658 additions and 267 deletions

View file

@ -54,6 +54,14 @@ impl Pep723Item {
Self::Remote(_) => None,
}
}
/// Return the PEP 723 script, if any.
pub fn as_script(&self) -> Option<&Pep723Script> {
match self {
Self::Script(script) => Some(script),
_ => None,
}
}
}
/// A reference to a PEP 723 item.
@ -234,6 +242,18 @@ impl Pep723Script {
Ok(())
}
/// Return the [`Sources`] defined in the PEP 723 metadata.
pub fn sources(&self) -> &BTreeMap<PackageName, Sources> {
static EMPTY: BTreeMap<PackageName, Sources> = BTreeMap::new();
self.metadata
.tool
.as_ref()
.and_then(|tool| tool.uv.as_ref())
.and_then(|uv| uv.sources.as_ref())
.unwrap_or(&EMPTY)
}
}
/// PEP 723 metadata as parsed from a `script` comment block.