Skip to content

Commit

Permalink
fix: minor pixi update improvements
Browse files Browse the repository at this point in the history
- Use `EnvironmentName` more
- Use `fancy_display`
- Borrow instead of taking ownership
  • Loading branch information
Hofer-Julian committed Oct 29, 2024
1 parent 2506137 commit e307808
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/cli/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::{
io::{stdout, Write},
};

use fancy_display::FancyDisplay;

use crate::cli::cli_config::ProjectConfig;
use crate::{
load_lock_file,
Expand Down Expand Up @@ -90,10 +92,15 @@ impl From<UpdateSpecsArgs> for UpdateSpecs {
impl UpdateSpecs {
/// Returns true if the package should be relaxed according to the user
/// input.
fn should_relax(&self, environment_name: &str, platform: Platform, package: &Package) -> bool {
fn should_relax(
&self,
environment_name: &EnvironmentName,
platform: &Platform,
package: &Package,
) -> bool {
// Check if the platform is in the list of platforms to update.
if let Some(platforms) = &self.platforms {
if !platforms.contains(&platform) {
if !platforms.contains(platform) {
return false;
}
}
Expand All @@ -115,7 +122,7 @@ impl UpdateSpecs {
tracing::debug!(
"relaxing package: {}, env={}, platform={}",
package.name(),
consts::ENVIRONMENT_STYLE.apply_to(environment_name),
environment_name.fancy_display(),
consts::PLATFORM_STYLE.apply_to(platform),
);

Expand All @@ -134,7 +141,10 @@ pub async fn execute(args: Args) -> miette::Result<()> {
if let Some(env) = &specs.environments {
for env in env {
if project.environment(env).is_none() {
miette::bail!("could not find an environment named '{}'", env)
miette::bail!(
"could not find an environment named {}",
env.fancy_display()
)
}
}
}
Expand Down Expand Up @@ -262,7 +272,7 @@ fn check_package_exists(
/// Constructs a new lock-file where some of the constraints have been removed.
fn unlock_packages(project: &Project, lock_file: &LockFile, specs: &UpdateSpecs) -> LockFile {
filter_lock_file(project, lock_file, |env, platform, package| {
!specs.should_relax(env.name().as_str(), platform, package)
!specs.should_relax(env.name(), &platform, package)
})
}

Expand Down

0 comments on commit e307808

Please sign in to comment.