Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve debugablity global #2241

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/cli/global/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use rattler_conda_types::{PackageName, PackageRecord, PrefixRecord, Version};
use serde::Serialize;
use std::io::{stdout, Write};
use std::str::FromStr;
use thiserror::__private::AsDisplay;

/// Lists all packages previously installed into a globally accessible location via `pixi global install`.
///
Expand Down Expand Up @@ -284,13 +283,8 @@ async fn list_global_environments(project: Project) -> miette::Result<()> {
println!("No global environments found.");
} else {
println!(
"Global environments at {}:\n{}",
project
.env_root
.path()
.parent()
.unwrap_or(project.env_root.path())
.as_display(),
"Global environments as specified in '{}'\n{}",
console::style(project.manifest.path.display()).bold(),
message
);
}
Expand Down
63 changes: 60 additions & 3 deletions src/cli/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ use tokio::task::spawn_blocking;

use crate::cli::cli_config::ProjectConfig;

use crate::{task::TaskName, Project};
use crate::{
global,
global::{BinDir, EnvRoot},
task::TaskName,
Project,
};
use fancy_display::FancyDisplay;

static WIDTH: usize = 18;
Expand Down Expand Up @@ -158,6 +163,38 @@ impl Display for EnvironmentInfo {
}
}

/// Information about `pixi global`
#[derive(Serialize)]
struct GlobalInfo {
bin_dir: PathBuf,
env_dir: PathBuf,
manifest: PathBuf,
}
impl Display for GlobalInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let bold = console::Style::new().bold();
writeln!(
f,
"{:>WIDTH$}: {}",
bold.apply_to("Bin dir"),
self.bin_dir.to_string_lossy()
)?;
writeln!(
f,
"{:>WIDTH$}: {}",
bold.apply_to("Environment dir"),
self.env_dir.to_string_lossy()
)?;
writeln!(
f,
"{:>WIDTH$}: {}",
bold.apply_to("Manifest dir"),
self.manifest.to_string_lossy()
)?;
Ok(())
}
}

#[serde_as]
#[derive(Serialize)]
pub struct Info {
Expand All @@ -168,6 +205,7 @@ pub struct Info {
cache_dir: Option<PathBuf>,
cache_size: Option<String>,
auth_dir: PathBuf,
global_info: Option<GlobalInfo>,
project_info: Option<ProjectInfo>,
environments_info: Vec<EnvironmentInfo>,
config_locations: Vec<PathBuf>,
Expand All @@ -180,6 +218,7 @@ impl Display for Info {
None => "None".to_string(),
};

writeln!(f, "{}", bold.apply_to("System\n------------").cyan())?;
writeln!(
f,
"{:>WIDTH$}: {}",
Expand Down Expand Up @@ -230,8 +269,15 @@ impl Display for Info {
}
)?;

// Pixi global information
if let Some(gi) = self.global_info.as_ref() {
writeln!(f, "\n{}", bold.apply_to("Global\n------------").cyan())?;
write!(f, "{}", gi)?;
}

// Project information
if let Some(pi) = self.project_info.as_ref() {
writeln!(f, "\n{}", bold.apply_to("Project\n------------"))?;
writeln!(f, "\n{}", bold.apply_to("Project\n------------").cyan())?;
writeln!(f, "{:>WIDTH$}: {}", bold.apply_to("Name"), pi.name)?;
if let Some(version) = pi.version.clone() {
writeln!(f, "{:>WIDTH$}: {}", bold.apply_to("Version"), version)?;
Expand All @@ -254,7 +300,11 @@ impl Display for Info {
}

if !self.environments_info.is_empty() {
writeln!(f, "\n{}", bold.apply_to("Environments\n------------"))?;
writeln!(
f,
"\n{}",
bold.apply_to("Environments\n------------").cyan()
)?;
for e in &self.environments_info {
writeln!(f, "{}", e)?;
}
Expand Down Expand Up @@ -360,6 +410,12 @@ pub async fn execute(args: Args) -> miette::Result<()> {
})
.unwrap_or_default();

let global_info = Some(GlobalInfo {
bin_dir: BinDir::from_env().await?.path().to_path_buf(),
env_dir: EnvRoot::from_env().await?.path().to_path_buf(),
manifest: global::Project::manifest_dir()?.join(global::project::MANIFEST_DEFAULT_NAME),
});

let virtual_packages = VirtualPackage::detect(&VirtualPackageOverrides::from_env())
.into_diagnostic()?
.iter()
Expand Down Expand Up @@ -389,6 +445,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
auth_dir: auth_file,
project_info,
environments_info,
global_info,
config_locations: config.loaded_from.clone(),
};

Expand Down
Loading