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

Nest setup code under unnamed requirements block #10163

Merged
merged 1 commit into from
Dec 25, 2024
Merged
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
139 changes: 68 additions & 71 deletions crates/uv/src/commands/project/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,76 +253,9 @@ pub(crate) async fn add(
let RequirementsSpecification { requirements, .. } =
RequirementsSpecification::from_simple_sources(&requirements, &client_builder).await?;

// TODO(charlie): These are all default values. We should consider whether we want to make them
// optional on the downstream APIs.
let bounds = LowerBound::default();
let build_constraints = Constraints::default();
let build_hasher = HashStrategy::default();
let hasher = HashStrategy::default();
let sources = SourceStrategy::Enabled;

// Add all authenticated sources to the cache.
for index in settings.index_locations.allowed_indexes() {
if let Some(credentials) = index.credentials() {
uv_auth::store_credentials(index.raw_url(), credentials);
}
}

// Initialize the registry client.
let client = RegistryClientBuilder::try_from(client_builder)?
.index_urls(settings.index_locations.index_urls())
.index_strategy(settings.index_strategy)
.markers(target.interpreter().markers())
.platform(target.interpreter().platform())
.build();

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

// Initialize any shared state.
let state = SharedState::default();

// Resolve the flat indexes from `--find-links`.
let flat_index = {
let client = FlatIndexClient::new(&client, cache);
let entries = client
.fetch(settings.index_locations.flat_indexes().map(Index::url))
.await?;
FlatIndex::from_entries(entries, None, &hasher, &settings.build_options)
};

// Create a build dispatch.
let build_dispatch = BuildDispatch::new(
&client,
cache,
build_constraints,
target.interpreter(),
&settings.index_locations,
&flat_index,
&settings.dependency_metadata,
state.clone(),
settings.index_strategy,
&settings.config_setting,
build_isolation,
settings.link_mode,
&settings.build_options,
&build_hasher,
settings.exclude_newer,
bounds,
sources,
concurrency,
preview,
);

// Resolve any unnamed requirements.
let requirements = {
// Partition the requirements into named and unnamed requirements.
Expand All @@ -345,6 +278,72 @@ pub(crate) async fn add(

// Resolve any unnamed requirements.
if !unnamed.is_empty() {
// TODO(charlie): These are all default values. We should consider whether we want to
// make them optional on the downstream APIs.
let build_constraints = Constraints::default();
let build_hasher = HashStrategy::default();
let hasher = HashStrategy::default();
let sources = SourceStrategy::Enabled;

// Add all authenticated sources to the cache.
for index in settings.index_locations.allowed_indexes() {
if let Some(credentials) = index.credentials() {
uv_auth::store_credentials(index.raw_url(), credentials);
}
}

// Initialize the registry client.
let client = RegistryClientBuilder::try_from(client_builder)?
.index_urls(settings.index_locations.index_urls())
.index_strategy(settings.index_strategy)
.markers(target.interpreter().markers())
.platform(target.interpreter().platform())
.build();

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

// Resolve the flat indexes from `--find-links`.
let flat_index = {
let client = FlatIndexClient::new(&client, cache);
let entries = client
.fetch(settings.index_locations.flat_indexes().map(Index::url))
.await?;
FlatIndex::from_entries(entries, None, &hasher, &settings.build_options)
};

// Create a build dispatch.
let build_dispatch = BuildDispatch::new(
&client,
cache,
build_constraints,
target.interpreter(),
&settings.index_locations,
&flat_index,
&settings.dependency_metadata,
state.clone(),
settings.index_strategy,
&settings.config_setting,
build_isolation,
settings.link_mode,
&settings.build_options,
&build_hasher,
settings.exclude_newer,
LowerBound::default(),
sources,
concurrency,
preview,
);

requirements.extend(
NamedRequirementsResolver::new(
&hasher,
Expand Down Expand Up @@ -654,7 +653,6 @@ pub(crate) async fn add(
&dependency_type,
raw_sources,
settings.as_ref(),
bounds,
installer_metadata,
connectivity,
concurrency,
Expand Down Expand Up @@ -698,7 +696,6 @@ async fn lock_and_sync(
dependency_type: &DependencyType,
raw_sources: bool,
settings: ResolverInstallerSettingsRef<'_>,
bounds: LowerBound,
installer_metadata: bool,
connectivity: Connectivity,
concurrency: Concurrency,
Expand All @@ -718,7 +715,7 @@ async fn lock_and_sync(
mode,
project.workspace().into(),
settings.into(),
bounds,
LowerBound::default(),
&state,
Box::new(DefaultResolveLogger),
connectivity,
Expand Down Expand Up @@ -837,7 +834,7 @@ async fn lock_and_sync(
mode,
project.workspace().into(),
settings.into(),
bounds,
LowerBound::default(),
&state,
Box::new(SummaryResolveLogger),
connectivity,
Expand Down
Loading