Skip to content

Commit

Permalink
use best_platform in a few places
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Mar 19, 2024
1 parent 93f838b commit 93dd46c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ pub async fn execute(args: Args) -> miette::Result<()> {
let search_environment = SearchEnvironments::from_opt_env(
&project,
explicit_environment.clone(),
Some(Platform::current()),
explicit_environment
.as_ref()
.map(|e| e.best_platform())
.or(Some(Platform::current())),
)
.with_disambiguate_fn(disambiguate_task_interactive);

Expand Down
2 changes: 1 addition & 1 deletion src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pub async fn get_up_to_date_prefix(
mut no_install: bool,
existing_repo_data: IndexMap<(Channel, Platform), SparseRepoData>,
) -> miette::Result<Prefix> {
let current_platform = Platform::current();
let current_platform = environment.best_platform();
let project = environment.project();

// Do not install if the platform is not supported
Expand Down
10 changes: 6 additions & 4 deletions src/lock_file/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<'p> LockFileDerivedData<'p> {
}

// Get the prefix with the conda packages installed.
let platform = Platform::current();
let platform = environment.best_platform();
let (prefix, python_status) = self.conda_prefix(environment).await?;
let repodata_records = self
.repodata_records(environment, platform)
Expand Down Expand Up @@ -173,7 +173,7 @@ impl<'p> LockFileDerivedData<'p> {
}

let prefix = Prefix::new(environment.dir());
let platform = Platform::current();
let platform = environment.best_platform();

// Determine the currently installed packages.
let installed_packages = prefix
Expand Down Expand Up @@ -619,7 +619,9 @@ pub async fn ensure_up_to_date_lock_file(
// we solve the platforms. We want to solve the current platform first, so we can start
// instantiating prefixes if we have to.
let mut ordered_platforms = platforms.into_iter().collect::<IndexSet<_>>();
if let Some(current_platform_index) = ordered_platforms.get_index_of(&current_platform) {
if let Some(current_platform_index) =
ordered_platforms.get_index_of(&environment.best_platform())
{
ordered_platforms.move_index(current_platform_index, 0);
}

Expand Down Expand Up @@ -704,7 +706,7 @@ pub async fn ensure_up_to_date_lock_file(
// Construct a future that will resolve when we have the repodata available for the current
// platform for this group.
let records_future = context
.get_latest_group_repodata_records(&group, current_platform)
.get_latest_group_repodata_records(&group, environment.best_platform())
.expect("conda records should be available now or in the future");

// Spawn a task to instantiate the environment
Expand Down
16 changes: 16 additions & 0 deletions src/project/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ impl<'p> Environment<'p> {
.unwrap_or_default()
}

/// Returns the best platform for the current platform & environment.
pub fn best_platform(&self) -> Platform {
let current = Platform::current();

// If the current platform is supported, return it.
if self.platforms().contains(&current) {
return current;
}

if current.is_osx() && self.platforms().contains(&Platform::Osx64) {
return Platform::Osx64;
}

current
}

/// Returns the tasks defined for this environment.
///
/// Tasks are defined on a per-target per-feature per-environment basis.
Expand Down
12 changes: 6 additions & 6 deletions src/project/virtual_packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ pub fn get_minimal_virtual_packages(
virtual_packages.push(VirtualPackage::Win);
}

if let Some(archspec) = system_requirements.archspec.clone() {
virtual_packages.push(VirtualPackage::Archspec(Archspec { spec: archspec }))
} else if let Some(archspec) = Archspec::from_platform(platform) {
virtual_packages.push(archspec.into())
}
// if let Some(archspec) = system_requirements.archspec.clone() {
// virtual_packages.push(VirtualPackage::Archspec(Archspec { spec: archspec }))
// } else if let Some(archspec) = Archspec::from_platform(platform) {
// virtual_packages.push(archspec.into())
// }

// Add platform specific packages
if platform.is_osx() {
Expand Down Expand Up @@ -139,7 +139,7 @@ pub enum VerifyCurrentPlatformError {
pub fn verify_current_platform_has_required_virtual_packages(
environment: &Environment<'_>,
) -> Result<(), VerifyCurrentPlatformError> {
let current_platform = Platform::current();
let current_platform = environment.best_platform();

// Is the current platform in the list of supported platforms?
if !environment.platforms().contains(&current_platform) {
Expand Down
7 changes: 5 additions & 2 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,11 @@ impl PixiControl {
// Create a task graph from the command line arguments.
let search_env = SearchEnvironments::from_opt_env(
&project,
explicit_environment,
Some(Platform::current()),
explicit_environment.clone(),
explicit_environment
.as_ref()
.map(|e| e.best_platform())
.or(Some(Platform::current())),
);
let task_graph = TaskGraph::from_cmd_args(&project, &search_env, args.task)
.map_err(RunError::TaskGraphError)?;
Expand Down

0 comments on commit 93dd46c

Please sign in to comment.