-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: only instantiate conda prefix for pypi solve on request (#3029)
This PR change behavior, that only when source distributions (i.e git, non-editable path, or sdist) are encountered, do we actually instantiate the prefix. If you do not have any source dependencies, we instantiate no prefix before doing a PyPI solve. You can further enforce this by adding no-build = true to your [pypi-options]. Also when a previously built sdist is cached, i.e. the built metadata is available, we also skip instantiation. So we expect a much faster solve for tomls with little source dependencies and heavy environments. This verification can be seen in the comments. This will be the first step though, there are also repositories like rerun-io/rerun that actually do have numerous source dependencies but only require python for the most of them. A further PR could be introduced where we also only instantiate a partial prefix on solve, this does require some user-input, as we need to know which packages need to be available.
- Loading branch information
Showing
20 changed files
with
952 additions
and
418 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
use crate::build::BuildContext; | ||
use crate::environment::{self, PythonStatus}; | ||
use crate::lock_file::IoConcurrencyLimit; | ||
use crate::prefix::Prefix; | ||
use crate::project::grouped_environment::{GroupedEnvironment, GroupedEnvironmentName}; | ||
use crate::project::HasProjectRef; | ||
use futures::TryFutureExt; | ||
use miette::IntoDiagnostic; | ||
use pixi_manifest::FeaturesExt; | ||
use pixi_record::PixiRecord; | ||
use rattler::package_cache::PackageCache; | ||
use rattler_conda_types::Platform; | ||
|
||
/// A struct that contains the result of updating a conda prefix. | ||
pub struct CondaPrefixUpdated { | ||
/// The name of the group that was updated. | ||
pub group: GroupedEnvironmentName, | ||
/// The prefix that was updated. | ||
pub prefix: Prefix, | ||
/// Any change to the python interpreter. | ||
pub python_status: Box<PythonStatus>, | ||
} | ||
|
||
#[derive(Clone)] | ||
/// A task that updates the prefix for a given environment. | ||
pub struct CondaPrefixUpdater<'a> { | ||
pub group: GroupedEnvironment<'a>, | ||
pub platform: Platform, | ||
pub package_cache: PackageCache, | ||
pub io_concurrency_limit: IoConcurrencyLimit, | ||
pub build_context: BuildContext, | ||
} | ||
|
||
impl<'a> CondaPrefixUpdater<'a> { | ||
/// Creates a new prefix task. | ||
pub fn new( | ||
group: GroupedEnvironment<'a>, | ||
platform: Platform, | ||
package_cache: PackageCache, | ||
io_concurrency_limit: IoConcurrencyLimit, | ||
build_context: BuildContext, | ||
) -> Self { | ||
Self { | ||
group, | ||
package_cache, | ||
io_concurrency_limit, | ||
build_context, | ||
platform, | ||
} | ||
} | ||
|
||
/// Updates the prefix for the given environment. | ||
pub(crate) async fn update( | ||
&self, | ||
pixi_records: Vec<PixiRecord>, | ||
) -> miette::Result<CondaPrefixUpdated> { | ||
tracing::debug!( | ||
"updating prefix for '{}'", | ||
self.group.name().fancy_display() | ||
); | ||
|
||
let channels = self | ||
.group | ||
.channel_urls(&self.group.project().channel_config()) | ||
.into_diagnostic()?; | ||
|
||
// Spawn a task to determine the currently installed packages. | ||
let prefix_clone = self.group.prefix().clone(); | ||
let installed_packages_future = | ||
tokio::task::spawn_blocking(move || prefix_clone.find_installed_packages()) | ||
.unwrap_or_else(|e| match e.try_into_panic() { | ||
Ok(panic) => std::panic::resume_unwind(panic), | ||
Err(_err) => Err(miette::miette!("the operation was cancelled")), | ||
}); | ||
|
||
// Wait until the conda records are available and until the installed packages | ||
// for this prefix are available. | ||
let installed_packages = installed_packages_future.await?; | ||
|
||
let has_existing_packages = !installed_packages.is_empty(); | ||
let group_name = self.group.name().clone(); | ||
let client = self.group.project().authenticated_client().clone(); | ||
let prefix = self.group.prefix(); | ||
|
||
let python_status = environment::update_prefix_conda( | ||
&prefix, | ||
self.package_cache.clone(), | ||
client, | ||
installed_packages, | ||
pixi_records, | ||
self.group.virtual_packages(self.platform), | ||
channels, | ||
self.platform, | ||
&format!( | ||
"{} conda prefix '{}'", | ||
if has_existing_packages { | ||
"updating" | ||
} else { | ||
"creating" | ||
}, | ||
group_name.fancy_display() | ||
), | ||
" ", | ||
self.io_concurrency_limit.clone().into(), | ||
self.build_context.clone(), | ||
) | ||
.await?; | ||
|
||
Ok(CondaPrefixUpdated { | ||
group: group_name, | ||
prefix, | ||
python_status: Box::new(python_status), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.