Add support for tool.uv into distribution building (#3904)

With the change, we remove the special casing of workspace dependencies
and resolve `tool.uv` for all git and directory distributions. This
gives us support for non-editable workspace dependencies and path
dependencies in other workspaces. It removes a lot of special casing
around workspaces. These changes are the groundwork for supporting
`tool.uv` with dynamic metadata.

The basis for this change is moving `Requirement` from
`distribution-types` to `pypi-types` and the lowering logic from
`uv-requirements` to `uv-distribution`. This changes should be split out
in separate PRs.

I've included an example workspace `albatross-root-workspace2` where
`bird-feeder` depends on `a` from another workspace `ab`. There's a
bunch of failing tests and regressed error messages that still need
fixing. It does fix the audited package count for the workspace tests.
This commit is contained in:
konsti 2024-05-31 04:42:03 +02:00 committed by GitHub
parent 09f55482a0
commit 081f20c53e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
69 changed files with 1159 additions and 1680 deletions

View file

@ -11,12 +11,13 @@ use itertools::Itertools;
use rustc_hash::FxHashMap;
use tracing::{debug, instrument};
use distribution_types::{CachedDist, IndexLocations, Name, Requirement, Resolution, SourceDist};
use distribution_types::{CachedDist, IndexLocations, Name, Resolution, SourceDist};
use pypi_types::Requirement;
use uv_build::{SourceBuild, SourceBuildContext};
use uv_cache::Cache;
use uv_client::RegistryClient;
use uv_configuration::Concurrency;
use uv_configuration::{BuildKind, ConfigSettings, NoBinary, NoBuild, Reinstall, SetupPyStrategy};
use uv_configuration::{Concurrency, PreviewMode};
use uv_distribution::DistributionDatabase;
use uv_installer::{Downloader, Installer, Plan, Planner, SitePackages};
use uv_interpreter::{Interpreter, PythonEnvironment};
@ -43,6 +44,7 @@ pub struct BuildDispatch<'a> {
options: Options,
build_extra_env_vars: FxHashMap<OsString, OsString>,
concurrency: Concurrency,
preview_mode: PreviewMode,
}
impl<'a> BuildDispatch<'a> {
@ -62,6 +64,7 @@ impl<'a> BuildDispatch<'a> {
no_build: &'a NoBuild,
no_binary: &'a NoBinary,
concurrency: Concurrency,
preview_mode: PreviewMode,
) -> Self {
Self {
client,
@ -81,6 +84,7 @@ impl<'a> BuildDispatch<'a> {
source_build_context: SourceBuildContext::default(),
options: Options::default(),
build_extra_env_vars: FxHashMap::default(),
preview_mode,
}
}
@ -138,7 +142,12 @@ impl<'a> BuildContext for BuildDispatch<'a> {
&HashStrategy::None,
self,
EmptyInstalledPackages,
DistributionDatabase::new(self.client, self, self.concurrency.downloads),
DistributionDatabase::new(
self.client,
self,
self.concurrency.downloads,
self.preview_mode,
),
)?;
let graph = resolver.resolve().await.with_context(|| {
format!(
@ -220,7 +229,12 @@ impl<'a> BuildContext for BuildDispatch<'a> {
self.cache,
tags,
&HashStrategy::None,
DistributionDatabase::new(self.client, self, self.concurrency.downloads),
DistributionDatabase::new(
self.client,
self,
self.concurrency.downloads,
self.preview_mode,
),
);
debug!(