pub trait BuildContext {
type SourceDistBuilder: SourceBuildTrait;
Show 19 methods
// Required methods
fn interpreter(&self) -> impl Future<Output = &Interpreter> + '_;
fn cache(&self) -> &Cache;
fn git(&self) -> &GitResolver;
fn build_arena(&self) -> &BuildArena<Self::SourceDistBuilder>;
fn capabilities(&self) -> &IndexCapabilities;
fn dependency_metadata(&self) -> &DependencyMetadata;
fn build_options(&self) -> &BuildOptions;
fn build_isolation(&self) -> BuildIsolation<'_>;
fn config_settings(&self) -> &ConfigSettings;
fn config_settings_package(&self) -> &PackageConfigSettings;
fn sources(&self) -> SourceStrategy;
fn locations(&self) -> &IndexLocations;
fn workspace_cache(&self) -> &WorkspaceCache;
fn extra_build_requires(&self) -> &ExtraBuildRequires;
fn extra_build_variables(&self) -> &ExtraBuildVariables;
fn resolve<'a>(
&'a self,
requirements: &'a [Requirement],
build_stack: &'a BuildStack,
) -> impl Future<Output = Result<Resolution, impl IsBuildBackendError>> + 'a;
fn install<'a>(
&'a self,
resolution: &'a Resolution,
venv: &'a PythonEnvironment,
build_stack: &'a BuildStack,
) -> impl Future<Output = Result<Vec<CachedDist>, impl IsBuildBackendError>> + 'a;
fn setup_build<'a>(
&'a self,
source: &'a Path,
subdirectory: Option<&'a Path>,
install_path: &'a Path,
version_id: Option<&'a str>,
dist: Option<&'a SourceDist>,
sources: SourceStrategy,
build_kind: BuildKind,
build_output: BuildOutput,
build_stack: BuildStack,
) -> impl Future<Output = Result<Self::SourceDistBuilder, impl IsBuildBackendError>> + 'a;
fn direct_build<'a>(
&'a self,
source: &'a Path,
subdirectory: Option<&'a Path>,
output_dir: &'a Path,
sources: SourceStrategy,
build_kind: BuildKind,
version_id: Option<&'a str>,
) -> impl Future<Output = Result<Option<DistFilename>, impl IsBuildBackendError>> + 'a;
}Expand description
Avoids cyclic crate dependencies between resolver, installer and builder.
To resolve the dependencies of a packages, we may need to build one or more source
distributions. To building a source distribution, we need to create a virtual environment from
the same base python as we use for the root resolution, resolve the build requirements
(potentially which nested source distributions, recursing a level deeper), installing
them and then build. The installer, the resolver and the source distribution builder are each in
their own crate. To avoid circular crate dependencies, this type dispatches between the three
crates with its three main methods (BuildContext::resolve, BuildContext::install and
BuildContext::setup_build).
The overall main crate structure looks like this:
┌────────────────┐
│ uv │
└───────▲────────┘
│
│
┌───────┴────────┐
┌─────────►│ uv-dispatch │◄─────────┐
│ └───────▲────────┘ │
│ │ │
│ │ │
┌───────┴────────┐ ┌───────┴────────┐ ┌────────┴────────────────┐
│ uv-resolver │ │ uv-installer │ │ uv-build-frontend │
└───────▲────────┘ └───────▲────────┘ └────────▲────────────────┘
│ │ │
└─────────────┐ │ ┌──────────────┘
┌──┴────┴────┴───┐
│ uv-types │
└────────────────┘Put in a different way, the types here allow uv-resolver to depend on uv-build and
uv-build-frontend to depend on uv-resolver without having actual crate dependencies between
them.
Required Associated Types§
Required Methods§
Sourcefn interpreter(&self) -> impl Future<Output = &Interpreter> + '_
fn interpreter(&self) -> impl Future<Output = &Interpreter> + '_
Return a reference to the interpreter.
Sourcefn git(&self) -> &GitResolver
fn git(&self) -> &GitResolver
Return a reference to the Git resolver.
Sourcefn build_arena(&self) -> &BuildArena<Self::SourceDistBuilder>
fn build_arena(&self) -> &BuildArena<Self::SourceDistBuilder>
Return a reference to the build arena.
Sourcefn capabilities(&self) -> &IndexCapabilities
fn capabilities(&self) -> &IndexCapabilities
Return a reference to the discovered registry capabilities.
Sourcefn dependency_metadata(&self) -> &DependencyMetadata
fn dependency_metadata(&self) -> &DependencyMetadata
Return a reference to any pre-defined static metadata.
Sourcefn build_options(&self) -> &BuildOptions
fn build_options(&self) -> &BuildOptions
Whether source distribution building or pre-built wheels is disabled.
This BuildContext::setup_build calls will fail if builds are disabled.
This method exists to avoid fetching source distributions if we know we can’t build them.
Sourcefn build_isolation(&self) -> BuildIsolation<'_>
fn build_isolation(&self) -> BuildIsolation<'_>
The isolation mode used for building source distributions.
Sourcefn config_settings(&self) -> &ConfigSettings
fn config_settings(&self) -> &ConfigSettings
The ConfigSettings used to build distributions.
Sourcefn config_settings_package(&self) -> &PackageConfigSettings
fn config_settings_package(&self) -> &PackageConfigSettings
The ConfigSettings used to build a specific package.
Sourcefn sources(&self) -> SourceStrategy
fn sources(&self) -> SourceStrategy
Whether to incorporate tool.uv.sources when resolving requirements.
Sourcefn locations(&self) -> &IndexLocations
fn locations(&self) -> &IndexLocations
The index locations being searched.
Sourcefn workspace_cache(&self) -> &WorkspaceCache
fn workspace_cache(&self) -> &WorkspaceCache
Workspace discovery caching.
Sourcefn extra_build_requires(&self) -> &ExtraBuildRequires
fn extra_build_requires(&self) -> &ExtraBuildRequires
Get the extra build requirements.
Sourcefn extra_build_variables(&self) -> &ExtraBuildVariables
fn extra_build_variables(&self) -> &ExtraBuildVariables
Get the extra build variables.
Sourcefn resolve<'a>(
&'a self,
requirements: &'a [Requirement],
build_stack: &'a BuildStack,
) -> impl Future<Output = Result<Resolution, impl IsBuildBackendError>> + 'a
fn resolve<'a>( &'a self, requirements: &'a [Requirement], build_stack: &'a BuildStack, ) -> impl Future<Output = Result<Resolution, impl IsBuildBackendError>> + 'a
Resolve the given requirements into a ready-to-install set of package versions.
Sourcefn install<'a>(
&'a self,
resolution: &'a Resolution,
venv: &'a PythonEnvironment,
build_stack: &'a BuildStack,
) -> impl Future<Output = Result<Vec<CachedDist>, impl IsBuildBackendError>> + 'a
fn install<'a>( &'a self, resolution: &'a Resolution, venv: &'a PythonEnvironment, build_stack: &'a BuildStack, ) -> impl Future<Output = Result<Vec<CachedDist>, impl IsBuildBackendError>> + 'a
Install the given set of package versions into the virtual environment. The environment must
use the same base Python as BuildContext::interpreter
Sourcefn setup_build<'a>(
&'a self,
source: &'a Path,
subdirectory: Option<&'a Path>,
install_path: &'a Path,
version_id: Option<&'a str>,
dist: Option<&'a SourceDist>,
sources: SourceStrategy,
build_kind: BuildKind,
build_output: BuildOutput,
build_stack: BuildStack,
) -> impl Future<Output = Result<Self::SourceDistBuilder, impl IsBuildBackendError>> + 'a
fn setup_build<'a>( &'a self, source: &'a Path, subdirectory: Option<&'a Path>, install_path: &'a Path, version_id: Option<&'a str>, dist: Option<&'a SourceDist>, sources: SourceStrategy, build_kind: BuildKind, build_output: BuildOutput, build_stack: BuildStack, ) -> impl Future<Output = Result<Self::SourceDistBuilder, impl IsBuildBackendError>> + 'a
Set up a source distribution build by installing the required dependencies. A wrapper for
uv_build::SourceBuild::setup.
For PEP 517 builds, this calls get_requires_for_build_wheel.
version_id is for error reporting only.
dist is for safety checks and may be null for editable builds.
Sourcefn direct_build<'a>(
&'a self,
source: &'a Path,
subdirectory: Option<&'a Path>,
output_dir: &'a Path,
sources: SourceStrategy,
build_kind: BuildKind,
version_id: Option<&'a str>,
) -> impl Future<Output = Result<Option<DistFilename>, impl IsBuildBackendError>> + 'a
fn direct_build<'a>( &'a self, source: &'a Path, subdirectory: Option<&'a Path>, output_dir: &'a Path, sources: SourceStrategy, build_kind: BuildKind, version_id: Option<&'a str>, ) -> impl Future<Output = Result<Option<DistFilename>, impl IsBuildBackendError>> + 'a
Build by calling directly into the uv build backend without PEP 517, if possible.
Checks if the source tree uses uv as build backend. If not, it returns Ok(None), otherwise
it builds and returns the name of the built file.
version_id is for error reporting only.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.