mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 02:48:17 +00:00
Add support for --no-build-isolation
(#2258)
## Summary This PR adds support for pip's `--no-build-isolation`. When enabled, build requirements won't be installed during PEP 517-style builds, but the source environment _will_ be used when executing the build steps themselves. Closes https://github.com/astral-sh/uv/issues/1715.
This commit is contained in:
parent
d249574a47
commit
5ae5980c88
19 changed files with 244 additions and 64 deletions
|
@ -20,7 +20,9 @@ use uv_client::{FlatIndex, RegistryClient};
|
|||
use uv_installer::{Downloader, Installer, NoBinary, Plan, Planner, Reinstall, SitePackages};
|
||||
use uv_interpreter::{Interpreter, PythonEnvironment};
|
||||
use uv_resolver::{InMemoryIndex, Manifest, Options, Resolver};
|
||||
use uv_traits::{BuildContext, BuildKind, ConfigSettings, InFlight, NoBuild, SetupPyStrategy};
|
||||
use uv_traits::{
|
||||
BuildContext, BuildIsolation, BuildKind, ConfigSettings, InFlight, NoBuild, SetupPyStrategy,
|
||||
};
|
||||
|
||||
/// The main implementation of [`BuildContext`], used by the CLI, see [`BuildContext`]
|
||||
/// documentation.
|
||||
|
@ -33,6 +35,7 @@ pub struct BuildDispatch<'a> {
|
|||
index: &'a InMemoryIndex,
|
||||
in_flight: &'a InFlight,
|
||||
setup_py: SetupPyStrategy,
|
||||
build_isolation: BuildIsolation<'a>,
|
||||
no_build: &'a NoBuild,
|
||||
no_binary: &'a NoBinary,
|
||||
config_settings: &'a ConfigSettings,
|
||||
|
@ -53,6 +56,7 @@ impl<'a> BuildDispatch<'a> {
|
|||
in_flight: &'a InFlight,
|
||||
setup_py: SetupPyStrategy,
|
||||
config_settings: &'a ConfigSettings,
|
||||
build_isolation: BuildIsolation<'a>,
|
||||
no_build: &'a NoBuild,
|
||||
no_binary: &'a NoBinary,
|
||||
) -> Self {
|
||||
|
@ -66,6 +70,7 @@ impl<'a> BuildDispatch<'a> {
|
|||
in_flight,
|
||||
setup_py,
|
||||
config_settings,
|
||||
build_isolation,
|
||||
no_build,
|
||||
no_binary,
|
||||
source_build_context: SourceBuildContext::default(),
|
||||
|
@ -107,6 +112,10 @@ impl<'a> BuildContext for BuildDispatch<'a> {
|
|||
self.interpreter
|
||||
}
|
||||
|
||||
fn build_isolation(&self) -> BuildIsolation {
|
||||
self.build_isolation
|
||||
}
|
||||
|
||||
fn no_build(&self) -> &NoBuild {
|
||||
self.no_build
|
||||
}
|
||||
|
@ -180,7 +189,7 @@ impl<'a> BuildContext for BuildDispatch<'a> {
|
|||
local,
|
||||
remote,
|
||||
reinstalls,
|
||||
extraneous,
|
||||
extraneous: _,
|
||||
} = Planner::with_requirements(&resolution.requirements()).build(
|
||||
site_packages,
|
||||
&Reinstall::None,
|
||||
|
@ -191,6 +200,12 @@ impl<'a> BuildContext for BuildDispatch<'a> {
|
|||
tags,
|
||||
)?;
|
||||
|
||||
// Nothing to do.
|
||||
if remote.is_empty() && local.is_empty() && reinstalls.is_empty() {
|
||||
debug!("No build requirements to install for build");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Resolve any registry-based requirements.
|
||||
let remote = remote
|
||||
.iter()
|
||||
|
@ -207,7 +222,7 @@ impl<'a> BuildContext for BuildDispatch<'a> {
|
|||
vec![]
|
||||
} else {
|
||||
// TODO(konstin): Check that there is no endless recursion.
|
||||
let downloader = Downloader::new(self.cache(), tags, self.client, self);
|
||||
let downloader = Downloader::new(self.cache, tags, self.client, self);
|
||||
debug!(
|
||||
"Downloading and building requirement{} for build: {}",
|
||||
if remote.len() == 1 { "" } else { "s" },
|
||||
|
@ -221,8 +236,8 @@ impl<'a> BuildContext for BuildDispatch<'a> {
|
|||
};
|
||||
|
||||
// Remove any unnecessary packages.
|
||||
if !extraneous.is_empty() || !reinstalls.is_empty() {
|
||||
for dist_info in extraneous.iter().chain(reinstalls.iter()) {
|
||||
if !reinstalls.is_empty() {
|
||||
for dist_info in &reinstalls {
|
||||
let summary = uv_installer::uninstall(dist_info)
|
||||
.await
|
||||
.context("Failed to uninstall build dependencies")?;
|
||||
|
@ -295,6 +310,7 @@ impl<'a> BuildContext for BuildDispatch<'a> {
|
|||
package_id.to_string(),
|
||||
self.setup_py,
|
||||
self.config_settings.clone(),
|
||||
self.build_isolation,
|
||||
build_kind,
|
||||
self.build_extra_env_vars.clone(),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue