Skip to content

Commit

Permalink
Feat/add sanity check (#569)
Browse files Browse the repository at this point in the history
Adds the same sanity check for add as is also being used for other
operations.
  • Loading branch information
tdejager authored Dec 14, 2023
1 parent 9da003f commit 3ca1e63
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions src/cli/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,13 @@ pub async fn add_conda_specs_to_project(
Ok(())
}

/// Updates the lock file and potentially the prefix to get an up-to-date environment.
///
/// We are using this function instead of [`crate::environment::get_up_to_date_prefix`] because we want to be able to
/// specify if we do not want to update the prefix. Also we know the lock file needs to be updated so `--frozen` and `--locked`
/// make no sense in this scenario.
///
/// Essentially, other than that it does almost the same thing
async fn update_environment(
project: &Project,
sparse_repo_data: Option<Vec<SparseRepoData>>,
Expand All @@ -344,24 +351,21 @@ async fn update_environment(

if let Some(lock_file) = lock_file {
if !no_install {
let platform = Platform::current();
if project.platforms().contains(&platform) {
// Get the currently installed packages
let prefix = Prefix::new(project.root().join(".pixi/env"))?;
let installed_packages = prefix.find_installed_packages(None).await?;

// Update the prefix
update_prefix(
project.pypi_package_db()?,
&prefix,
installed_packages,
&lock_file,
platform,
)
.await?;
} else {
eprintln!("{} skipping installation of environment because your platform ({platform}) is not supported by this project.", console::style("!").yellow().bold())
}
crate::environment::sanity_check_project(project)?;

// Get the currently installed packages
let prefix = Prefix::new(project.root().join(".pixi/env"))?;
let installed_packages = prefix.find_installed_packages(None).await?;

// Update the prefix
update_prefix(
project.pypi_package_db()?,
&prefix,
installed_packages,
&lock_file,
Platform::current(),
)
.await?;
}
}
Ok(())
Expand Down

0 comments on commit 3ca1e63

Please sign in to comment.