From eec6d1f7aba70ed31c01c0a4421f76471f46533b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Tue, 16 Jan 2024 11:12:02 +0100 Subject: [PATCH] fix: support adding dependencies for project's unsupported platforms (#668) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes #650 reproducible case (on Linux): ```yaml channels = ["conda-forge"] platforms = [ # "linux-64", "osx-arm64", ] name = "bug" [dependencies] python = "=3.11.*" ``` Run: ``` $ pixi add --no-install ruff WARN pixi::environment: Adding dependency for unsupported platform (linux-64). ✔ Added ruff ``` `ruff = ">=0.1.13,<0.2"` added to `pixi.toml` 🎉 --------- Co-authored-by: Ruben Arts --- src/environment.rs | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/environment.rs b/src/environment.rs index 0cf9c3a5d..d568f1428 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -2,7 +2,7 @@ use crate::{ consts, default_authenticated_client, install, install_pypi, lock_file, prefix::Prefix, progress, Project, }; -use miette::{Context, IntoDiagnostic, LabeledSpan}; +use miette::{Context, IntoDiagnostic}; use crate::lock_file::lock_file_satisfies_project; use crate::project::virtual_packages::verify_current_platform_has_required_virtual_packages; @@ -53,31 +53,13 @@ fn create_prefix_location_file(prefix_file: &Path) -> miette::Result<()> { Ok(()) } -/// Runs a number of different checks to make sure the project is in a sane state: +/// Runs the following checks to make sure the project is in a sane state: /// 1. It verifies that the prefix location is unchanged. -/// 2. It verifies that the project supports the current platform. -/// 3. It verifies that the system requirements are met. +/// 2. It verifies that the system requirements are met. pub fn sanity_check_project(project: &Project) -> miette::Result<()> { // Sanity check of prefix location verify_prefix_location_unchanged(project.pixi_dir().join(consts::PREFIX_FILE_NAME).as_path())?; - // Make sure the project supports the current platform - let platform = Platform::current(); - if !project.platforms().contains(&platform) { - let span = project.manifest.parsed.project.platforms.span(); - return Err(miette::miette!( - help = format!( - "The project needs to be configured to support your platform ({platform})." - ), - labels = vec![LabeledSpan::at( - span.unwrap_or_default(), - format!("add '{platform}' here"), - )], - "the project is not configured for your current platform" - ) - .with_source_code(project.manifest_named_source())); - } - // Make sure the system requirements are met verify_current_platform_has_required_virtual_packages(&project.default_environment())?; @@ -124,9 +106,18 @@ impl LockFileUsage { pub async fn get_up_to_date_prefix( project: &Project, usage: LockFileUsage, - no_install: bool, + mut no_install: bool, sparse_repo_data: Option>, ) -> miette::Result { + // Do not install if the platform is not supported + if !no_install { + let current_platform = Platform::current(); + if !project.platforms().contains(¤t_platform) { + tracing::warn!("Not installing dependency on current platform: ({current_platform}) as it is not part of this project's supported platforms."); + no_install = true; + } + } + // Make sure the project is in a sane state sanity_check_project(project)?;