Skip to content

Commit

Permalink
refactor: check platform separately
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Jan 15, 2024
1 parent 91b87fb commit 95e8435
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,17 @@ 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.
///
/// Returns `true` if project supports the current platform.
pub fn sanity_check_project(project: &Project) -> miette::Result<bool> {
// Whether that the dependency will be installed or not.
let mut supported_platform = true;

/// 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) {
supported_platform = false;
tracing::warn!("Not installing dependency on current platform: ({platform}) as it is not part of the supported platforms.");
}

// Make sure the system requirements are met
verify_current_platform_has_required_virtual_packages(&project.default_environment())?;

Ok(supported_platform)
Ok(())
}

/// Specifies how the lock-file should be updated.
Expand Down Expand Up @@ -122,12 +109,16 @@ pub async fn get_up_to_date_prefix(
mut no_install: bool,
sparse_repo_data: Option<Vec<SparseRepoData>>,
) -> miette::Result<Prefix> {
// Make sure the project is in a sane state
// Do not install if the platform is not supported
if !sanity_check_project(project)? {
let current_platform = Platform::current();
if !project.platforms().contains(&current_platform) {

This comment has been minimized.

Copy link
@ruben-arts

ruben-arts Jan 16, 2024

Contributor

Yeah this is good, though I would skip this check/warning when no_install is true.

This comment has been minimized.

Copy link
@orhun

orhun Jan 16, 2024

Author Contributor

Done in e9a99c6

tracing::warn!("Not installing dependency on current platform: ({current_platform}) as it is not part of the supported platforms.");
no_install = true;
}

// Make sure the project is in a sane state
sanity_check_project(project)?;

// Start loading the installed packages in the background
let prefix = Prefix::new(project.environment_dir())?;
let installed_packages_future = {
Expand Down

0 comments on commit 95e8435

Please sign in to comment.