From ebda8b142eaf19b37f04b7a77f6eda0ebbcbb4d4 Mon Sep 17 00:00:00 2001 From: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com> Date: Fri, 20 Sep 2024 08:51:44 +0200 Subject: [PATCH] fix: Remove `allow(unused` and fix resulting warnings (#2091) --- src/global/common.rs | 70 ++------------------------- src/global/install.rs | 30 ++++-------- src/global/mod.rs | 9 +--- src/global/project/environment.rs | 3 -- src/global/project/manifest.rs | 3 ++ src/global/project/mod.rs | 57 +++++++--------------- src/global/project/parsed_manifest.rs | 8 ++- src/lib.rs | 1 - src/repodata.rs | 10 ---- 9 files changed, 38 insertions(+), 153 deletions(-) delete mode 100644 src/repodata.rs diff --git a/src/global/common.rs b/src/global/common.rs index 6d326ee59..08d985d58 100644 --- a/src/global/common.rs +++ b/src/global/common.rs @@ -5,24 +5,7 @@ use std::{ use itertools::Itertools; use miette::{Context, IntoDiagnostic}; -use pixi_progress::{await_in_progress, global_multi_progress}; -use rattler::{ - install::{DefaultProgressFormatter, IndicatifReporter, Installer}, - package_cache::PackageCache, -}; -use rattler_conda_types::{ - Channel, ChannelConfig, PackageName, Platform, PrefixRecord, RepoDataRecord, -}; -use rattler_shell::{ - activation::{ActivationVariables, Activator, PathModificationBehavior}, - shell::ShellEnum, -}; -use reqwest_middleware::ClientWithMiddleware; -use tokio::io::AsyncReadExt; -use crate::{ - cli::project::environment, prefix::Prefix, repodata, rlimit::try_increase_rlimit_to_sensible, -}; use pixi_config::home_path; use super::{EnvironmentName, ExposedKey}; @@ -84,7 +67,7 @@ impl BinDir { executable_script_path } - pub(crate) async fn print_executables_available( + pub async fn print_executables_available( &self, executables: Vec, ) -> miette::Result<()> { @@ -206,7 +189,6 @@ impl EnvRoot { /// A global environment directory pub(crate) struct EnvDir { - root: EnvRoot, path: PathBuf, } @@ -219,23 +201,7 @@ impl EnvDir { let path = root.path().join(environment_name.as_str()); tokio::fs::create_dir_all(&path).await.into_diagnostic()?; - Ok(Self { root, path }) - } - - /// Initialize a global environment directory from an existing path - pub(crate) fn try_from_existing( - root: EnvRoot, - environment_name: EnvironmentName, - ) -> miette::Result { - let path = root.path().join(environment_name.as_str()); - if !path.is_dir() { - return Err(miette::miette!( - "Directory does not exist: {}", - path.display() - )); - } - - Ok(Self { root, path }) + Ok(Self { path }) } /// Construct the path to the env directory for the environment @@ -245,36 +211,6 @@ impl EnvDir { } } -/// Get the friendly channel name of a [`PrefixRecord`] -/// -/// # Returns -/// -/// The friendly channel name of the given prefix record -pub(crate) fn channel_name_from_prefix( - prefix_package: &PrefixRecord, - channel_config: &ChannelConfig, -) -> String { - Channel::from_str(&prefix_package.repodata_record.channel, channel_config) - .map(|ch| repodata::friendly_channel_name(&ch)) - .unwrap_or_else(|_| prefix_package.repodata_record.channel.clone()) -} - -/// Find the designated package in the given [`Prefix`] -/// -/// # Returns -/// -/// The PrefixRecord of the designated package -pub(crate) async fn find_designated_package( - prefix: &Prefix, - package_name: &PackageName, -) -> miette::Result { - let prefix_records = prefix.find_installed_packages(None).await?; - prefix_records - .into_iter() - .find(|r| r.repodata_record.package_record.name == *package_name) - .ok_or_else(|| miette::miette!("could not find {} in prefix", package_name.as_source())) -} - /// Checks if a file is binary by reading the first 1024 bytes and checking for null bytes. pub(crate) fn is_binary(file_path: impl AsRef) -> miette::Result { let mut file = std::fs::File::open(&file_path) @@ -298,7 +234,7 @@ pub(crate) fn is_text(file_path: impl AsRef) -> miette::Result { #[cfg(test)] mod tests { use super::*; - use std::path::Path; + use tempfile::tempdir; #[tokio::test] diff --git a/src/global/install.rs b/src/global/install.rs index 7c5587e76..54b0bc9b8 100644 --- a/src/global/install.rs +++ b/src/global/install.rs @@ -1,19 +1,9 @@ -use std::{ - borrow::Borrow, - collections::HashMap, - ffi::OsStr, - iter, - path::{Path, PathBuf}, - str::FromStr, - time, -}; +use std::{collections::HashMap, ffi::OsStr, path::PathBuf, str::FromStr}; -use clap::Parser; -use distribution_types::Diagnostic; use indexmap::IndexMap; use itertools::Itertools; -use miette::{bail, Context, IntoDiagnostic}; -use pixi_config::{self, default_channel_config, Config, ConfigCli}; +use miette::{Context, IntoDiagnostic}; +use pixi_config::{self, default_channel_config, Config}; use pixi_progress::{await_in_progress, global_multi_progress, wrap_in_progress}; use pixi_utils::reqwest::build_reqwest_clients; use rattler::{ @@ -22,7 +12,7 @@ use rattler::{ }; use rattler_conda_types::{ GenericVirtualPackage, MatchSpec, Matches, PackageName, ParseStrictness, Platform, - PrefixRecord, RepoDataRecord, + RepoDataRecord, }; use rattler_repodata_gateway::Gateway; use rattler_shell::{ @@ -35,17 +25,14 @@ use reqwest_middleware::ClientWithMiddleware; use super::{common::EnvRoot, project::ParsedEnvironment, EnvironmentName, ExposedKey}; use crate::{ - cli::{cli_config::ChannelsConfig, has_specs::HasSpecs, project::platform}, - global::{self, channel_name_from_prefix, find_designated_package, BinDir, EnvDir}, + global::{self, BinDir, EnvDir}, prefix::Prefix, rlimit::try_increase_rlimit_to_sensible, - task::ExecutableTask, }; /// Installs global environment records pub(crate) async fn install_environment( specs: &IndexMap, - env_name: &EnvironmentName, parsed_environment: &ParsedEnvironment, authenticated_client: ClientWithMiddleware, prefix: &Prefix, @@ -163,7 +150,7 @@ pub(crate) async fn expose_executables( .map(|name| (name.to_string(), path.clone())) }) // Filters tuples to include only those whose names are in the `exposed` values - .filter(|(name, path)| parsed_environment.exposed.values().contains(&name)) + .filter(|(name, _)| parsed_environment.exposed.values().contains(&name)) .collect(); let script_mapping = parsed_environment @@ -255,6 +242,7 @@ fn get_catch_all_arg(shell: &ShellEnum) -> &str { /// For each executable provided, map it to the installation path for its global /// executable script. +#[allow(unused)] async fn map_executables_to_global_bin_scripts( package_executables: impl IntoIterator, bin_dir: &BinDir, @@ -409,6 +397,7 @@ async fn create_executable_scripts( } /// Warn user on dangerous package installations, interactive yes no prompt +#[allow(unused)] pub(crate) fn prompt_user_to_continue( packages: &IndexMap, ) -> miette::Result { @@ -514,7 +503,6 @@ pub(crate) async fn sync(config: &Config, assume_yes: bool) -> Result<(), miette if !specs_match_local_environment(&specs, prefix_records, parsed_environment.platform()) { install_environment( &specs, - &env_name, &parsed_environment, auth_client.clone(), &prefix, @@ -549,7 +537,7 @@ fn specs_match_local_environment>( ) -> bool { // Check whether all specs in the manifest are present in the installed // environment - let specs_in_manifest_are_present = specs.iter().all(|(name, spec)| { + let specs_in_manifest_are_present = specs.values().all(|spec| { prefix_records .iter() .any(|record| spec.matches(record.as_ref())) diff --git a/src/global/mod.rs b/src/global/mod.rs index 764fe402b..76930498f 100644 --- a/src/global/mod.rs +++ b/src/global/mod.rs @@ -1,16 +1,11 @@ -// TODO: remove this before merging to main -#![allow(unused)] - mod common; mod install; mod project; use crate::prefix::Prefix; -pub(crate) use common::{ - channel_name_from_prefix, find_designated_package, BinDir, EnvDir, EnvRoot, -}; +pub(crate) use common::{BinDir, EnvDir, EnvRoot}; pub(crate) use install::sync; -pub(crate) use project::{EnvironmentName, ExposedKey, Project, MANIFEST_DEFAULT_NAME}; +pub(crate) use project::{EnvironmentName, ExposedKey, Project}; use rattler_conda_types::PrefixRecord; use std::path::{Path, PathBuf}; diff --git a/src/global/project/environment.rs b/src/global/project/environment.rs index 4dc887292..974f5b1c2 100644 --- a/src/global/project/environment.rs +++ b/src/global/project/environment.rs @@ -1,9 +1,6 @@ use std::{fmt, str::FromStr}; -use indexmap::IndexMap; use miette::Diagnostic; -use pixi_spec::PixiSpec; -use rattler_conda_types::PackageName; use regex::Regex; use serde::{self, Deserialize, Deserializer, Serialize}; use thiserror::Error; diff --git a/src/global/project/manifest.rs b/src/global/project/manifest.rs index b8328dcba..90d098d11 100644 --- a/src/global/project/manifest.rs +++ b/src/global/project/manifest.rs @@ -9,6 +9,9 @@ use super::error::ManifestError; use super::MANIFEST_DEFAULT_NAME; use super::{document::ManifestSource, parsed_manifest::ParsedManifest}; +// TODO: remove +#[allow(unused)] + /// Handles the global project's manifest file. /// This struct is responsible for reading, parsing, editing, and saving the /// manifest. It encapsulates all logic related to the manifest's TOML format diff --git a/src/global/project/mod.rs b/src/global/project/mod.rs index 35789a7f6..46b078721 100644 --- a/src/global/project/mod.rs +++ b/src/global/project/mod.rs @@ -1,33 +1,26 @@ use std::{ - env, ffi::OsStr, fmt::{Debug, Formatter}, path::{Path, PathBuf}, str::FromStr, - sync::OnceLock, }; pub(crate) use environment::EnvironmentName; use indexmap::IndexMap; -use itertools::Itertools; use manifest::Manifest; -use miette::{miette, Context, IntoDiagnostic}; +use miette::{Context, IntoDiagnostic}; use once_cell::sync::Lazy; use parsed_manifest::ParsedManifest; pub(crate) use parsed_manifest::{ExposedKey, ParsedEnvironment}; -use pixi_config::{default_channel_config, home_path, Config}; +use pixi_config::{home_path, Config}; use pixi_manifest::PrioritizedChannel; -use rattler_conda_types::{Channel, NamedChannelOrUrl, PackageName, Platform, PrefixRecord}; -use rattler_digest::digest::typenum::Exp; -use rattler_repodata_gateway::Gateway; +use rattler_conda_types::{NamedChannelOrUrl, PackageName, Platform, PrefixRecord}; use regex::Regex; -use reqwest_middleware::ClientWithMiddleware; use tokio_stream::{wrappers::ReadDirStream, StreamExt}; -use url::Url; -use super::{find_executables, BinDir, EnvRoot}; +use super::{BinDir, EnvRoot}; use crate::{ - global::{common::is_text, EnvDir}, + global::{common::is_text, find_executables, EnvDir}, prefix::Prefix, }; @@ -47,12 +40,6 @@ pub(crate) const MANIFEST_DEFAULT_NAME: &str = "pixi-global.toml"; pub struct Project { /// Root folder of the project root: PathBuf, - /// Reqwest client shared for this project. - /// This is wrapped in a `OnceLock` to allow for lazy initialization. - client: OnceLock<(reqwest::Client, ClientWithMiddleware)>, - /// The repodata gateway to use for answering queries about repodata. - /// This is wrapped in a `OnceLock` to allow for lazy initialization. - repodata_gateway: OnceLock, /// The manifest for the project pub(crate) manifest: Manifest, /// The global configuration as loaded from the config file(s) @@ -189,8 +176,6 @@ async fn package_from_conda_meta( executable: &str, prefix: &Prefix, ) -> miette::Result<(Option, PrioritizedChannel, PackageName)> { - let channel_config = default_channel_config(); - let read_dir = tokio::fs::read_dir(conda_meta) .await .into_diagnostic() @@ -206,35 +191,32 @@ async fn package_from_conda_meta( .path(); // Check if the entry is a file and has a .json extension if path.is_file() && path.extension().and_then(OsStr::to_str) == Some("json") { - let content = std::fs::read_to_string(&path).into_diagnostic()?; let prefix_record = PrefixRecord::from_path(&path) .into_diagnostic() .wrap_err_with(|| format!("Could not parse json from {}", path.display()))?; - let binaries = find_executables(prefix, &prefix_record); - let Some(found_executable) = binaries + if find_executables(prefix, &prefix_record) .iter() - .find(|exe_path| exe_path.file_stem().and_then(OsStr::to_str) == Some(executable)) - else { - continue; - }; - - let platform = - match Platform::from_str(&prefix_record.repodata_record.package_record.subdir) { + .any(|exe_path| exe_path.file_stem().and_then(OsStr::to_str) == Some(executable)) + { + let platform = match Platform::from_str( + &prefix_record.repodata_record.package_record.subdir, + ) { Ok(Platform::NoArch) => None, Ok(platform) if platform == Platform::current() => None, Err(_) => None, Ok(p) => Some(p), }; - let channel: PrioritizedChannel = - NamedChannelOrUrl::from_str(&prefix_record.repodata_record.channel) - .into_diagnostic()? - .into(); + let channel: PrioritizedChannel = + NamedChannelOrUrl::from_str(&prefix_record.repodata_record.channel) + .into_diagnostic()? + .into(); - let name = prefix_record.repodata_record.package_record.name; + let name = prefix_record.repodata_record.package_record.name; - return Ok((platform, channel, name)); + return Ok((platform, channel, name)); + } } } @@ -254,8 +236,6 @@ impl Project { Self { root, - client: Default::default(), - repodata_gateway: Default::default(), manifest, config, } @@ -286,7 +266,6 @@ impl Project { let manifest_path = manifest_dir.join(MANIFEST_DEFAULT_NAME); if !manifest_path.exists() { - let warn = console::style(console::Emoji("⚠️ ", "")).yellow(); let prompt = format!( "{} You don't have a global manifest yet.\n\ Do you want to create one based on your existing installation?\n\ diff --git a/src/global/project/parsed_manifest.rs b/src/global/project/parsed_manifest.rs index 454a12221..1f753e26e 100644 --- a/src/global/project/parsed_manifest.rs +++ b/src/global/project/parsed_manifest.rs @@ -1,13 +1,11 @@ use std::fmt; -use std::path::PathBuf; use std::str::FromStr; use indexmap::{IndexMap, IndexSet}; use itertools::Itertools; -use miette::IntoDiagnostic; use pixi_manifest::PrioritizedChannel; use rattler_conda_types::{NamedChannelOrUrl, PackageName, Platform}; -use serde::de::{Deserialize, DeserializeSeed, Deserializer, MapAccess, Visitor}; +use serde::de::{Deserialize, Deserializer, Visitor}; use serde::Serialize; use serde_with::{serde_as, serde_derive::Deserialize}; @@ -39,7 +37,7 @@ where executable_name, exposed, } = data; - let mut parsed_environment = envs.entry(env_name).or_default(); + let parsed_environment = envs.entry(env_name).or_default(); parsed_environment.channels.insert(channel); parsed_environment.platform = platform; parsed_environment @@ -77,7 +75,7 @@ impl<'de> serde::Deserialize<'de> for ParsedManifest { envs: IndexMap, } - let mut manifest = TomlManifest::deserialize(deserializer)?; + let manifest = TomlManifest::deserialize(deserializer)?; // Check for duplicate keys in the exposed fields let mut exposed_keys = IndexSet::new(); diff --git a/src/lib.rs b/src/lib.rs index 711298c00..af7df88d7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,6 @@ pub mod task; mod uv_reporter; -mod repodata; mod rlimit; pub use lock_file::load_lock_file; diff --git a/src/repodata.rs b/src/repodata.rs deleted file mode 100644 index d0d1786dc..000000000 --- a/src/repodata.rs +++ /dev/null @@ -1,10 +0,0 @@ -use rattler_conda_types::Channel; - -/// Returns a friendly name for the specified channel. -pub(crate) fn friendly_channel_name(channel: &Channel) -> String { - channel - .name - .as_ref() - .map(String::from) - .unwrap_or_else(|| channel.canonical_name()) -}