Skip to content
Draft
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
47 changes: 37 additions & 10 deletions crates/uv/src/commands/build_frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use uv_distribution_filename::{
DistFilename, SourceDistExtension, SourceDistFilename, WheelFilename,
};
use uv_distribution_types::{
ConfigSettings, DependencyMetadata, ExtraBuildVariables, Index, IndexLocations,
PackageConfigSettings, RequiresPython, SourceDist,
ConfigSettings, DependencyMetadata, ExtraBuildRequires, ExtraBuildVariables, Index,
IndexLocations, PackageConfigSettings, RequiresPython, SourceDist,
};
use uv_fs::{Simplified, relative_to};
use uv_install_wheel::LinkMode;
Expand All @@ -40,7 +40,6 @@ use uv_requirements::RequirementsSource;
use uv_resolver::{ExcludeNewer, FlatIndex};
use uv_settings::PythonInstallMirrors;
use uv_types::{AnyErrorBuild, BuildContext, BuildStack, HashStrategy};
use uv_workspace::pyproject::ExtraBuildDependencies;
use uv_workspace::{DiscoveryOptions, Workspace, WorkspaceCache, WorkspaceError};

use crate::commands::ExitStatus;
Expand Down Expand Up @@ -251,6 +250,38 @@ async fn build_impl(
)
.await;

// Discover the settings workspace (from the project directory) for lowering extra build
// dependencies. This may differ from the source workspace when building a subdirectory
// (e.g., `uv build child`).
let settings_workspace = if src.directory() == project_dir {
workspace.as_ref().ok()
} else {
None
};
let settings_workspace_owned;
let settings_workspace = if let Some(workspace) = settings_workspace {
Some(workspace)
} else {
settings_workspace_owned =
Workspace::discover(project_dir, &DiscoveryOptions::default(), &workspace_cache).await;
settings_workspace_owned.as_ref().ok()
};

// Lower the extra build dependencies with source resolution.
let extra_build_requires = if let Some(workspace) = settings_workspace {
LoweredExtraBuildDependencies::from_workspace(
extra_build_dependencies.clone(),
workspace,
index_locations,
sources,
client_builder.credentials_cache(),
)
.map_err(ProjectError::from)?
} else {
LoweredExtraBuildDependencies::from_non_lowered(extra_build_dependencies.clone())
}
.into_inner();

