Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --no-build-isolation to uv lock et al #5829

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 63 additions & 44 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,20 +680,6 @@ pub struct PipCompileArgs {
#[arg(long, overrides_with("legacy_setup_py"), hide = true)]
pub no_legacy_setup_py: bool,

/// Disable isolation when building source distributions.
///
/// Assumes that build dependencies specified by PEP 518 are already installed.
#[arg(
long,
env = "UV_NO_BUILD_ISOLATION",
value_parser = clap::builder::BoolishValueParser::new(),
overrides_with("build_isolation")
)]
pub no_build_isolation: bool,

#[arg(long, overrides_with("no_build_isolation"), hide = true)]
pub build_isolation: bool,

/// Don't build source distributions.
///
/// When enabled, resolving will not run arbitrary Python code. The cached wheels of
Expand Down Expand Up @@ -981,20 +967,6 @@ pub struct PipSyncArgs {
#[arg(long, overrides_with("legacy_setup_py"), hide = true)]
pub no_legacy_setup_py: bool,

/// Disable isolation when building source distributions.
///
/// Assumes that build dependencies specified by PEP 518 are already installed.
#[arg(
long,
env = "UV_NO_BUILD_ISOLATION",
value_parser = clap::builder::BoolishValueParser::new(),
overrides_with("build_isolation")
)]
pub no_build_isolation: bool,

#[arg(long, overrides_with("no_build_isolation"), hide = true)]
pub build_isolation: bool,

/// Don't build source distributions.
///
/// When enabled, resolving will not run arbitrary Python code. The cached wheels of
Expand Down Expand Up @@ -1286,20 +1258,6 @@ pub struct PipInstallArgs {
#[arg(long, overrides_with("legacy_setup_py"), hide = true)]
pub no_legacy_setup_py: bool,

/// Disable isolation when building source distributions.
///
/// Assumes that build dependencies specified by PEP 518 are already installed.
#[arg(
long,
env = "UV_NO_BUILD_ISOLATION",
value_parser = clap::builder::BoolishValueParser::new(),
overrides_with("build_isolation")
)]
pub no_build_isolation: bool,

#[arg(long, overrides_with("no_build_isolation"), hide = true)]
pub build_isolation: bool,

/// Don't build source distributions.
///
/// When enabled, resolving will not run arbitrary Python code. The cached wheels of
Expand Down Expand Up @@ -2103,9 +2061,10 @@ pub struct SyncArgs {
#[arg(long, overrides_with("dev"))]
pub no_dev: bool,

/// Does not clean the environment.
/// When syncing, make the minimum necessary changes to satisfy the requirements.
///
/// When omitted, any extraneous installations will be removed.
/// By default, `uv sync` will remove any extraneous packages from the environment, unless
/// `--no-build-isolation` is enabled.
#[arg(long)]
pub no_clean: bool,

Expand Down Expand Up @@ -2874,6 +2833,26 @@ pub struct InstallerArgs {
)]
pub config_setting: Option<Vec<ConfigSettingEntry>>,

/// Disable isolation when building source distributions.
///
/// Assumes that build dependencies specified by PEP 518 are already installed.
#[arg(
long,
overrides_with("build_isolation"),
help_heading = "Build options",
env = "UV_NO_BUILD_ISOLATION",
value_parser = clap::builder::BoolishValueParser::new(),
)]
pub no_build_isolation: bool,

#[arg(
long,
overrides_with("no_build_isolation"),
hide = true,
help_heading = "Build options"
)]
pub build_isolation: bool,

/// Limit candidate packages to those that were uploaded prior to the given date.
///
/// Accepts both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and UTC dates in the same
Expand Down Expand Up @@ -3021,6 +3000,26 @@ pub struct ResolverArgs {
)]
pub config_setting: Option<Vec<ConfigSettingEntry>>,

/// Disable isolation when building source distributions.
///
/// Assumes that build dependencies specified by PEP 518 are already installed.
#[arg(
long,
overrides_with("build_isolation"),
help_heading = "Build options",
env = "UV_NO_BUILD_ISOLATION",
value_parser = clap::builder::BoolishValueParser::new(),
)]
pub no_build_isolation: bool,

