Skip to content

Commit

Permalink
Use shared resolver state between add and lock
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Oct 12, 2024
1 parent e67d873 commit 9678a30
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 24 deletions.
3 changes: 2 additions & 1 deletion crates/uv/src/commands/project/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ async fn lock_and_sync(
project.workspace(),
venv.interpreter(),
settings.into(),
&state,
Box::new(DefaultResolveLogger),
connectivity,
concurrency,
Expand Down Expand Up @@ -734,6 +735,7 @@ async fn lock_and_sync(
project.workspace(),
venv.interpreter(),
settings.into(),
&state,
Box::new(SummaryResolveLogger),
connectivity,
concurrency,
Expand Down Expand Up @@ -779,7 +781,6 @@ async fn lock_and_sync(
InstallOptions::default(),
Modifications::Sufficient,
settings.into(),
&state,
Box::new(DefaultInstallLogger),
connectivity,
concurrency,
Expand Down
7 changes: 6 additions & 1 deletion crates/uv/src/commands/project/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use uv_workspace::{DiscoveryOptions, MemberDiscovery, VirtualProject, Workspace}
use crate::commands::pip::loggers::DefaultResolveLogger;
use crate::commands::project::lock::do_safe_lock;
use crate::commands::project::{ProjectError, ProjectInterpreter};
use crate::commands::{diagnostics, pip, ExitStatus, OutputWriter};
use crate::commands::{diagnostics, pip, ExitStatus, OutputWriter, SharedState};
use crate::printer::Printer;
use crate::settings::ResolverSettings;

Expand Down Expand Up @@ -88,13 +88,18 @@ pub(crate) async fn export(
.await?
.into_interpreter();

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


// Lock the project.
let lock = match do_safe_lock(
locked,
frozen,
project.workspace(),
&interpreter,
settings.as_ref(),
&state,
Box::new(DefaultResolveLogger),
connectivity,
concurrency,
Expand Down
17 changes: 6 additions & 11 deletions crates/uv/src/commands/project/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,18 @@ pub(crate) async fn lock(
.await?
.into_interpreter();

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


// Perform the lock operation.
match do_safe_lock(
locked,
frozen,
&workspace,
&interpreter,
settings.as_ref(),
&state,
Box::new(DefaultResolveLogger),
connectivity,
concurrency,
Expand Down Expand Up @@ -153,24 +158,14 @@ pub(super) async fn do_safe_lock(
workspace: &Workspace,
interpreter: &Interpreter,
settings: ResolverSettingsRef<'_>,
state: &SharedState,
logger: Box<dyn ResolveLogger>,
connectivity: Connectivity,
concurrency: Concurrency,
native_tls: bool,
cache: &Cache,
printer: Printer,
) -> Result<LockResult, ProjectError> {
// Use isolate state for universal resolution. When resolving, we don't enforce that the
// prioritized distributions match the current platform. So if we lock here, then try to
// install from the same state, and we end up performing a resolution during the sync (i.e.,
// for the build dependencies of a source distribution), we may try to use incompatible
// distributions.
// TODO(charlie): In universal resolution, we should still track version compatibility! We
// just need to accept versions that are platform-incompatible. That would also make us more
// likely to (e.g.) download a wheel that we'll end up using when installing. This would
// make it safe to share the state.
let state = SharedState::default();

if frozen {
// Read the existing lockfile, but don't attempt to lock the project.
let existing = read(workspace)
Expand Down
10 changes: 6 additions & 4 deletions crates/uv/src/commands/project/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,19 @@ pub(crate) async fn remove(
)
.await?;


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


// Lock and sync the environment, if necessary.
let lock = project::lock::do_safe_lock(
locked,
frozen,
project.workspace(),
venv.interpreter(),
settings.as_ref().into(),
&state,
Box::new(DefaultResolveLogger),
connectivity,
concurrency,
Expand All @@ -193,9 +199,6 @@ pub(crate) async fn remove(
let extras = ExtrasSpecification::All;
let install_options = InstallOptions::default();

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

project::sync::do_sync(
InstallTarget::from(&project),
&venv,
Expand All @@ -206,7 +209,6 @@ pub(crate) async fn remove(
install_options,
Modifications::Exact,
settings.as_ref().into(),
&state,
Box::new(DefaultInstallLogger),
connectivity,
concurrency,
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ pub(crate) async fn run(
project.workspace(),
venv.interpreter(),
settings.as_ref().into(),
&state,
if show_resolution {
Box::new(DefaultResolveLogger)
} else {
Expand Down Expand Up @@ -576,7 +577,6 @@ pub(crate) async fn run(
install_options,
Modifications::Sufficient,
settings.as_ref().into(),
&state,
if show_resolution {
Box::new(DefaultInstallLogger)
} else {
Expand Down
20 changes: 15 additions & 5 deletions crates/uv/src/commands/project/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,16 @@ pub(crate) async fn sync(
)
.await?;

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

let lock = match do_safe_lock(
locked,
frozen,
target.workspace(),
venv.interpreter(),
settings.as_ref().into(),
&state,
Box::new(DefaultResolveLogger),
connectivity,
concurrency,
Expand Down Expand Up @@ -140,9 +144,6 @@ pub(crate) async fn sync(
Err(err) => return Err(err.into()),
};

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

// Perform the sync operation.
do_sync(
target,
Expand All @@ -154,7 +155,6 @@ pub(crate) async fn sync(
install_options,
modifications,
settings.as_ref().into(),
&state,
Box::new(DefaultInstallLogger),
connectivity,
concurrency,
Expand All @@ -179,14 +179,24 @@ pub(super) async fn do_sync(
install_options: InstallOptions,
modifications: Modifications,
settings: InstallerSettingsRef<'_>,
state: &SharedState,
logger: Box<dyn InstallLogger>,
connectivity: Connectivity,
concurrency: Concurrency,
native_tls: bool,
cache: &Cache,
printer: Printer,
) -> Result<(), ProjectError> {
// Use isolated state for universal resolution. When resolving, we don't enforce that the
// prioritized distributions match the current platform. So if we lock here, then try to
// install from the same state, and we end up performing a resolution during the sync (i.e.,
// for the build dependencies of a source distribution), we may try to use incompatible
// distributions.
// TODO(charlie): In universal resolution, we should still track version compatibility! We
// just need to accept versions that are platform-incompatible. That would also make us more
// likely to (e.g.) download a wheel that we'll end up using when installing. This would
// make it safe to share the state.
let state = SharedState::default();

// Extract the project settings.
let InstallerSettingsRef {
index_locations,
Expand Down
6 changes: 5 additions & 1 deletion crates/uv/src/commands/project/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use uv_workspace::{DiscoveryOptions, Workspace};
use crate::commands::pip::loggers::DefaultResolveLogger;
use crate::commands::pip::resolution_markers;
use crate::commands::project::ProjectInterpreter;
use crate::commands::{project, ExitStatus};
use crate::commands::{project, ExitStatus, SharedState};
use crate::printer::Printer;
use crate::settings::ResolverSettings;

Expand Down Expand Up @@ -59,13 +59,17 @@ pub(crate) async fn tree(
.await?
.into_interpreter();

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

// Update the lockfile, if necessary.
let lock = project::lock::do_safe_lock(
locked,
frozen,
&workspace,
&interpreter,
settings.as_ref(),
&state,
Box::new(DefaultResolveLogger),
connectivity,
concurrency,
Expand Down

0 comments on commit 9678a30

Please sign in to comment.