// If a `--package` or `--all-packages` was provided, adjust the source directory.
let packages = if let Some(package) = package {
if matches!(src, Source::File(_)) {
Expand Down Expand Up @@ -354,7 +385,7 @@ async fn build_impl(
clear,
build_constraints,
build_isolation,
extra_build_dependencies,
&extra_build_requires,
extra_build_variables,
*index_strategy,
*keyring_provider,
Expand Down Expand Up @@ -463,7 +494,7 @@ async fn build_package(
clear: bool,
build_constraints: &[RequirementsSource],
build_isolation: &BuildIsolation,
extra_build_dependencies: &ExtraBuildDependencies,
extra_build_requires: &ExtraBuildRequires,
extra_build_variables: &ExtraBuildVariables,
index_strategy: IndexStrategy,
keyring_provider: KeyringProviderType,
Expand Down Expand Up @@ -604,10 +635,6 @@ async fn build_package(
let state = SharedState::default();
let workspace_cache = WorkspaceCache::default();

let extra_build_requires =
LoweredExtraBuildDependencies::from_non_lowered(extra_build_dependencies.clone())
.into_inner();

// Create a build dispatch.
let build_dispatch = BuildDispatch::new(
&client,
Expand All @@ -622,7 +649,7 @@ async fn build_package(
config_setting,
config_settings_package,
types_build_isolation,
&extra_build_requires,
extra_build_requires,
extra_build_variables,
link_mode,
build_options,
Expand Down
4 changes: 4 additions & 0 deletions crates/uv/src/commands/project/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use uv_distribution_types::{Name, Resolution};
use uv_fs::PythonExt;
use uv_preview::Preview;
use uv_python::{Interpreter, PythonEnvironment, canonicalize_executable};
use uv_workspace::Workspace;

/// An ephemeral [`PythonEnvironment`] for running an individual command.
#[derive(Debug)]
Expand Down Expand Up @@ -114,6 +115,7 @@ impl CachedEnvironment {
interpreter: &Interpreter,
python_platform: Option<&TargetTriple>,
settings: &ResolverInstallerSettings,
workspace: Option<&Workspace>,
client_builder: &BaseClientBuilder<'_>,
state: &PlatformState,
resolve: Box<dyn ResolveLogger>,
Expand All @@ -134,6 +136,7 @@ impl CachedEnvironment {
python_platform,
build_constraints.clone(),
&settings.resolver,
workspace,
client_builder,
state,
resolve,
Expand Down Expand Up @@ -199,6 +202,7 @@ impl CachedEnvironment {
Modifications::Exact,
build_constraints,
settings.into(),
workspace,
client_builder,
state,
install,
Expand Down
61 changes: 46 additions & 15 deletions crates/uv/src/commands/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,7 @@ pub(crate) async fn resolve_names(
requirements: Vec<UnresolvedRequirementSpecification>,
interpreter: &Interpreter,
settings: &ResolverInstallerSettings,
workspace: Option<&Workspace>,
client_builder: &BaseClientBuilder<'_>,
state: &SharedState,
concurrency: Concurrency,
Expand Down Expand Up @@ -1798,6 +1799,21 @@ pub(crate) async fn resolve_names(

let client_builder = client_builder.clone().keyring(*keyring_provider);

// Lower the extra build dependencies, if any.
let extra_build_requires = if let Some(workspace) = workspace {
LoweredExtraBuildDependencies::from_workspace(
extra_build_dependencies.clone(),
workspace,
index_locations,
sources,
client_builder.credentials_cache(),
)
.map_err(uv_distribution::Error::from)?
} else {
LoweredExtraBuildDependencies::from_non_lowered(extra_build_dependencies.clone())
}
.into_inner();

// Determine the PyTorch backend.
let torch_backend = torch_backend
.map(|mode| {
Expand Down Expand Up @@ -1844,11 +1860,6 @@ pub(crate) async fn resolve_names(
let build_constraints = Constraints::default();
let build_hasher = HashStrategy::default();

// Lower the extra build dependencies, if any.
let extra_build_requires =
LoweredExtraBuildDependencies::from_non_lowered(extra_build_dependencies.clone())
.into_inner();

// Create a build dispatch.
let build_dispatch = BuildDispatch::new(
&client,
Expand Down Expand Up @@ -1936,6 +1947,7 @@ pub(crate) async fn resolve_environment(
python_platform: Option<&TargetTriple>,
build_constraints: Constraints,
settings: &ResolverSettings,
workspace: Option<&Workspace>,
client_builder: &BaseClientBuilder<'_>,
state: &PlatformState,
logger: Box<dyn ResolveLogger>,
Expand Down Expand Up @@ -1980,6 +1992,20 @@ pub(crate) async fn resolve_environment(

let client_builder = client_builder.clone().keyring(*keyring_provider);

// Lower the extra build dependencies, if any.
let extra_build_requires = if let Some(workspace) = workspace {
LoweredExtraBuildDependencies::from_workspace(
extra_build_dependencies.clone(),
workspace,
index_locations,
sources,
client_builder.credentials_cache(),
)?
} else {
LoweredExtraBuildDependencies::from_non_lowered(extra_build_dependencies.clone())
}
.into_inner();

// Determine the tags, markers, and interpreter to use for resolution.
let tags = pip::resolution_tags(None, python_platform, interpreter)?;
let marker_env = pip::resolution_markers(None, python_platform, interpreter);
Expand Down Expand Up @@ -2080,11 +2106,6 @@ pub(crate) async fn resolve_environment(

let workspace_cache = WorkspaceCache::default();

// Lower the extra build dependencies, if any.
let extra_build_requires =
LoweredExtraBuildDependencies::from_non_lowered(extra_build_dependencies.clone())
.into_inner();

// Create a build dispatch.
let resolve_dispatch = BuildDispatch::new(
&client,
Expand Down Expand Up @@ -2151,6 +2172,7 @@ pub(crate) async fn sync_environment(
modifications: Modifications,
build_constraints: Constraints,
settings: InstallerSettingsRef<'_>,
workspace: Option<&Workspace>,
client_builder: &BaseClientBuilder<'_>,
state: &PlatformState,
logger: Box<dyn InstallLogger>,
Expand Down Expand Up @@ -2180,6 +2202,20 @@ pub(crate) async fn sync_environment(

let client_builder = client_builder.clone().keyring(keyring_provider);

// Lower the extra build dependencies, if any.
let extra_build_requires = if let Some(workspace) = workspace {
LoweredExtraBuildDependencies::from_workspace(
extra_build_dependencies.clone(),
workspace,
index_locations,
&sources,
client_builder.credentials_cache(),
)?
} else {
LoweredExtraBuildDependencies::from_non_lowered(extra_build_dependencies.clone())
}
.into_inner();

let site_packages = SitePackages::from_environment(&venv)?;

// Determine the markers tags to use for resolution.
Expand Down Expand Up @@ -2219,11 +2255,6 @@ pub(crate) async fn sync_environment(
FlatIndex::from_entries(entries, Some(tags), &hasher, build_options)
};

// Lower the extra build dependencies, if any.
let extra_build_requires =
LoweredExtraBuildDependencies::from_non_lowered(extra_build_dependencies.clone())
.into_inner();

// Create a build dispatch.
let build_dispatch = BuildDispatch::new(
&client,
Expand Down
6 changes: 6 additions & 0 deletions crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ hint: If you are running a script with `{}` in the shebang, you may need to incl
// The lockfile used for the base environment.
let mut base_lock: Option<(Lock, PathBuf)> = None;

// The workspace for the base environment.
let mut workspace: Option<Workspace> = None;

// Determine whether the command to execute is a PEP 723 script.
let temp_dir;
let script_interpreter = if let Some(script) = script {
Expand Down Expand Up @@ -639,6 +642,8 @@ hint: If you are running a script with `{}` in the shebang, you may need to incl
}
}

workspace = project.as_ref().map(|p| p.workspace().clone());

if let Some(project) = project {
if let Some(project_name) = project.project_name() {
debug!(
Expand Down Expand Up @@ -1015,6 +1020,7 @@ hint: If you are running a script with `{}` in the shebang, you may need to incl
&base_interpreter,
python_platform.as_ref(),
&settings,
workspace.as_ref(),
&client_builder,
&sync_state,
if show_resolution {
Expand Down
6 changes: 6 additions & 0 deletions crates/uv/src/commands/tool/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ pub(crate) async fn install(
requirement,
&interpreter,
&settings,
None,
&client_builder,
&state,
concurrency,
Expand Down Expand Up @@ -360,6 +361,7 @@ pub(crate) async fn install(
spec.requirements.clone(),
&interpreter,
&settings,
None,
&client_builder,
&state,
concurrency,
Expand All @@ -386,6 +388,7 @@ pub(crate) async fn install(
spec.overrides,
&interpreter,
&settings,
None,
&client_builder,
&state,
concurrency,
Expand Down Expand Up @@ -616,6 +619,7 @@ pub(crate) async fn install(
python_platform.as_ref(),
Constraints::from_requirements(build_constraints.iter().cloned()),
&settings.resolver,
None,
&client_builder,
&state,
Box::new(DefaultResolveLogger),
Expand Down Expand Up @@ -671,6 +675,7 @@ pub(crate) async fn install(
python_platform.as_ref(),
Constraints::from_requirements(build_constraints.iter().cloned()),
&settings.resolver,
None,
&client_builder,
&state,
Box::new(DefaultResolveLogger),
Expand Down Expand Up @@ -711,6 +716,7 @@ pub(crate) async fn install(
Modifications::Exact,
Constraints::from_requirements(build_constraints.iter().cloned()),
(&settings).into(),
None,
&client_builder,
&state,
Box::new(DefaultInstallLogger),
Expand Down
5 changes: 5 additions & 0 deletions crates/uv/src/commands/tool/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ async fn get_or_create_environment(
vec![spec],
&interpreter,
settings,
None,
client_builder,
&state,
concurrency,
Expand Down Expand Up @@ -992,6 +993,7 @@ async fn get_or_create_environment(
spec.requirements.clone(),
&interpreter,
settings,
None,
client_builder,
&state,
concurrency,
Expand Down Expand Up @@ -1019,6 +1021,7 @@ async fn get_or_create_environment(
spec.overrides.clone(),
&interpreter,
settings,
None,
client_builder,
&state,
concurrency,
Expand Down Expand Up @@ -1135,6 +1138,7 @@ async fn get_or_create_environment(
&interpreter,
python_platform.as_ref(),
settings,
None,
client_builder,
&state,
if show_resolution {
Expand Down Expand Up @@ -1195,6 +1199,7 @@ async fn get_or_create_environment(
&interpreter,
python_platform.as_ref(),
settings,
None,
client_builder,
&state,
if show_resolution {
Expand Down
2 changes: 2 additions & 0 deletions crates/uv/src/commands/tool/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ async fn upgrade_tool(
python_platform,
build_constraints.clone(),
&settings.resolver,
None,
client_builder,
&state,
Box::new(SummaryResolveLogger),
Expand All @@ -368,6 +369,7 @@ async fn upgrade_tool(
Modifications::Exact,
build_constraints,
(&settings).into(),
None,
client_builder,
&state,
Box::new(DefaultInstallLogger),
Expand Down
Loading
Loading