Skip to content

Commit

Permalink
feat: Add the system requirements to pixi info
Browse files Browse the repository at this point in the history
  • Loading branch information
ruben-arts committed Dec 20, 2024
1 parent 9845dfa commit e4fe26c
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/cli/info.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::{fmt::Display, path::PathBuf};

use crate::cli::cli_config::ProjectConfig;
use chrono::{DateTime, Local};
use clap::Parser;
use itertools::Itertools;
use miette::IntoDiagnostic;
use pixi_config;
use pixi_consts::consts;
use pixi_manifest::{EnvironmentName, FeatureName};
use pixi_manifest::{EnvironmentName, FeatureName, SystemRequirements};
use pixi_manifest::{FeaturesExt, HasFeaturesIter};
use pixi_progress::await_in_progress;
use rattler_conda_types::{GenericVirtualPackage, Platform};
Expand All @@ -15,8 +16,7 @@ use rattler_virtual_packages::{VirtualPackage, VirtualPackageOverrides};
use serde::Serialize;
use serde_with::{serde_as, DisplayFromStr};
use tokio::task::spawn_blocking;

use crate::cli::cli_config::ProjectConfig;
use toml_edit::ser::to_string;

use crate::{
global,
Expand All @@ -26,7 +26,7 @@ use crate::{
};
use fancy_display::FancyDisplay;

static WIDTH: usize = 18;
static WIDTH: usize = 19;

/// Information about the system, project and environments for the current
/// machine.
Expand Down Expand Up @@ -65,6 +65,7 @@ pub struct EnvironmentInfo {
tasks: Vec<TaskName>,
channels: Vec<String>,
prefix: PathBuf,
system_requirements: SystemRequirements,
}

impl Display for EnvironmentInfo {
Expand Down Expand Up @@ -145,6 +146,27 @@ impl Display for EnvironmentInfo {
platform_list
)?;
}

if !self.system_requirements.is_empty() {
let serialized = to_string(&self.system_requirements).unwrap();
let indented = serialized
.lines()
.enumerate()
.map(|(i, line)| {
if i == 0 {
// First line includes the label
format!("{:>WIDTH$}: {}", bold.apply_to("System requirements"), line)
} else {
// Subsequent lines are indented to align
format!("{:>WIDTH$} {}", "", line)
}
})
.collect::<Vec<_>>()
.join("\n");

writeln!(f, "{}", indented)?;
}

if !self.tasks.is_empty() {
let tasks_list = self
.tasks
Expand Down Expand Up @@ -403,6 +425,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
.map(|(name, _p)| name.as_source().to_string())
.collect(),
platforms: env.platforms().into_iter().collect(),
system_requirements: env.system_requirements().clone(),
channels: env.channels().into_iter().map(|c| c.to_string()).collect(),
prefix: env.dir(),
tasks,
Expand Down

0 comments on commit e4fe26c

Please sign in to comment.