#[arg(
long,
overrides_with("no_build_isolation"),
hide = true,
help_heading = "Build options"
)]
pub build_isolation: bool,

/// Limit candidate packages to those that were uploaded prior to the given date.
///
/// Accepts both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and UTC dates in the same
Expand Down Expand Up @@ -3166,6 +3165,26 @@ pub struct ResolverInstallerArgs {
)]
pub config_setting: Option<Vec<ConfigSettingEntry>>,

/// Disable isolation when building source distributions.
///
/// Assumes that build dependencies specified by PEP 518 are already installed.
#[arg(
long,
overrides_with("build_isolation"),
help_heading = "Build options",
env = "UV_NO_BUILD_ISOLATION",
value_parser = clap::builder::BoolishValueParser::new(),
)]
pub no_build_isolation: bool,

#[arg(
long,
overrides_with("no_build_isolation"),
hide = true,
help_heading = "Build options"
)]
pub build_isolation: bool,

/// Limit candidate packages to those that were uploaded prior to the given date.
///
/// Accepts both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and UTC dates in the same
Expand Down
15 changes: 15 additions & 0 deletions crates/uv-cli/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ impl From<ResolverArgs> for PipOptions {
prerelease,
pre,
config_setting,
no_build_isolation,
build_isolation,
exclude_newer,
link_mode,
no_sources,
Expand All @@ -60,6 +62,7 @@ impl From<ResolverArgs> for PipOptions {
},
config_settings: config_setting
.map(|config_settings| config_settings.into_iter().collect::<ConfigSettings>()),
no_build_isolation: flag(no_build_isolation, build_isolation),
exclude_newer,
link_mode,
no_sources: if no_sources { Some(true) } else { None },
Expand All @@ -78,6 +81,8 @@ impl From<InstallerArgs> for PipOptions {
index_strategy,
keyring_provider,
config_setting,
no_build_isolation,
build_isolation,
exclude_newer,
link_mode,
compile_bytecode,
Expand All @@ -92,6 +97,7 @@ impl From<InstallerArgs> for PipOptions {
keyring_provider,
config_settings: config_setting
.map(|config_settings| config_settings.into_iter().collect::<ConfigSettings>()),
no_build_isolation: flag(no_build_isolation, build_isolation),
exclude_newer,
link_mode,
compile_bytecode: flag(compile_bytecode, no_compile_bytecode),
Expand All @@ -117,6 +123,8 @@ impl From<ResolverInstallerArgs> for PipOptions {
prerelease,
pre,
config_setting,
no_build_isolation,
build_isolation,
exclude_newer,
link_mode,
compile_bytecode,
Expand All @@ -139,6 +147,7 @@ impl From<ResolverInstallerArgs> for PipOptions {
},
config_settings: config_setting
.map(|config_settings| config_settings.into_iter().collect::<ConfigSettings>()),
no_build_isolation: flag(no_build_isolation, build_isolation),
exclude_newer,
link_mode,
compile_bytecode: flag(compile_bytecode, no_compile_bytecode),
Expand Down Expand Up @@ -185,6 +194,8 @@ pub fn resolver_options(resolver_args: ResolverArgs, build_args: BuildArgs) -> R
prerelease,
pre,
config_setting,
no_build_isolation,
build_isolation,
exclude_newer,
link_mode,
no_sources,
Expand Down Expand Up @@ -225,6 +236,7 @@ pub fn resolver_options(resolver_args: ResolverArgs, build_args: BuildArgs) -> R
},
config_settings: config_setting
.map(|config_settings| config_settings.into_iter().collect::<ConfigSettings>()),
no_build_isolation: flag(no_build_isolation, build_isolation),
exclude_newer,
link_mode,
no_build: flag(no_build, build),
Expand Down Expand Up @@ -254,6 +266,8 @@ pub fn resolver_installer_options(
prerelease,
pre,
config_setting,
no_build_isolation,
build_isolation,
exclude_newer,
link_mode,
compile_bytecode,
Expand Down Expand Up @@ -298,6 +312,7 @@ pub fn resolver_installer_options(
},
config_settings: config_setting
.map(|config_settings| config_settings.into_iter().collect::<ConfigSettings>()),
no_build_isolation: flag(no_build_isolation, build_isolation),
exclude_newer,
link_mode,
compile_bytecode: flag(compile_bytecode, no_compile_bytecode),
Expand Down
15 changes: 15 additions & 0 deletions crates/uv-settings/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ pub struct InstallerOptions {
pub no_build_package: Option<Vec<PackageName>>,
pub no_binary: Option<bool>,
pub no_binary_package: Option<Vec<PackageName>>,
pub no_build_isolation: Option<bool>,
pub no_sources: Option<bool>,
}

/// Settings relevant to all resolver operations.
Expand All @@ -184,6 +186,7 @@ pub struct ResolverOptions {
pub no_build_package: Option<Vec<PackageName>>,
pub no_binary: Option<bool>,
pub no_binary_package: Option<Vec<PackageName>>,
pub no_build_isolation: Option<bool>,
pub no_sources: Option<bool>,
}

Expand Down Expand Up @@ -317,6 +320,18 @@ pub struct ResolverInstallerOptions {
"#
)]
pub config_settings: Option<ConfigSettings>,
/// Disable isolation when building source distributions.
///
/// Assumes that build dependencies specified by [PEP 518](https://peps.python.org/pep-0518/)
/// are already installed.
#[option(
default = "false",
value_type = "bool",
example = r#"
no-build-isolation = true
"#
)]
pub no_build_isolation: Option<bool>,
/// Limit candidate packages to those that were uploaded prior to the given date.
///
/// Accepts both [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339.html) timestamps (e.g.,
Expand Down
18 changes: 12 additions & 6 deletions crates/uv/src/commands/project/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use uv_dispatch::BuildDispatch;
use uv_fs::CWD;
use uv_git::ResolvedRepositoryReference;
use uv_normalize::{PackageName, DEV_DEPENDENCIES};
use uv_python::{Interpreter, PythonFetch, PythonPreference, PythonRequest};
use uv_python::{Interpreter, PythonEnvironment, PythonFetch, PythonPreference, PythonRequest};
use uv_requirements::upgrade::{read_lock_requirements, LockedRequirements};
use uv_resolver::{
FlatIndex, Lock, OptionsBuilder, PythonRequirement, RequiresPython, ResolverMarkers,
Expand Down Expand Up @@ -219,6 +219,7 @@ async fn do_lock(
resolution,
prerelease,
config_setting,
no_build_isolation,
exclude_newer,
link_mode,
upgrade,
Expand Down Expand Up @@ -277,6 +278,15 @@ async fn do_lock(
.platform(interpreter.platform())
.build();

// Determine whether to enable build isolation.
let environment;
let build_isolation = if no_build_isolation {
environment = PythonEnvironment::from_interpreter(interpreter.clone());
BuildIsolation::Shared(&environment)
} else {
BuildIsolation::Isolated
};

let options = OptionsBuilder::new()
.resolution_mode(resolution)
.prerelease_mode(prerelease)
Expand All @@ -287,7 +297,7 @@ async fn do_lock(

// TODO(charlie): These are all default values. We should consider whether we want to make them
// optional on the downstream APIs.
let build_isolation = BuildIsolation::default();
let build_constraints = [];
let extras = ExtrasSpecification::default();
let setup_py = SetupPyStrategy::default();

Expand Down Expand Up @@ -404,8 +414,6 @@ async fn do_lock(
// Prefill the index with the lockfile metadata.
let index = lock.to_index(workspace.install_path(), upgrade)?;

// TODO: read locked build constraints
let build_constraints = [];
// Create a build dispatch.
let build_dispatch = BuildDispatch::new(
&client,
Expand Down Expand Up @@ -484,8 +492,6 @@ async fn do_lock(
None => {
debug!("Starting clean resolution");

// TODO: read locked build constraints
let build_constraints = [];
// Create a build dispatch.
let build_dispatch = BuildDispatch::new(
&client,
Expand Down
Loading
Loading