mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
![]() ## Summary This PR enables the source distribution database to be used with unnamed requirements (i.e., URLs without a package name). The (significant) upside here is that we can now use PEP 517 hooks to resolve unnamed requirement metadata _and_ reuse any computation in the cache. The changes to `crates/uv-distribution/src/source/mod.rs` are quite extensive, but mostly mechanical. The core idea is that we introduce a new `BuildableSource` abstraction, which can either be a distribution, or an unnamed URL: ```rust /// A reference to a source that can be built into a built distribution. /// /// This can either be a distribution (e.g., a package on a registry) or a direct URL. /// /// Distributions can _also_ point to URLs in lieu of a registry; however, the primary distinction /// here is that a distribution will always include a package name, while a URL will not. #[derive(Debug, Clone, Copy)] pub enum BuildableSource<'a> { Dist(&'a SourceDist), Url(SourceUrl<'a>), } ``` All the methods on the source distribution database now accept `BuildableSource`. `BuildableSource` has a `name()` method, but it returns `Option<&PackageName>`, and everything is required to work with and without a package name. The main drawback of this approach (which isn't a terrible one) is that we can no longer include the package name in the cache. (We do continue to use the package name for registry-based distributions, since those always have a name.). The package name was included in the cache route for two reasons: (1) it's nice for debugging; and (2) we use it to power `uv cache clean flask`, to identify the entries that are relevant for Flask. To solve this, I changed the `uv cache clean` code to look one level deeper. So, when we want to determine whether to remove the cache entry for a given URL, we now look into the directory to see if there are any wheels that match the package name. This isn't as nice, but it does work (and we have test coverage for it -- all passing). I also considered removing the package name from the cache routes for non-registry _wheels_, for consistency... But, it would require a cache bump, and it didn't feel important enough to merit that. |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |