From 98a8515ac8a19c1938c2e67ed9a555f21a1717d0 Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Fri, 26 Jul 2024 19:41:02 +0200 Subject: [PATCH 1/8] feat: refactor pixi::consts and pixi::config into seperate crates --- Cargo.lock | 36 +++++++++ Cargo.toml | 8 +- crates/pixi_config/Cargo.toml | 31 ++++++++ crates/pixi_config/src/consts.rs | 0 .../pixi_config/src/lib.rs | 30 +++++++- crates/pixi_consts/Cargo.toml | 17 +++++ {src => crates/pixi_consts/src}/consts.rs | 2 +- crates/pixi_consts/src/lib.rs | 1 + crates/pixi_manifest/Cargo.toml | 1 + crates/pixi_manifest/src/consts.rs | 6 +- crates/pixi_manifest/src/pypi/pypi_options.rs | 2 +- src/cli/add.rs | 2 +- src/cli/clean.rs | 6 +- src/cli/config.rs | 12 +-- src/cli/exec.rs | 4 +- src/cli/global/common.rs | 8 +- src/cli/global/install.rs | 5 +- src/cli/global/list.rs | 2 +- src/cli/global/upgrade.rs | 2 +- src/cli/global/upgrade_all.rs | 2 +- src/cli/info.rs | 12 +-- src/cli/init.rs | 4 +- src/cli/install.rs | 2 +- src/cli/remove.rs | 2 +- src/cli/run.rs | 2 +- src/cli/search.rs | 5 +- src/cli/self_update.rs | 2 +- src/cli/shell.rs | 4 +- src/cli/shell_hook.rs | 2 +- src/cli/update.rs | 17 ++--- src/environment.rs | 6 +- src/fancy_display.rs | 2 +- src/install_pypi.rs | 18 +++-- src/lib.rs | 2 - src/lock_file/outdated.rs | 3 +- src/lock_file/resolve/pypi.rs | 2 +- src/lock_file/resolve/resolver_provider.rs | 10 +-- .../resolve/uv_resolution_context.rs | 11 ++- src/lock_file/update.rs | 6 +- src/project/environment.rs | 5 +- src/project/grouped_environment.rs | 2 +- src/project/mod.rs | 14 ++-- src/project/repodata.rs | 28 +------ src/pypi_mapping/mod.rs | 3 +- src/repodata.rs | 6 +- src/task/executable_task.rs | 6 +- src/utils/conda_environment_file.rs | 2 +- src/utils/reqwest.rs | 2 +- tests/add_tests.rs | 74 +++++++++++++++---- tests/common/mod.rs | 2 +- tests/install_tests.rs | 57 ++++++++------ tests/update_tests.rs | 50 ++++++++++--- 52 files changed, 367 insertions(+), 173 deletions(-) create mode 100644 crates/pixi_config/Cargo.toml create mode 100644 crates/pixi_config/src/consts.rs rename src/config.rs => crates/pixi_config/src/lib.rs (97%) create mode 100644 crates/pixi_consts/Cargo.toml rename {src => crates/pixi_consts/src}/consts.rs (100%) create mode 100644 crates/pixi_consts/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index efba7947d..94f767fb4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3445,6 +3445,8 @@ dependencies = [ "pep440_rs", "pep508_rs", "percent-encoding", + "pixi_config", + "pixi_consts", "pixi_manifest", "pixi_pty", "platform-tags", @@ -3500,6 +3502,39 @@ dependencies = [ "zip 0.6.6", ] +[[package]] +name = "pixi_config" +version = "0.1.0" +dependencies = [ + "clap", + "console", + "dirs", + "insta", + "itertools 0.12.1", + "miette 7.2.0", + "pixi_consts", + "rattler", + "rattler_conda_types", + "rattler_repodata_gateway", + "rstest", + "serde", + "serde_ignored", + "serde_json", + "toml_edit 0.22.13", + "tracing", + "url", +] + +[[package]] +name = "pixi_consts" +version = "0.1.0" +dependencies = [ + "console", + "lazy_static", + "pixi_manifest", + "url", +] + [[package]] name = "pixi_manifest" version = "0.1.0" @@ -3508,6 +3543,7 @@ dependencies = [ "indexmap 2.2.6", "insta", "itertools 0.12.1", + "lazy_static", "miette 7.2.0", "pep440_rs", "pep508_rs", diff --git a/Cargo.toml b/Cargo.toml index 88c3c2b67..dcf26c447 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -110,6 +110,10 @@ winapi = { version = "0.3.9", default-features = false } xxhash-rust = "0.8.10" zip = { version = "0.6.6", default-features = false } +pixi_config = { path = "crates/pixi_config" } +pixi_consts = { path = "crates/pixi_consts" } +pixi_manifest = { path = "crates/pixi_manifest" } + [package] authors.workspace = true description = "A package management and workflow tool" @@ -208,6 +212,9 @@ rattler_repodata_gateway = { workspace = true, features = [ rattler_shell = { workspace = true, features = ["sysinfo"] } rattler_solve = { workspace = true, features = ["resolvo", "serde"] } +pixi_config = { workspace = true } +pixi_consts = { workspace = true } +pixi_manifest = { workspace = true } rattler_virtual_packages = { workspace = true } regex = { workspace = true } reqwest = { workspace = true, features = [ @@ -249,7 +256,6 @@ uv-types = { workspace = true } xxhash-rust = { workspace = true } zip = { workspace = true, features = ["deflate", "time"] } -pixi_manifest = { path = "crates/pixi_manifest" } [target.'cfg(unix)'.dependencies] libc = { workspace = true, default-features = false } diff --git a/crates/pixi_config/Cargo.toml b/crates/pixi_config/Cargo.toml new file mode 100644 index 000000000..c0e37d040 --- /dev/null +++ b/crates/pixi_config/Cargo.toml @@ -0,0 +1,31 @@ +[package] +authors.workspace = true +description = "Contains the global configuration for use in a pixi project" +edition.workspace = true +homepage.workspace = true +license.workspace = true +name = "pixi_config" +readme.workspace = true +repository.workspace = true +version = "0.1.0" + +[dependencies] +clap = { workspace = true, features = ["std", "derive", "env"] } +console = { workspace = true } +dirs = { workspace = true } +itertools = { workspace = true } +miette = { workspace = true } +pixi_consts = { workspace = true } +rattler = { workspace = true } +rattler_conda_types = { workspace = true } +rattler_repodata_gateway = { workspace = true } +serde = { workspace = true } +serde_ignored = { workspace = true } +serde_json = { workspace = true } +toml_edit = { workspace = true, features = ["serde"] } +tracing = { workspace = true } +url = { workspace = true } + +[dev-dependencies] +insta = { workspace = true, features = ["yaml"] } +rstest = { workspace = true } diff --git a/crates/pixi_config/src/consts.rs b/crates/pixi_config/src/consts.rs new file mode 100644 index 000000000..e69de29bb diff --git a/src/config.rs b/crates/pixi_config/src/lib.rs similarity index 97% rename from src/config.rs rename to crates/pixi_config/src/lib.rs index 7bfcf3cc8..5c7178f2f 100644 --- a/src/config.rs +++ b/crates/pixi_config/src/lib.rs @@ -10,14 +10,21 @@ use std::{ use clap::{ArgAction, Parser}; use itertools::Itertools; use miette::{miette, Context, IntoDiagnostic}; +use pixi_consts::consts; use rattler_conda_types::{ version_spec::{EqualityOperator, LogicalOperator, RangeOperator}, ChannelConfig, NamedChannelOrUrl, Version, VersionBumpType, VersionSpec, }; +use rattler_repodata_gateway::SourceConfig; use serde::{de::IntoDeserializer, Deserialize, Serialize}; use url::Url; -use crate::{consts, util::default_channel_config}; +/// TODO: maybe remove this duplicate from `src/util.rs` at some point +pub fn default_channel_config() -> ChannelConfig { + ChannelConfig::default_with_root_dir( + std::env::current_dir().expect("Could not retrieve the current directory"), + ) +} /// Determines the default author based on the default git author. Both the name /// and the email address of the author are returned. @@ -63,6 +70,7 @@ pub fn home_path() -> Option { } } +// TODO(tim): I think we should move this to another crate, dont know if global config is really correct /// Returns the default cache directory. /// Most important is the `PIXI_CACHE_DIR` environment variable. /// - If that is not set, the `RATTLER_CACHE_DIR` environment variable is used. @@ -888,6 +896,26 @@ pub fn config_path_global() -> Vec { .collect() } +impl<'c> From<&'c Config> for rattler_repodata_gateway::ChannelConfig { + fn from(config: &'c Config) -> Self { + let default_source_config = config + .repodata_config + .as_ref() + .map(|config| SourceConfig { + jlap_enabled: !config.disable_jlap.unwrap_or(false), + zstd_enabled: !config.disable_zstd.unwrap_or(false), + bz2_enabled: !config.disable_bzip2.unwrap_or(false), + cache_action: Default::default(), + }) + .unwrap_or_default(); + + Self { + default: default_source_config, + per_channel: Default::default(), + } + } +} + #[cfg(test)] mod tests { use rstest::rstest; diff --git a/crates/pixi_consts/Cargo.toml b/crates/pixi_consts/Cargo.toml new file mode 100644 index 000000000..9f613bd3f --- /dev/null +++ b/crates/pixi_consts/Cargo.toml @@ -0,0 +1,17 @@ +[package] +authors.workspace = true +edition.workspace = true +homepage.workspace = true +license.workspace = true +name = "pixi_consts" +readme.workspace = true +repository.workspace = true +version = "0.1.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +console = { workspace = true } +lazy_static = { workspace = true } +pixi_manifest = { workspace = true } +url = { workspace = true } diff --git a/src/consts.rs b/crates/pixi_consts/src/consts.rs similarity index 100% rename from src/consts.rs rename to crates/pixi_consts/src/consts.rs index c6adfb855..eedfedbfd 100644 --- a/src/consts.rs +++ b/crates/pixi_consts/src/consts.rs @@ -8,9 +8,9 @@ pub use pixi_manifest::consts::*; pub const PROJECT_MANIFEST: &str = "pixi.toml"; pub const PYPROJECT_MANIFEST: &str = "pyproject.toml"; pub const PROJECT_LOCK_FILE: &str = "pixi.lock"; +pub const CONFIG_FILE: &str = "config.toml"; pub const PIXI_DIR: &str = ".pixi"; pub const PIXI_VERSION: &str = env!("CARGO_PKG_VERSION"); -pub const CONFIG_FILE: &str = "config.toml"; pub const PREFIX_FILE_NAME: &str = "pixi_env_prefix"; pub const ENVIRONMENTS_DIR: &str = "envs"; pub const SOLVE_GROUP_ENVIRONMENTS_DIR: &str = "solve-group-envs"; diff --git a/crates/pixi_consts/src/lib.rs b/crates/pixi_consts/src/lib.rs new file mode 100644 index 000000000..b99566220 --- /dev/null +++ b/crates/pixi_consts/src/lib.rs @@ -0,0 +1 @@ +pub mod consts; diff --git a/crates/pixi_manifest/Cargo.toml b/crates/pixi_manifest/Cargo.toml index 224ccd637..d0102279e 100644 --- a/crates/pixi_manifest/Cargo.toml +++ b/crates/pixi_manifest/Cargo.toml @@ -11,6 +11,7 @@ version = "0.1.0" [dependencies] indexmap = { workspace = true } itertools = { workspace = true } +lazy_static = { workspace = true } pep440_rs = { workspace = true } pep508_rs = { workspace = true } regex = { workspace = true } diff --git a/crates/pixi_manifest/src/consts.rs b/crates/pixi_manifest/src/consts.rs index c5df976fe..86daae6a6 100644 --- a/crates/pixi_manifest/src/consts.rs +++ b/crates/pixi_manifest/src/consts.rs @@ -1,3 +1,5 @@ +use url::Url; + pub const PYPI_DEPENDENCIES: &str = "pypi-dependencies"; pub const DEFAULT_ENVIRONMENT_NAME: &str = "default"; pub const PROJECT_MANIFEST: &str = "pixi.toml"; @@ -5,4 +7,6 @@ pub const PYPROJECT_MANIFEST: &str = "pyproject.toml"; pub const DEFAULT_FEATURE_NAME: &str = DEFAULT_ENVIRONMENT_NAME; pub const PYPROJECT_PIXI_PREFIX: &str = "tool.pixi"; -pub const DEFAULT_PYPI_INDEX_URL: &str = "https://pypi.org/simple"; +lazy_static::lazy_static! { + pub static ref DEFAULT_PYPI_INDEX_URL: Url = Url::parse("https://pypi.org/simple").unwrap(); +} diff --git a/crates/pixi_manifest/src/pypi/pypi_options.rs b/crates/pixi_manifest/src/pypi/pypi_options.rs index 9c791d8b0..5f1f3d9e2 100644 --- a/crates/pixi_manifest/src/pypi/pypi_options.rs +++ b/crates/pixi_manifest/src/pypi/pypi_options.rs @@ -126,7 +126,7 @@ impl From for rattler_lock::PypiIndexes { fn from(value: PypiOptions) -> Self { let primary_index = value .index_url - .unwrap_or(consts::DEFAULT_PYPI_INDEX_URL.parse().unwrap()); + .unwrap_or(consts::DEFAULT_PYPI_INDEX_URL.clone()); Self { indexes: iter::once(primary_index) .chain(value.extra_index_urls.into_iter().flatten()) diff --git a/src/cli/add.rs b/src/cli/add.rs index 1b7a71029..e3af24310 100644 --- a/src/cli/add.rs +++ b/src/cli/add.rs @@ -15,7 +15,6 @@ use rattler_lock::{LockFile, Package}; use super::has_specs::HasSpecs; use crate::{ - config::ConfigCli, environment::{verify_prefix_location_unchanged, LockFileUsage}, load_lock_file, lock_file::{filter_lock_file, LockFileDerivedData, UpdateContext}, @@ -23,6 +22,7 @@ use crate::{ grouped_environment::GroupedEnvironment, has_features::HasFeatures, DependencyType, Project, }, }; +use pixi_config::ConfigCli; /// Adds dependencies to the project /// diff --git a/src/cli/clean.rs b/src/cli/clean.rs index 1396d3612..21b8a84e5 100644 --- a/src/cli/clean.rs +++ b/src/cli/clean.rs @@ -1,5 +1,7 @@ +use crate::Project; /// Command to clean the parts of your system which are touched by pixi. -use crate::{config, consts, Project}; +use pixi_config; +use pixi_consts::consts; use pixi_manifest::EnvironmentName; use std::path::PathBuf; use std::time::Duration; @@ -105,7 +107,7 @@ pub async fn execute(args: Args) -> miette::Result<()> { /// Clean the pixi cache folders. async fn clean_cache(args: CacheArgs) -> miette::Result<()> { - let cache_dir = config::get_cache_dir()?; + let cache_dir = pixi_config::get_cache_dir()?; let mut dirs = vec![]; if args.pypi { diff --git a/src/cli/config.rs b/src/cli/config.rs index 6b85e328f..d51014709 100644 --- a/src/cli/config.rs +++ b/src/cli/config.rs @@ -2,12 +2,12 @@ use std::{path::PathBuf, str::FromStr}; use clap::Parser; use miette::{IntoDiagnostic, WrapErr}; +use pixi_config; +use pixi_config::Config; +use pixi_consts::consts; use rattler_conda_types::NamedChannelOrUrl; -use crate::{ - config::{self, Config}, - consts, project, -}; +use crate::project; #[derive(Parser, Debug)] enum Subcommand { @@ -222,7 +222,7 @@ fn load_config(common_args: &CommonArgs) -> miette::Result { fn determine_config_write_path(common_args: &CommonArgs) -> miette::Result { let write_path = if common_args.system { - config::config_path_system() + pixi_config::config_path_system() } else { if let Some(root) = determine_project_root(common_args)? { if !common_args.global { @@ -230,7 +230,7 @@ fn determine_config_write_path(common_args: &CommonArgs) -> miette::Result miette::Result<()> { let config = Config::with_cli_config(&args.config); - let cache_dir = config::get_cache_dir().context("failed to determine cache directory")?; + let cache_dir = pixi_config::get_cache_dir().context("failed to determine cache directory")?; let mut command_args = args.command.iter(); let command = command_args.next().ok_or_else(|| miette::miette!(help ="i.e when specifying specs explicitly use a command at the end: `pixi exec -s python==3.12 python`", "missing required command to execute",))?; diff --git a/src/cli/global/common.rs b/src/cli/global/common.rs index e2e620311..97ec78af7 100644 --- a/src/cli/global/common.rs +++ b/src/cli/global/common.rs @@ -9,12 +9,8 @@ use rattler_repodata_gateway::sparse::SparseRepoData; use rattler_solve::{resolvo, SolverImpl, SolverTask}; use reqwest_middleware::ClientWithMiddleware; -use crate::{ - config::{home_path, Config}, - prefix::Prefix, - repodata, - utils::reqwest::build_reqwest_clients, -}; +use crate::{prefix::Prefix, repodata, utils::reqwest::build_reqwest_clients}; +use pixi_config::{home_path, Config}; /// Global binaries directory, default to `$HOME/.pixi/bin` pub struct BinDir(pub PathBuf); diff --git a/src/cli/global/install.rs b/src/cli/global/install.rs index ae16da9d7..9cd8b3fc0 100644 --- a/src/cli/global/install.rs +++ b/src/cli/global/install.rs @@ -25,11 +25,10 @@ use super::common::{ }; use crate::{ cli::has_specs::HasSpecs, - config, - config::{Config, ConfigCli}, prefix::Prefix, progress::{await_in_progress, global_multi_progress}, }; +use pixi_config::{self, Config, ConfigCli}; /// Installs the defined package in a global accessible location. #[derive(Parser, Debug)] @@ -404,7 +403,7 @@ pub(super) async fn globally_install_package( let prefix = Prefix::new(bin_prefix); // Install the environment - let package_cache = PackageCache::new(config::get_cache_dir()?.join("pkgs")); + let package_cache = PackageCache::new(pixi_config::get_cache_dir()?.join("pkgs")); let result = await_in_progress("creating virtual environment", |pb| { Installer::new() diff --git a/src/cli/global/list.rs b/src/cli/global/list.rs index a2e294eb8..ea6212a63 100644 --- a/src/cli/global/list.rs +++ b/src/cli/global/list.rs @@ -6,8 +6,8 @@ use itertools::Itertools; use miette::IntoDiagnostic; use rattler_conda_types::PackageName; -use crate::config::home_path; use crate::prefix::Prefix; +use pixi_config::home_path; use super::common::{bin_env_dir, find_designated_package, BinDir, BinEnvDir}; use super::install::{find_and_map_executable_scripts, BinScriptMapping}; diff --git a/src/cli/global/upgrade.rs b/src/cli/global/upgrade.rs index 67f72fbef..de1785b63 100644 --- a/src/cli/global/upgrade.rs +++ b/src/cli/global/upgrade.rs @@ -14,9 +14,9 @@ use super::{ }; use crate::{ cli::has_specs::HasSpecs, - config::Config, progress::{global_multi_progress, long_running_progress_style}, }; +use pixi_config::Config; /// Upgrade specific package which is installed globally. #[derive(Parser, Debug)] diff --git a/src/cli/global/upgrade_all.rs b/src/cli/global/upgrade_all.rs index e08df18e0..37647ac0a 100644 --- a/src/cli/global/upgrade_all.rs +++ b/src/cli/global/upgrade_all.rs @@ -3,7 +3,7 @@ use indexmap::IndexMap; use rattler_conda_types::{MatchSpec, NamedChannelOrUrl, Platform}; -use crate::config::{Config, ConfigCli}; +use pixi_config::{Config, ConfigCli}; use super::{list::list_global_packages, upgrade::upgrade_packages}; diff --git a/src/cli/info.rs b/src/cli/info.rs index 7cd2a6f4c..1737b7a6c 100644 --- a/src/cli/info.rs +++ b/src/cli/info.rs @@ -4,6 +4,8 @@ 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 rattler_conda_types::{GenericVirtualPackage, Platform}; use rattler_networking::authentication_storage; @@ -13,8 +15,8 @@ use serde_with::{serde_as, DisplayFromStr}; use tokio::task::spawn_blocking; use crate::{ - config, consts, fancy_display::FancyDisplay, progress::await_in_progress, - project::has_features::HasFeatures, task::TaskName, Project, + fancy_display::FancyDisplay, progress::await_in_progress, project::has_features::HasFeatures, + task::TaskName, Project, }; static WIDTH: usize = 18; @@ -292,7 +294,7 @@ pub async fn execute(args: Args) -> miette::Result<()> { let (pixi_folder_size, cache_size) = if args.extended { let env_dir = project.as_ref().map(|p| p.pixi_dir()); - let cache_dir = config::get_cache_dir()?; + let cache_dir = pixi_config::get_cache_dir()?; await_in_progress("fetching directory sizes", |_| { spawn_blocking(move || { let env_size = env_dir.and_then(|env| dir_size(env).ok()); @@ -363,7 +365,7 @@ pub async fn execute(args: Args) -> miette::Result<()> { let config = project .map(|p| p.config().clone()) - .unwrap_or_else(config::Config::load_global); + .unwrap_or_else(pixi_config::Config::load_global); let auth_file = config .authentication_override_file() @@ -378,7 +380,7 @@ pub async fn execute(args: Args) -> miette::Result<()> { platform: Platform::current().to_string(), virtual_packages, version: consts::PIXI_VERSION.to_string(), - cache_dir: Some(config::get_cache_dir()?), + cache_dir: Some(pixi_config::get_cache_dir()?), cache_size, auth_dir: auth_file, project_info, diff --git a/src/cli/init.rs b/src/cli/init.rs index 7f825b933..a2867b6cc 100644 --- a/src/cli/init.rs +++ b/src/cli/init.rs @@ -12,12 +12,12 @@ use rattler_conda_types::{NamedChannelOrUrl, Platform}; use url::Url; use crate::{ - config::{get_default_author, Config}, - consts, environment::{get_up_to_date_prefix, LockFileUsage}, utils::conda_environment_file::CondaEnvFile, Project, }; +use pixi_config::{get_default_author, Config}; +use pixi_consts::consts; /// Creates a new project #[derive(Parser, Debug)] diff --git a/src/cli/install.rs b/src/cli/install.rs index 3096b94a7..598f3d86b 100644 --- a/src/cli/install.rs +++ b/src/cli/install.rs @@ -1,9 +1,9 @@ -use crate::config::ConfigCli; use crate::environment::get_up_to_date_prefix; use crate::fancy_display::FancyDisplay; use crate::Project; use clap::Parser; use itertools::Itertools; +use pixi_config::ConfigCli; use std::path::PathBuf; /// Install all dependencies diff --git a/src/cli/remove.rs b/src/cli/remove.rs index a8348301e..20ab929c2 100644 --- a/src/cli/remove.rs +++ b/src/cli/remove.rs @@ -1,9 +1,9 @@ use clap::Parser; -use crate::config::ConfigCli; use crate::environment::get_up_to_date_prefix; use crate::DependencyType; use crate::Project; +use pixi_config::ConfigCli; use super::add::DependencyConfig; use super::has_specs::HasSpecs; diff --git a/src/cli/run.rs b/src/cli/run.rs index 59c251092..6524fb834 100644 --- a/src/cli/run.rs +++ b/src/cli/run.rs @@ -3,11 +3,11 @@ use std::collections::HashSet; use std::convert::identity; use std::{collections::HashMap, path::PathBuf, string::String}; -use crate::config::ConfigCli; use clap::Parser; use dialoguer::theme::ColorfulTheme; use itertools::Itertools; use miette::{Context, Diagnostic, IntoDiagnostic}; +use pixi_config::ConfigCli; use crate::activation::CurrentEnvVarBehavior; use crate::environment::verify_prefix_location_unchanged; diff --git a/src/cli/search.rs b/src/cli/search.rs index e2a19aaaf..5e8138be4 100644 --- a/src/cli/search.rs +++ b/src/cli/search.rs @@ -16,9 +16,10 @@ use strsim::jaro; use tokio::task::spawn_blocking; use crate::{ - config::Config, progress::await_in_progress, repodata::fetch_sparse_repodata, - util::default_channel_config, utils::reqwest::build_reqwest_clients, HasFeatures, Project, + progress::await_in_progress, repodata::fetch_sparse_repodata, util::default_channel_config, + utils::reqwest::build_reqwest_clients, HasFeatures, Project, }; +use pixi_config::Config; /// Search a conda package /// diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index 45030a0fc..94633f0c1 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -6,8 +6,8 @@ use std::{ use flate2::read::GzDecoder; use tar::Archive; -use crate::consts; use miette::{Context, IntoDiagnostic}; +use pixi_consts::consts; use reqwest::Client; use serde::Deserialize; diff --git a/src/cli/shell.rs b/src/cli/shell.rs index 7c8d23616..573c639ad 100644 --- a/src/cli/shell.rs +++ b/src/cli/shell.rs @@ -9,11 +9,11 @@ use rattler_shell::{ }; use crate::{ - activation::CurrentEnvVarBehavior, cli::LockFileUsageArgs, config::ConfigCliPrompt, - environment::get_up_to_date_prefix, + activation::CurrentEnvVarBehavior, cli::LockFileUsageArgs, environment::get_up_to_date_prefix, project::virtual_packages::verify_current_platform_has_required_virtual_packages, prompt, Project, }; +use pixi_config::ConfigCliPrompt; use pixi_manifest::EnvironmentName; #[cfg(target_family = "unix")] use pixi_pty::unix::PtySession; diff --git a/src/cli/shell_hook.rs b/src/cli/shell_hook.rs index a50fe91bd..a6d369f6d 100644 --- a/src/cli/shell_hook.rs +++ b/src/cli/shell_hook.rs @@ -2,6 +2,7 @@ use std::{collections::HashMap, default::Default, path::PathBuf}; use clap::Parser; use miette::IntoDiagnostic; +use pixi_config::ConfigCliPrompt; use rattler_shell::{ activation::{ActivationVariables, PathModificationBehavior}, shell::ShellEnum, @@ -12,7 +13,6 @@ use serde_json; use crate::{ activation::{get_activator, CurrentEnvVarBehavior}, cli::LockFileUsageArgs, - config::ConfigCliPrompt, environment::get_up_to_date_prefix, project::Environment, HasFeatures, Project, diff --git a/src/cli/update.rs b/src/cli/update.rs index d5a3a91cd..f69756425 100644 --- a/src/cli/update.rs +++ b/src/cli/update.rs @@ -7,9 +7,6 @@ use std::{ }; use crate::{ - config::ConfigCli, - consts, - consts::{CondaEmoji, PypiEmoji}, load_lock_file, lock_file::{filter_lock_file, UpdateContext}, HasFeatures, Project, @@ -19,6 +16,8 @@ use clap::Parser; use indexmap::IndexMap; use itertools::{Either, Itertools}; use miette::{Context, IntoDiagnostic, MietteDiagnostic}; +use pixi_config::ConfigCli; +use pixi_consts::consts; use pixi_manifest::EnvironmentName; use rattler_conda_types::Platform; use rattler_lock::{LockFile, Package}; @@ -538,8 +537,8 @@ impl LockFileDiff { "{} {} {}\t{}\t\t", console::style("+").green(), match p { - Package::Conda(_) => CondaEmoji.to_string(), - Package::Pypi(_) => PypiEmoji.to_string(), + Package::Conda(_) => consts::CondaEmoji.to_string(), + Package::Pypi(_) => consts::PypiEmoji.to_string(), }, p.name(), format_package_identifier(p) @@ -551,8 +550,8 @@ impl LockFileDiff { "{} {} {}\t{}\t\t", console::style("-").red(), match p { - Package::Conda(_) => CondaEmoji.to_string(), - Package::Pypi(_) => PypiEmoji.to_string(), + Package::Conda(_) => consts::CondaEmoji.to_string(), + Package::Pypi(_) => consts::PypiEmoji.to_string(), }, p.name(), format_package_identifier(p) @@ -576,7 +575,7 @@ impl LockFileDiff { format!( "{} {} {}\t{} {}\t->\t{} {}", console::style("~").yellow(), - CondaEmoji, + consts::CondaEmoji, name, choose_style(&previous.version.as_str(), ¤t.version.as_str()), choose_style(previous.build.as_str(), current.build.as_str()), @@ -591,7 +590,7 @@ impl LockFileDiff { format!( "{} {} {}\t{}\t->\t{}", console::style("~").yellow(), - PypiEmoji, + consts::PypiEmoji, name, choose_style( &previous.version.to_string(), diff --git a/src/environment.rs b/src/environment.rs index 242f44d6c..1a4d288a1 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -1,10 +1,9 @@ -use crate::consts::PIXI_UV_INSTALLER; use crate::fancy_display::FancyDisplay; use crate::lock_file::UvResolutionContext; use crate::progress::{await_in_progress, global_multi_progress}; use crate::project::has_features::HasFeatures; use crate::{ - consts, install_pypi, + install_pypi, lock_file::UpdateLockFileOptions, prefix::Prefix, progress, @@ -14,6 +13,7 @@ use crate::{ use dialoguer::theme::ColorfulTheme; use distribution_types::{InstalledDist, Name}; use miette::{IntoDiagnostic, WrapErr}; +use pixi_consts::consts; use pixi_manifest::{EnvironmentName, SystemRequirements}; use rattler::install::{DefaultProgressFormatter, IndicatifReporter, Installer}; @@ -397,7 +397,7 @@ async fn uninstall_outdated_site_packages(site_packages: &Path) -> miette::Resul // Only remove if have actually installed it // by checking the installer - if installer.unwrap_or_default() == PIXI_UV_INSTALLER { + if installer.unwrap_or_default() == consts::PIXI_UV_INSTALLER { installed.push(installed_dist); } } diff --git a/src/fancy_display.rs b/src/fancy_display.rs index e07a7e4f2..f940fcfcc 100644 --- a/src/fancy_display.rs +++ b/src/fancy_display.rs @@ -1,6 +1,6 @@ use console::StyledObject; -use crate::consts; +use pixi_consts::consts; pub trait FancyDisplay { fn fancy_display(&self) -> StyledObject<&str>; diff --git a/src/install_pypi.rs b/src/install_pypi.rs index 9a167ca3b..0daae7fee 100644 --- a/src/install_pypi.rs +++ b/src/install_pypi.rs @@ -36,12 +36,12 @@ use uv_types::HashStrategy; use crate::utils::uv::locked_indexes_to_index_locations; use crate::{ conda_pypi_clobber::PypiCondaClobberRegistry, - consts::{DEFAULT_PYPI_INDEX_URL, PIXI_UV_INSTALLER, PROJECT_MANIFEST}, lock_file::UvResolutionContext, prefix::Prefix, pypi_tags::{get_pypi_tags, is_python_record}, uv_reporter::{UvReporter, UvReporterOptions}, }; +use pixi_consts::consts; type CombinedPypiPackageData = (PypiPackageData, PypiPackageEnvironmentData); @@ -209,7 +209,7 @@ fn convert_to_dist( // out but it would require adding the indexes to // the lock file index: IndexUrl::Pypi(VerbatimUrl::from_url( - DEFAULT_PYPI_INDEX_URL.clone(), + consts::DEFAULT_PYPI_INDEX_URL.clone(), )), }], best_wheel_index: 0, @@ -221,7 +221,9 @@ fn convert_to_dist( version: pkg.version.clone(), file: Box::new(file), // This should be fine because currently it is only used for caching - index: IndexUrl::Pypi(VerbatimUrl::from_url(DEFAULT_PYPI_INDEX_URL.clone())), + index: IndexUrl::Pypi(VerbatimUrl::from_url( + consts::DEFAULT_PYPI_INDEX_URL.clone(), + )), // I don't think this really matters for the install wheels: vec![], })) @@ -489,7 +491,7 @@ fn whats_the_plan<'a>( // Empty string if no installer or any other error .map_or(String::new(), |f| f.unwrap_or_default()); - if required_map_copy.contains_key(&dist.name()) && installer != PIXI_UV_INSTALLER { + if required_map_copy.contains_key(&dist.name()) && installer != consts::PIXI_UV_INSTALLER { // We are managing the package but something else has installed a version // let's re-install to make sure that we have the **correct** version reinstalls.push(dist.clone()); @@ -497,7 +499,7 @@ fn whats_the_plan<'a>( } if let Some(pkg) = pkg { - if installer == PIXI_UV_INSTALLER { + if installer == consts::PIXI_UV_INSTALLER { // Check if we need to reinstall match need_reinstall(dist, pkg, python_version)? { ValidateInstall::Keep => { @@ -529,7 +531,7 @@ fn whats_the_plan<'a>( } else { remote.push(convert_to_dist(pkg, lock_file_dir).into_diagnostic()?); } - } else if installer != PIXI_UV_INSTALLER { + } else if installer != consts::PIXI_UV_INSTALLER { // Ignore packages that we are not managed by us continue; } else { @@ -586,7 +588,7 @@ pub async fn update_python_distributions( platform: Platform, ) -> miette::Result<()> { let start = std::time::Instant::now(); - + use pixi_consts::consts::PROJECT_MANIFEST; // Determine the current environment markers. let python_record = conda_package .iter() @@ -882,7 +884,7 @@ pub async fn update_python_distributions( let start = std::time::Instant::now(); uv_installer::Installer::new(&venv) .with_link_mode(LinkMode::default()) - .with_installer_name(Some(PIXI_UV_INSTALLER.to_string())) + .with_installer_name(Some(consts::PIXI_UV_INSTALLER.to_string())) .with_reporter(UvReporter::new(options)) .install(&wheels) .unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 265290136..e9d53593b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,6 @@ pub mod activation; pub mod cli; pub(crate) mod conda_pypi_clobber; -pub mod config; -pub mod consts; mod environment; mod install_pypi; mod install_wheel; diff --git a/src/lock_file/outdated.rs b/src/lock_file/outdated.rs index 0d2e3a482..b81b7dd8d 100644 --- a/src/lock_file/outdated.rs +++ b/src/lock_file/outdated.rs @@ -2,8 +2,9 @@ use super::{verify_environment_satisfiability, verify_platform_satisfiability}; use crate::fancy_display::FancyDisplay; use crate::lock_file::satisfiability::EnvironmentUnsat; use crate::project::has_features::HasFeatures; -use crate::{consts, project::Environment, project::SolveGroup, Project}; +use crate::{project::Environment, project::SolveGroup, Project}; use itertools::Itertools; +use pixi_consts::consts; use rattler_conda_types::Platform; use rattler_lock::{LockFile, Package}; use std::collections::{HashMap, HashSet}; diff --git a/src/lock_file/resolve/pypi.rs b/src/lock_file/resolve/pypi.rs index 1d23dd94c..fc7f7aa28 100644 --- a/src/lock_file/resolve/pypi.rs +++ b/src/lock_file/resolve/pypi.rs @@ -1,4 +1,3 @@ -use crate::consts::PROJECT_MANIFEST; use crate::lock_file::resolve::resolver_provider::CondaResolverProvider; use crate::uv_reporter::{UvReporter, UvReporterOptions}; use std::collections::HashMap; @@ -268,6 +267,7 @@ pub async fn resolve_pypi( .collect::, _>>() .into_diagnostic()?; + use pixi_consts::consts::PROJECT_MANIFEST; // Determine the python interpreter that is installed as part of the conda packages. let python_record = locked_conda_records .iter() diff --git a/src/lock_file/resolve/resolver_provider.rs b/src/lock_file/resolve/resolver_provider.rs index 6c02aebee..1d5daa2ce 100644 --- a/src/lock_file/resolve/resolver_provider.rs +++ b/src/lock_file/resolve/resolver_provider.rs @@ -9,6 +9,7 @@ use distribution_types::{ }; use futures::{Future, FutureExt}; use pep508_rs::{PackageName, VerbatimUrl}; +use pixi_consts::consts; use rattler_conda_types::RepoDataRecord; use uv_distribution::{ArchiveMetadata, Metadata}; use uv_resolver::{ @@ -17,10 +18,7 @@ use uv_resolver::{ }; use uv_types::BuildContext; -use crate::{ - consts::DEFAULT_PYPI_INDEX_URL, - lock_file::{records_by_name::HasNameVersion, PypiPackageIdentifier}, -}; +use crate::lock_file::{records_by_name::HasNameVersion, PypiPackageIdentifier}; pub(super) struct CondaResolverProvider<'a, Context: BuildContext> { pub(super) fallback: DefaultResolverProvider<'a, Context>, @@ -63,7 +61,9 @@ impl<'a, Context: BuildContext> ResolverProvider for CondaResolverProvider<'a, C .parse() .expect("could not convert to pypi version"), file: Box::new(file), - index: IndexUrl::Pypi(VerbatimUrl::from_url(DEFAULT_PYPI_INDEX_URL.clone())), + index: IndexUrl::Pypi(VerbatimUrl::from_url( + consts::DEFAULT_PYPI_INDEX_URL.clone(), + )), wheels: vec![], }; diff --git a/src/lock_file/resolve/uv_resolution_context.rs b/src/lock_file/resolve/uv_resolution_context.rs index 68f7cf76b..bd0b86c0f 100644 --- a/src/lock_file/resolve/uv_resolution_context.rs +++ b/src/lock_file/resolve/uv_resolution_context.rs @@ -5,10 +5,9 @@ use uv_cache::Cache; use uv_configuration::{BuildOptions, Concurrency}; use uv_types::{HashStrategy, InFlight}; -use crate::{ - config::{self, get_cache_dir}, - consts, Project, -}; +use crate::Project; +use pixi_config::{self, get_cache_dir}; +use pixi_consts::consts; /// Objects that are needed for resolutions which can be shared between different resolutions. #[derive(Clone)] @@ -34,11 +33,11 @@ impl UvResolutionContext { let cache = Cache::from_path(uv_cache); let keyring_provider = match project.config().pypi_config().use_keyring() { - config::KeyringProvider::Subprocess => { + pixi_config::KeyringProvider::Subprocess => { tracing::info!("using uv keyring (subprocess) provider"); uv_configuration::KeyringProviderType::Subprocess } - config::KeyringProvider::Disabled => { + pixi_config::KeyringProvider::Disabled => { tracing::info!("uv keyring provider is disabled"); uv_configuration::KeyringProviderType::Disabled } diff --git a/src/lock_file/update.rs b/src/lock_file/update.rs index 678a34299..63b95f173 100644 --- a/src/lock_file/update.rs +++ b/src/lock_file/update.rs @@ -19,6 +19,7 @@ use indicatif::{HumanBytes, ProgressBar, ProgressState}; use itertools::Itertools; use miette::{IntoDiagnostic, LabeledSpan, MietteDiagnostic, WrapErr}; use parking_lot::Mutex; +use pixi_consts::consts; use pixi_manifest::EnvironmentName; use rattler::package_cache::PackageCache; use rattler_conda_types::{Arch, MatchSpec, Platform, RepoDataRecord}; @@ -32,7 +33,6 @@ use uv_normalize::ExtraName; use crate::{ activation::CurrentEnvVarBehavior, - config, consts, environment::{ self, write_environment_file, EnvironmentFile, LockFileUsage, PerEnvironmentAndPlatform, PerGroup, PerGroupAndPlatform, PythonStatus, @@ -515,7 +515,7 @@ pub async fn ensure_up_to_date_lock_file( options: UpdateLockFileOptions, ) -> miette::Result> { let lock_file = load_lock_file(project).await?; - let package_cache = PackageCache::new(config::get_cache_dir()?.join("pkgs")); + let package_cache = PackageCache::new(pixi_config::get_cache_dir()?.join("pkgs")); // should we check the lock-file in the first place? if !options.lock_file_usage.should_check_if_out_of_date() { @@ -648,7 +648,7 @@ impl<'p> UpdateContextBuilder<'p> { let project = self.project; let package_cache = match self.package_cache { Some(package_cache) => package_cache, - None => PackageCache::new(config::get_cache_dir()?.join("pkgs")), + None => PackageCache::new(pixi_config::get_cache_dir()?.join("pkgs")), }; let lock_file = self.lock_file; let outdated = self.outdated_environments.unwrap_or_else(|| { diff --git a/src/project/environment.rs b/src/project/environment.rs index 070543530..d866f22fa 100644 --- a/src/project/environment.rs +++ b/src/project/environment.rs @@ -16,7 +16,8 @@ use super::{ errors::{UnknownTask, UnsupportedPlatformError}, SolveGroup, }; -use crate::{consts, project::has_features::HasFeatures, Project}; +use crate::{project::has_features::HasFeatures, Project}; +use pixi_consts::consts; /// Describes a single environment from a project manifest. This is used to /// describe environments that can be installed and activated. @@ -26,7 +27,7 @@ use crate::{consts, project::has_features::HasFeatures, Project}; /// while this struct provides methods to easily interact with an environment /// without having to deal with the structure of the project model. /// -/// This type does not provide manipulation methods. To modify the data model +/// This type does not provide manipulation methods. To modify the data mode /// you should directly interact with the manifest instead. /// /// The lifetime `'p` refers to the lifetime of the project that this diff --git a/src/project/grouped_environment.rs b/src/project/grouped_environment.rs index 090899d5f..503fa926d 100644 --- a/src/project/grouped_environment.rs +++ b/src/project/grouped_environment.rs @@ -1,12 +1,12 @@ use super::has_features::HasFeatures; use crate::fancy_display::FancyDisplay; use crate::{ - consts, prefix::Prefix, project::{virtual_packages::get_minimal_virtual_packages, Environment, SolveGroup}, Project, }; use itertools::Either; +use pixi_consts::consts; use pixi_manifest::{EnvironmentName, Feature, SystemRequirements}; use rattler_conda_types::{GenericVirtualPackage, Platform}; use std::path::PathBuf; diff --git a/src/project/mod.rs b/src/project/mod.rs index 849c5b402..87cc91a3f 100644 --- a/src/project/mod.rs +++ b/src/project/mod.rs @@ -36,12 +36,12 @@ use xxhash_rust::xxh3::xxh3_64; use crate::{ activation::{initialize_env_variables, CurrentEnvVarBehavior}, - config::Config, - consts::{self, PROJECT_MANIFEST, PYPROJECT_MANIFEST}, project::grouped_environment::GroupedEnvironment, pypi_mapping::{ChannelName, CustomMapping, MappingLocation, MappingSource}, utils::reqwest::build_reqwest_clients, }; +use pixi_config::Config; +use pixi_consts::consts; static CUSTOM_TARGET_DIR_WARN: OnceCell<()> = OnceCell::new(); @@ -197,8 +197,8 @@ impl Project { Some(file) => file, None => miette::bail!( "could not find {} or {} which is configured to use pixi", - PROJECT_MANIFEST, - PYPROJECT_MANIFEST + consts::PROJECT_MANIFEST, + consts::PYPROJECT_MANIFEST ), }; @@ -639,14 +639,14 @@ impl Project { pub fn find_project_manifest() -> Option { let current_dir = std::env::current_dir().ok()?; std::iter::successors(Some(current_dir.as_path()), |prev| prev.parent()).find_map(|dir| { - [PROJECT_MANIFEST, PYPROJECT_MANIFEST] + [consts::PROJECT_MANIFEST, consts::PYPROJECT_MANIFEST] .iter() .find_map(|manifest| { let path = dir.join(manifest); if path.is_file() { match *manifest { - PROJECT_MANIFEST => Some(path.to_path_buf()), - PYPROJECT_MANIFEST + consts::PROJECT_MANIFEST => Some(path.to_path_buf()), + consts::PYPROJECT_MANIFEST if PyProjectToml::from_path(&path) .is_ok_and(|project| project.is_pixi()) => { diff --git a/src/project/repodata.rs b/src/project/repodata.rs index 7373ad672..1b9325aea 100644 --- a/src/project/repodata.rs +++ b/src/project/repodata.rs @@ -1,6 +1,6 @@ -use crate::config::Config; -use crate::{config, project::Project}; -use rattler_repodata_gateway::{ChannelConfig, Gateway, SourceConfig}; +use crate::project::Project; + +use rattler_repodata_gateway::{ChannelConfig, Gateway}; use std::path::PathBuf; impl Project { @@ -8,7 +8,7 @@ impl Project { pub fn repodata_gateway(&self) -> &Gateway { self.repodata_gateway.get_or_init(|| { // Determine the cache directory and fall back to sane defaults otherwise. - let cache_dir = config::get_cache_dir().unwrap_or_else(|e| { + let cache_dir = pixi_config::get_cache_dir().unwrap_or_else(|e| { tracing::error!("failed to determine repodata cache directory: {e}"); std::env::current_dir().unwrap_or_else(|_| PathBuf::from("./")) }); @@ -22,23 +22,3 @@ impl Project { }) } } - -impl<'c> From<&'c Config> for ChannelConfig { - fn from(config: &'c Config) -> Self { - let default_source_config = config - .repodata_config - .as_ref() - .map(|config| SourceConfig { - jlap_enabled: !config.disable_jlap.unwrap_or(false), - zstd_enabled: !config.disable_zstd.unwrap_or(false), - bz2_enabled: !config.disable_bzip2.unwrap_or(false), - cache_action: Default::default(), - }) - .unwrap_or_default(); - - Self { - default: default_source_config, - per_channel: Default::default(), - } - } -} diff --git a/src/pypi_mapping/mod.rs b/src/pypi_mapping/mod.rs index 87ff65ba7..887bcdbc3 100644 --- a/src/pypi_mapping/mod.rs +++ b/src/pypi_mapping/mod.rs @@ -8,7 +8,8 @@ use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; use reqwest_retry::{policies::ExponentialBackoff, RetryTransientMiddleware}; use url::Url; -use crate::{config::get_cache_dir, pypi_mapping::custom_pypi_mapping::fetch_mapping_from_url}; +use crate::pypi_mapping::custom_pypi_mapping::fetch_mapping_from_url; +use pixi_config::get_cache_dir; pub mod custom_pypi_mapping; pub mod prefix_pypi_name_mapping; diff --git a/src/repodata.rs b/src/repodata.rs index e3b198ffb..1b3e4e03a 100644 --- a/src/repodata.rs +++ b/src/repodata.rs @@ -1,10 +1,10 @@ -use crate::config::Config; -use crate::{config, progress}; +use crate::progress; use futures::{stream, StreamExt, TryStreamExt}; use indexmap::IndexMap; use indicatif::ProgressBar; use itertools::Itertools; use miette::{IntoDiagnostic, WrapErr}; +use pixi_config::{self, Config}; use rattler_conda_types::{Channel, Platform}; use rattler_repodata_gateway::fetch::FetchRepoDataOptions; use rattler_repodata_gateway::sparse::SparseRepoData; @@ -61,7 +61,7 @@ pub async fn fetch_sparse_repodata_targets( top_level_progress.set_message("fetching package metadata"); top_level_progress.enable_steady_tick(Duration::from_millis(50)); - let repodata_cache_path = config::get_cache_dir()?.join("repodata"); + let repodata_cache_path = pixi_config::get_cache_dir()?.join("repodata"); let multi_progress = progress::global_multi_progress(); let mut progress_bars = Vec::new(); diff --git a/src/task/executable_task.rs b/src/task/executable_task.rs index 363236321..7c172ad69 100644 --- a/src/task/executable_task.rs +++ b/src/task/executable_task.rs @@ -15,12 +15,12 @@ use tokio::task::JoinHandle; use super::task_hash::{InputHashesError, TaskCache, TaskHash}; use crate::{ - consts::TASK_STYLE, lock_file::LockFileDerivedData, project::Environment, task::task_graph::{TaskGraph, TaskId}, Project, }; +use pixi_consts::consts; use pixi_manifest::{Task, TaskName}; @@ -311,7 +311,7 @@ impl<'p, 't> Display for ExecutableTaskConsoleDisplay<'p, 't> { write!( f, "{}", - TASK_STYLE + consts::TASK_STYLE .apply_to(command.as_deref().unwrap_or("")) .bold() )?; @@ -319,7 +319,7 @@ impl<'p, 't> Display for ExecutableTaskConsoleDisplay<'p, 't> { write!( f, " {}", - TASK_STYLE.apply_to(self.task.additional_args.iter().format(" ")) + consts::TASK_STYLE.apply_to(self.task.additional_args.iter().format(" ")) )?; } Ok(()) diff --git a/src/utils/conda_environment_file.rs b/src/utils/conda_environment_file.rs index 95f625c2f..cf145c440 100644 --- a/src/utils/conda_environment_file.rs +++ b/src/utils/conda_environment_file.rs @@ -5,7 +5,7 @@ use miette::IntoDiagnostic; use rattler_conda_types::{MatchSpec, NamedChannelOrUrl, ParseStrictness::Lenient}; use serde::Deserialize; -use crate::config::Config; +use pixi_config::Config; #[derive(Deserialize, Debug, Clone)] pub struct CondaEnvFile { diff --git a/src/utils/reqwest.rs b/src/utils/reqwest.rs index 5edb16892..3ad4ef856 100644 --- a/src/utils/reqwest.rs +++ b/src/utils/reqwest.rs @@ -11,7 +11,7 @@ use reqwest::Client; use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; use std::collections::HashMap; -use crate::config::Config; +use pixi_config::Config; /// The default retry policy employed by pixi. /// TODO: At some point we might want to make this configurable. diff --git a/tests/add_tests.rs b/tests/add_tests.rs index 29db07cfb..0a7fc8d3e 100644 --- a/tests/add_tests.rs +++ b/tests/add_tests.rs @@ -4,8 +4,8 @@ use crate::common::builders::HasDependencyConfig; use crate::common::package_database::{Package, PackageDatabase}; use crate::common::LockFileExt; use crate::common::PixiControl; -use pixi::consts::DEFAULT_ENVIRONMENT_NAME; use pixi::{DependencyType, HasFeatures}; +use pixi_consts::consts; use pixi_manifest::SpecType; use rattler_conda_types::{PackageName, Platform}; use serial_test::serial; @@ -49,14 +49,30 @@ async fn add_functionality() { .unwrap(); let lock = pixi.lock_file().await.unwrap(); - assert!(lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "rattler==3")); - assert!(!lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "rattler==2")); - assert!(!lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "rattler==1")); + assert!(lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "rattler==3" + )); + assert!(!lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "rattler==2" + )); + assert!(!lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "rattler==1" + )); // remove the package, using matchspec pixi.remove("rattler==1").await.unwrap(); let lock = pixi.lock_file().await.unwrap(); - assert!(!lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "rattler==1")); + assert!(!lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "rattler==1" + )); } /// Test that we get the union of all packages in the lockfile for the run, build and host @@ -120,13 +136,21 @@ async fn add_functionality_union() { // Lock file should contain all packages as well let lock = pixi.lock_file().await.unwrap(); - assert!(lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "rattler==1")); assert!(lock.contains_match_spec( - DEFAULT_ENVIRONMENT_NAME, + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "rattler==1" + )); + assert!(lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, Platform::current(), "libcomputer==1.2" )); - assert!(lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "libidk==3.1")); + assert!(lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "libidk==3.1" + )); } /// Test adding a package for a specific OS @@ -163,7 +187,11 @@ async fn add_functionality_os() { .unwrap(); let lock = pixi.lock_file().await.unwrap(); - assert!(lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::LinuxS390X, "rattler==1")); + assert!(lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::LinuxS390X, + "rattler==1" + )); } /// Test the `pixi add --pypi` functionality @@ -213,14 +241,18 @@ async fn add_pypi_functionality() { .unwrap(); let lock = pixi.lock_file().await.unwrap(); - assert!(lock.contains_pypi_package(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "pipx")); + assert!(lock.contains_pypi_package( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "pipx" + )); assert!(lock.contains_pep508_requirement( - DEFAULT_ENVIRONMENT_NAME, + consts::DEFAULT_ENVIRONMENT_NAME, Platform::Osx64, pep508_rs::Requirement::from_str("boltons").unwrap() )); assert!(lock.contains_pep508_requirement( - DEFAULT_ENVIRONMENT_NAME, + consts::DEFAULT_ENVIRONMENT_NAME, Platform::Linux64, pep508_rs::Requirement::from_str("pytest[all]").unwrap(), )); @@ -248,9 +280,21 @@ async fn add_pypi_functionality() { .unwrap(); let lock = pixi.lock_file().await.unwrap(); - assert!(lock.contains_pypi_package(DEFAULT_ENVIRONMENT_NAME, Platform::Linux64, "requests")); - assert!(lock.contains_pypi_package(DEFAULT_ENVIRONMENT_NAME, Platform::Linux64, "isort")); - assert!(lock.contains_pypi_package(DEFAULT_ENVIRONMENT_NAME, Platform::Linux64, "pytest")); + assert!(lock.contains_pypi_package( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::Linux64, + "requests" + )); + assert!(lock.contains_pypi_package( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::Linux64, + "isort" + )); + assert!(lock.contains_pypi_package( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::Linux64, + "pytest" + )); } /// Test the sdist support for pypi packages diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 2cdcf9eb3..b57a40d0d 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -27,10 +27,10 @@ use pixi::{ task::{self, AddArgs, AliasArgs}, update, LockFileUsageArgs, }, - consts, task::TaskName, Project, UpdateLockFileOptions, }; +use pixi_consts::consts; use pixi_manifest::{EnvironmentName, FeatureName}; use rattler_conda_types::{MatchSpec, ParseStrictness::Lenient, Platform}; use rattler_lock::{LockFile, Package}; diff --git a/tests/install_tests.rs b/tests/install_tests.rs index f00403575..f66ed0f58 100644 --- a/tests/install_tests.rs +++ b/tests/install_tests.rs @@ -8,12 +8,9 @@ use std::{ }; use common::{LockFileExt, PixiControl}; -use pixi::{ - cli::{run, run::Args, LockFileUsageArgs}, - config::{Config, DetachedEnvironments}, - consts, - consts::{DEFAULT_ENVIRONMENT_NAME, PIXI_UV_INSTALLER}, -}; +use pixi::cli::{run, run::Args, LockFileUsageArgs}; +use pixi_config::{Config, DetachedEnvironments}; +use pixi_consts::consts; use pixi_manifest::FeatureName; use rattler_conda_types::Platform; use serial_test::serial; @@ -38,7 +35,7 @@ async fn install_run_python() { // Check if lock has python version let lock = pixi.lock_file().await.unwrap(); assert!(lock.contains_match_spec( - DEFAULT_ENVIRONMENT_NAME, + consts::DEFAULT_ENVIRONMENT_NAME, Platform::current(), "python==3.11.0" )); @@ -107,8 +104,16 @@ async fn test_incremental_lock_file() { // Get the created lock-file let lock = pixi.lock_file().await.unwrap(); - assert!(lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "foo ==1")); - assert!(lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "bar ==1")); + assert!(lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "foo ==1" + )); + assert!(lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "bar ==1" + )); // Add version 2 of both `foo` and `bar`. package_database.add_package(Package::build("bar", "2").finish()); @@ -128,11 +133,19 @@ async fn test_incremental_lock_file() { let lock = pixi.lock_file().await.unwrap(); assert!( - lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "foo ==2"), + lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "foo ==2" + ), "expected `foo` to be on version 2 because we changed the requirement" ); assert!( - lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "bar ==1"), + lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "bar ==1" + ), "expected `bar` to remain locked to version 1." ); } @@ -183,7 +196,7 @@ async fn install_locked_with_config() { // Check if it didn't accidentally update the lockfile let lock = pixi.lock_file().await.unwrap(); assert!(lock.contains_match_spec( - DEFAULT_ENVIRONMENT_NAME, + consts::DEFAULT_ENVIRONMENT_NAME, Platform::current(), python_version )); @@ -195,7 +208,7 @@ async fn install_locked_with_config() { // Check if lock has python version updated let lock = pixi.lock_file().await.unwrap(); assert!(lock.contains_match_spec( - DEFAULT_ENVIRONMENT_NAME, + consts::DEFAULT_ENVIRONMENT_NAME, Platform::current(), "python==3.9.0" )); @@ -252,7 +265,7 @@ async fn install_frozen() { // Check if it didn't accidentally update the lockfile let lock = pixi.lock_file().await.unwrap(); assert!(lock.contains_match_spec( - DEFAULT_ENVIRONMENT_NAME, + consts::DEFAULT_ENVIRONMENT_NAME, Platform::current(), "python==3.9.1" )); @@ -302,7 +315,7 @@ async fn pypi_reinstall_python() { .await .unwrap(); assert!(pixi.lock_file().await.unwrap().contains_match_spec( - DEFAULT_ENVIRONMENT_NAME, + consts::DEFAULT_ENVIRONMENT_NAME, Platform::current(), "python==3.11" )); @@ -324,7 +337,7 @@ async fn pypi_reinstall_python() { // Reinstall python pixi.add("python==3.12").with_install(true).await.unwrap(); assert!(pixi.lock_file().await.unwrap().contains_match_spec( - DEFAULT_ENVIRONMENT_NAME, + consts::DEFAULT_ENVIRONMENT_NAME, Platform::current(), "python==3.12" )); @@ -409,7 +422,7 @@ async fn test_channels_changed() { // Get an up-to-date lockfile and verify that bar version 2 was selected from // channel `a`. let lock_file = pixi.up_to_date_lock_file().await.unwrap(); - assert!(lock_file.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, platform, "bar ==2")); + assert!(lock_file.contains_match_spec(consts::DEFAULT_ENVIRONMENT_NAME, platform, "bar ==2")); // Switch the channel around let platform = Platform::current(); @@ -430,7 +443,7 @@ async fn test_channels_changed() { // Get an up-to-date lockfile and verify that bar version 1 was now selected // from channel `b`. let lock_file = pixi.up_to_date_lock_file().await.unwrap(); - assert!(lock_file.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, platform, "bar ==1")); + assert!(lock_file.contains_match_spec(consts::DEFAULT_ENVIRONMENT_NAME, platform, "bar ==1")); } #[tokio::test(flavor = "multi_thread", worker_threads = 1)] @@ -467,7 +480,7 @@ async fn minimal_lockfile_update_pypi() { // Check the locked click dependencies let lock = pixi.lock_file().await.unwrap(); assert!(lock.contains_pep508_requirement( - DEFAULT_ENVIRONMENT_NAME, + consts::DEFAULT_ENVIRONMENT_NAME, Platform::current(), pep508_rs::Requirement::from_str("click==7.1.2").unwrap() )); @@ -482,7 +495,7 @@ async fn minimal_lockfile_update_pypi() { // `click` should not be updated to a higher version. let lock = pixi.lock_file().await.unwrap(); assert!(lock.contains_pep508_requirement( - DEFAULT_ENVIRONMENT_NAME, + consts::DEFAULT_ENVIRONMENT_NAME, Platform::current(), pep508_rs::Requirement::from_str("click==7.1.2").unwrap() )); @@ -520,7 +533,7 @@ async fn test_installer_name() { assert!(dist_info.exists(), "{dist_info:?} does not exist"); let installer = dist_info.join("INSTALLER"); let installer = std::fs::read_to_string(installer).unwrap(); - assert_eq!(installer, PIXI_UV_INSTALLER); + assert_eq!(installer, consts::PIXI_UV_INSTALLER); // Write a new installer name to the INSTALLER file // so that we fake that it is not installed by pixi @@ -547,5 +560,5 @@ async fn test_installer_name() { .unwrap(); let installer = dist_info.join("INSTALLER"); let installer = std::fs::read_to_string(installer).unwrap(); - assert_eq!(installer, PIXI_UV_INSTALLER); + assert_eq!(installer, consts::PIXI_UV_INSTALLER); } diff --git a/tests/update_tests.rs b/tests/update_tests.rs index 1e347ac0d..4824811b8 100644 --- a/tests/update_tests.rs +++ b/tests/update_tests.rs @@ -1,6 +1,6 @@ mod common; -use pixi::consts::DEFAULT_ENVIRONMENT_NAME; +use pixi_consts::consts; use rattler_conda_types::Platform; use tempfile::TempDir; @@ -38,8 +38,16 @@ async fn test_update() { // Get the created lock-file let lock = pixi.lock_file().await.unwrap(); - assert!(lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "bar ==1")); - assert!(lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "foo ==1")); + assert!(lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "bar ==1" + )); + assert!(lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "foo ==1" + )); // Add version 2 and 3 of `bar`. Version 3 should never be selected. package_database.add_package(Package::build("bar", "2").finish()); @@ -58,11 +66,19 @@ async fn test_update() { // spec and has been updated. let lock = pixi.lock_file().await.unwrap(); assert!( - lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "foo ==2"), + lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "foo ==2" + ), "expected `foo` to be on version 2 because we updated the lock-file" ); assert!( - lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "bar ==2"), + lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "bar ==2" + ), "expected `bar` to be on version 2 because we updated the lock-file" ); } @@ -96,8 +112,16 @@ async fn test_update_single_package() { // Get the created lock-file let lock = pixi.lock_file().await.unwrap(); - assert!(lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "bar ==1")); - assert!(lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "foo ==1")); + assert!(lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "bar ==1" + )); + assert!(lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "foo ==1" + )); // Add version 2 and 3 of `bar`. Version 3 should never be selected. package_database.add_package(Package::build("bar", "2").finish()); @@ -112,11 +136,19 @@ async fn test_update_single_package() { let lock = pixi.lock_file().await.unwrap(); assert!( - lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "foo ==2"), + lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "foo ==2" + ), "expected `foo` to be on version 2 because we updated it" ); assert!( - lock.contains_match_spec(DEFAULT_ENVIRONMENT_NAME, Platform::current(), "bar ==1"), + lock.contains_match_spec( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::current(), + "bar ==1" + ), "expected `bar` to be on version 1 because only foo should be updated" ); } From 975dc9029c39bd5139ce5d71f6af9769f5905e51 Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Fri, 26 Jul 2024 20:09:48 +0200 Subject: [PATCH 2/8] fix: delete unreferenced snaps --- .../pixi__config__tests__config_merge.snap | 69 -------------- ...i__config__tests__version_constraints.snap | 93 ------------------- 2 files changed, 162 deletions(-) delete mode 100644 src/snapshots/pixi__config__tests__config_merge.snap delete mode 100644 src/snapshots/pixi__config__tests__version_constraints.snap diff --git a/src/snapshots/pixi__config__tests__config_merge.snap b/src/snapshots/pixi__config__tests__config_merge.snap deleted file mode 100644 index ca7a77c5c..000000000 --- a/src/snapshots/pixi__config__tests__config_merge.snap +++ /dev/null @@ -1,69 +0,0 @@ ---- -source: src/config.rs -expression: debug ---- -Config { - default_channels: [ - Name( - "conda-forge", - ), - Name( - "bioconda", - ), - Name( - "defaults", - ), - ], - change_ps1: Some( - true, - ), - authentication_override_file: None, - tls_no_verify: Some( - false, - ), - mirrors: {}, - pinning_strategy: None, - loaded_from: [ - "path/config_1.toml", - "path/config_2.toml", - ], - channel_config: ChannelConfig { - channel_alias: Url { - scheme: "https", - cannot_be_a_base: false, - username: "", - password: None, - host: Some( - Domain( - "conda.anaconda.org", - ), - ), - port: None, - path: "/", - query: None, - fragment: None, - }, - root_dir: "/root/dir", - }, - repodata_config: Some( - RepodataConfig { - disable_jlap: Some( - true, - ), - disable_bzip2: None, - disable_zstd: Some( - true, - ), - }, - ), - pypi_config: PyPIConfig { - index_url: None, - extra_index_urls: [], - keyring_provider: None, - }, - detached_environments: Some( - Boolean( - true, - ), - ), -} diff --git a/src/snapshots/pixi__config__tests__version_constraints.snap b/src/snapshots/pixi__config__tests__version_constraints.snap deleted file mode 100644 index deeacac9d..000000000 --- a/src/snapshots/pixi__config__tests__version_constraints.snap +++ /dev/null @@ -1,93 +0,0 @@ ---- -source: src/config.rs -expression: results ---- -### Strategy: 'Semver' ->=1.2.3,<2 from 1.2.3 ->=0.0.0,<0.0.1 from 0.0.0 ->=1!1,<1!2 from 1!1 ->=1!0.0.0,<1!0.0.1 from 1!0.0.0 ->=1.2.3a1,<2 from 1.2.3a1 ->=1.2.3a1,<2 from 1.2.3a1, 1.2.3 ->=1.2.3a1,<10001 from 1.2.3, 1.2.3a1, 1.2.3b1, 1.2.3rc1, 2, 10000 ->=1.2.0,<2 from 1.2.0, 1.3.0 ->=0.2.0,<0.4 from 0.2.0, 0.3.0 ->=0.2.0,<2 from 0.2.0, 1.3.0 ->=1.2,<2 from 1.2 ->=1.2,<3 from 1.2, 2 ->=1.2,<1!3 from 1.2, 1!2.0 - -### Strategy: 'Major' ->=1.2.3,<2 from 1.2.3 ->=0.0.0,<1 from 0.0.0 ->=1!1,<1!2 from 1!1 ->=1!0.0.0,<1!1 from 1!0.0.0 ->=1.2.3a1,<2 from 1.2.3a1 ->=1.2.3a1,<2 from 1.2.3a1, 1.2.3 ->=1.2.3a1,<10001 from 1.2.3, 1.2.3a1, 1.2.3b1, 1.2.3rc1, 2, 10000 ->=1.2.0,<2 from 1.2.0, 1.3.0 ->=0.2.0,<1 from 0.2.0, 0.3.0 ->=0.2.0,<2 from 0.2.0, 1.3.0 ->=1.2,<2.2 from 1.2 ->=1.2,<3 from 1.2, 2 ->=1.2,<1!3.0 from 1.2, 1!2.0 - -### Strategy: 'Minor' ->=1.2.3,<1.3 from 1.2.3 ->=0.0.0,<0.1 from 0.0.0 ->=1!1,<1!1.1 from 1!1 ->=1!0.0.0,<1!0.1 from 1!0.0.0 ->=1.2.3a1,<1.3 from 1.2.3a1 ->=1.2.3a1,<1.3 from 1.2.3a1, 1.2.3 ->=1.2.3a1,<10000.1 from 1.2.3, 1.2.3a1, 1.2.3b1, 1.2.3rc1, 2, 10000 ->=1.2.0,<1.4 from 1.2.0, 1.3.0 ->=0.2.0,<0.4 from 0.2.0, 0.3.0 ->=0.2.0,<1.4 from 0.2.0, 1.3.0 ->=1.2,<1.1 from 1.2 ->=1.2,<2.1 from 1.2, 2 ->=1.2,<1!2.1 from 1.2, 1!2.0 - -### Strategy: 'ExactVersion' -==1.2.3 from 1.2.3 -==0.0.0 from 0.0.0 -==1!1 from 1!1 -==1!0.0.0 from 1!0.0.0 -==1.2.3a1 from 1.2.3a1 -==1.2.3a1|==1.2.3 from 1.2.3a1, 1.2.3 -==1.2.3|==1.2.3a1|==1.2.3b1|==1.2.3rc1|==2|==10000 from 1.2.3, 1.2.3a1, 1.2.3b1, 1.2.3rc1, 2, 10000 -==1.2.0|==1.3.0 from 1.2.0, 1.3.0 -==0.2.0|==0.3.0 from 0.2.0, 0.3.0 -==0.2.0|==1.3.0 from 0.2.0, 1.3.0 -==1.2 from 1.2 -==1.2|==2 from 1.2, 2 -==1.2|==1!2.0 from 1.2, 1!2.0 - -### Strategy: 'LatestUp' ->=1.2.3 from 1.2.3 ->=0.0.0 from 0.0.0 ->=1!1 from 1!1 ->=1!0.0.0 from 1!0.0.0 ->=1.2.3a1 from 1.2.3a1 ->=1.2.3a1 from 1.2.3a1, 1.2.3 ->=1.2.3a1 from 1.2.3, 1.2.3a1, 1.2.3b1, 1.2.3rc1, 2, 10000 ->=1.2.0 from 1.2.0, 1.3.0 ->=0.2.0 from 0.2.0, 0.3.0 ->=0.2.0 from 0.2.0, 1.3.0 ->=1.2 from 1.2 ->=1.2 from 1.2, 2 ->=1.2 from 1.2, 1!2.0 - -### Strategy: 'NoPin' -* from 1.2.3 -* from 0.0.0 -* from 1!1 -* from 1!0.0.0 -* from 1.2.3a1 -* from 1.2.3a1, 1.2.3 -* from 1.2.3, 1.2.3a1, 1.2.3b1, 1.2.3rc1, 2, 10000 -* from 1.2.0, 1.3.0 -* from 0.2.0, 0.3.0 -* from 0.2.0, 1.3.0 -* from 1.2 -* from 1.2, 2 -* from 1.2, 1!2.0 From c42e0cb80fdec6d7dde716df7ff99cef7dd3f977 Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Mon, 29 Jul 2024 10:13:38 +0200 Subject: [PATCH 3/8] feat: fix snapshots --- crates/pixi_config/Cargo.toml | 2 +- .../pixi_config__tests__config_merge.snap | 69 ++++++++++++++ ...xi_config__tests__version_constraints.snap | 93 +++++++++++++++++++ .../pixi_config/tests}/config/config_1.toml | 0 .../pixi_config/tests}/config/config_2.toml | 0 ...ts__error_on_multiple_primary_indexes.snap | 5 - ...pi_options__tests__merge_pypi_options.snap | 13 --- ..._pypi_requirement__tests__from_args-2.snap | 5 - ...i__pypi_requirement__tests__from_args.snap | 5 - crates/pixi_pty/src/unix/pty_session.rs | 2 +- 10 files changed, 164 insertions(+), 30 deletions(-) create mode 100644 crates/pixi_config/src/snapshots/pixi_config__tests__config_merge.snap create mode 100644 crates/pixi_config/src/snapshots/pixi_config__tests__version_constraints.snap rename {tests => crates/pixi_config/tests}/config/config_1.toml (100%) rename {tests => crates/pixi_config/tests}/config/config_2.toml (100%) delete mode 100644 crates/pixi_manifest/src/pypi/snapshots/pixi__project__manifest__pypi__pypi_options__tests__error_on_multiple_primary_indexes.snap delete mode 100644 crates/pixi_manifest/src/pypi/snapshots/pixi__project__manifest__pypi__pypi_options__tests__merge_pypi_options.snap delete mode 100644 crates/pixi_manifest/src/pypi/snapshots/pixi__project__manifest__pypi__pypi_requirement__tests__from_args-2.snap delete mode 100644 crates/pixi_manifest/src/pypi/snapshots/pixi__project__manifest__pypi__pypi_requirement__tests__from_args.snap diff --git a/crates/pixi_config/Cargo.toml b/crates/pixi_config/Cargo.toml index c0e37d040..56519515c 100644 --- a/crates/pixi_config/Cargo.toml +++ b/crates/pixi_config/Cargo.toml @@ -18,7 +18,7 @@ miette = { workspace = true } pixi_consts = { workspace = true } rattler = { workspace = true } rattler_conda_types = { workspace = true } -rattler_repodata_gateway = { workspace = true } +rattler_repodata_gateway = { workspace = true, features = ["gateway"] } serde = { workspace = true } serde_ignored = { workspace = true } serde_json = { workspace = true } diff --git a/crates/pixi_config/src/snapshots/pixi_config__tests__config_merge.snap b/crates/pixi_config/src/snapshots/pixi_config__tests__config_merge.snap new file mode 100644 index 000000000..e44c67974 --- /dev/null +++ b/crates/pixi_config/src/snapshots/pixi_config__tests__config_merge.snap @@ -0,0 +1,69 @@ +--- +source: crates/pixi_config/src/lib.rs +expression: debug +--- +Config { + default_channels: [ + Name( + "conda-forge", + ), + Name( + "bioconda", + ), + Name( + "defaults", + ), + ], + change_ps1: Some( + true, + ), + authentication_override_file: None, + tls_no_verify: Some( + false, + ), + mirrors: {}, + pinning_strategy: None, + loaded_from: [ + "path/config_1.toml", + "path/config_2.toml", + ], + channel_config: ChannelConfig { + channel_alias: Url { + scheme: "https", + cannot_be_a_base: false, + username: "", + password: None, + host: Some( + Domain( + "conda.anaconda.org", + ), + ), + port: None, + path: "/", + query: None, + fragment: None, + }, + root_dir: "/root/dir", + }, + repodata_config: Some( + RepodataConfig { + disable_jlap: Some( + true, + ), + disable_bzip2: None, + disable_zstd: Some( + true, + ), + }, + ), + pypi_config: PyPIConfig { + index_url: None, + extra_index_urls: [], + keyring_provider: None, + }, + detached_environments: Some( + Boolean( + true, + ), + ), +} diff --git a/crates/pixi_config/src/snapshots/pixi_config__tests__version_constraints.snap b/crates/pixi_config/src/snapshots/pixi_config__tests__version_constraints.snap new file mode 100644 index 000000000..3e23fbc07 --- /dev/null +++ b/crates/pixi_config/src/snapshots/pixi_config__tests__version_constraints.snap @@ -0,0 +1,93 @@ +--- +source: crates/pixi_config/src/lib.rs +expression: results +--- +### Strategy: 'Semver' +>=1.2.3,<2 from 1.2.3 +>=0.0.0,<0.0.1 from 0.0.0 +>=1!1,<1!2 from 1!1 +>=1!0.0.0,<1!0.0.1 from 1!0.0.0 +>=1.2.3a1,<2 from 1.2.3a1 +>=1.2.3a1,<2 from 1.2.3a1, 1.2.3 +>=1.2.3a1,<10001 from 1.2.3, 1.2.3a1, 1.2.3b1, 1.2.3rc1, 2, 10000 +>=1.2.0,<2 from 1.2.0, 1.3.0 +>=0.2.0,<0.4 from 0.2.0, 0.3.0 +>=0.2.0,<2 from 0.2.0, 1.3.0 +>=1.2,<2 from 1.2 +>=1.2,<3 from 1.2, 2 +>=1.2,<1!3 from 1.2, 1!2.0 + +### Strategy: 'Major' +>=1.2.3,<2 from 1.2.3 +>=0.0.0,<1 from 0.0.0 +>=1!1,<1!2 from 1!1 +>=1!0.0.0,<1!1 from 1!0.0.0 +>=1.2.3a1,<2 from 1.2.3a1 +>=1.2.3a1,<2 from 1.2.3a1, 1.2.3 +>=1.2.3a1,<10001 from 1.2.3, 1.2.3a1, 1.2.3b1, 1.2.3rc1, 2, 10000 +>=1.2.0,<2 from 1.2.0, 1.3.0 +>=0.2.0,<1 from 0.2.0, 0.3.0 +>=0.2.0,<2 from 0.2.0, 1.3.0 +>=1.2,<2.2 from 1.2 +>=1.2,<3 from 1.2, 2 +>=1.2,<1!3.0 from 1.2, 1!2.0 + +### Strategy: 'Minor' +>=1.2.3,<1.3 from 1.2.3 +>=0.0.0,<0.1 from 0.0.0 +>=1!1,<1!1.1 from 1!1 +>=1!0.0.0,<1!0.1 from 1!0.0.0 +>=1.2.3a1,<1.3 from 1.2.3a1 +>=1.2.3a1,<1.3 from 1.2.3a1, 1.2.3 +>=1.2.3a1,<10000.1 from 1.2.3, 1.2.3a1, 1.2.3b1, 1.2.3rc1, 2, 10000 +>=1.2.0,<1.4 from 1.2.0, 1.3.0 +>=0.2.0,<0.4 from 0.2.0, 0.3.0 +>=0.2.0,<1.4 from 0.2.0, 1.3.0 +>=1.2,<1.1 from 1.2 +>=1.2,<2.1 from 1.2, 2 +>=1.2,<1!2.1 from 1.2, 1!2.0 + +### Strategy: 'ExactVersion' +==1.2.3 from 1.2.3 +==0.0.0 from 0.0.0 +==1!1 from 1!1 +==1!0.0.0 from 1!0.0.0 +==1.2.3a1 from 1.2.3a1 +==1.2.3a1|==1.2.3 from 1.2.3a1, 1.2.3 +==1.2.3|==1.2.3a1|==1.2.3b1|==1.2.3rc1|==2|==10000 from 1.2.3, 1.2.3a1, 1.2.3b1, 1.2.3rc1, 2, 10000 +==1.2.0|==1.3.0 from 1.2.0, 1.3.0 +==0.2.0|==0.3.0 from 0.2.0, 0.3.0 +==0.2.0|==1.3.0 from 0.2.0, 1.3.0 +==1.2 from 1.2 +==1.2|==2 from 1.2, 2 +==1.2|==1!2.0 from 1.2, 1!2.0 + +### Strategy: 'LatestUp' +>=1.2.3 from 1.2.3 +>=0.0.0 from 0.0.0 +>=1!1 from 1!1 +>=1!0.0.0 from 1!0.0.0 +>=1.2.3a1 from 1.2.3a1 +>=1.2.3a1 from 1.2.3a1, 1.2.3 +>=1.2.3a1 from 1.2.3, 1.2.3a1, 1.2.3b1, 1.2.3rc1, 2, 10000 +>=1.2.0 from 1.2.0, 1.3.0 +>=0.2.0 from 0.2.0, 0.3.0 +>=0.2.0 from 0.2.0, 1.3.0 +>=1.2 from 1.2 +>=1.2 from 1.2, 2 +>=1.2 from 1.2, 1!2.0 + +### Strategy: 'NoPin' +* from 1.2.3 +* from 0.0.0 +* from 1!1 +* from 1!0.0.0 +* from 1.2.3a1 +* from 1.2.3a1, 1.2.3 +* from 1.2.3, 1.2.3a1, 1.2.3b1, 1.2.3rc1, 2, 10000 +* from 1.2.0, 1.3.0 +* from 0.2.0, 0.3.0 +* from 0.2.0, 1.3.0 +* from 1.2 +* from 1.2, 2 +* from 1.2, 1!2.0 diff --git a/tests/config/config_1.toml b/crates/pixi_config/tests/config/config_1.toml similarity index 100% rename from tests/config/config_1.toml rename to crates/pixi_config/tests/config/config_1.toml diff --git a/tests/config/config_2.toml b/crates/pixi_config/tests/config/config_2.toml similarity index 100% rename from tests/config/config_2.toml rename to crates/pixi_config/tests/config/config_2.toml diff --git a/crates/pixi_manifest/src/pypi/snapshots/pixi__project__manifest__pypi__pypi_options__tests__error_on_multiple_primary_indexes.snap b/crates/pixi_manifest/src/pypi/snapshots/pixi__project__manifest__pypi__pypi_options__tests__error_on_multiple_primary_indexes.snap deleted file mode 100644 index c013fb559..000000000 --- a/crates/pixi_manifest/src/pypi/snapshots/pixi__project__manifest__pypi__pypi_options__tests__error_on_multiple_primary_indexes.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: src/project/manifest/pypi/pypi_options.rs -expression: merged_opts.err().unwrap() ---- -multiple primary pypi indexes are not supported, found both https://example.com/pypi and https://example.com/pypi2 across multiple pypi options diff --git a/crates/pixi_manifest/src/pypi/snapshots/pixi__project__manifest__pypi__pypi_options__tests__merge_pypi_options.snap b/crates/pixi_manifest/src/pypi/snapshots/pixi__project__manifest__pypi__pypi_options__tests__merge_pypi_options.snap deleted file mode 100644 index 724076ee4..000000000 --- a/crates/pixi_manifest/src/pypi/snapshots/pixi__project__manifest__pypi__pypi_options__tests__merge_pypi_options.snap +++ /dev/null @@ -1,13 +0,0 @@ ---- -source: src/project/manifest/pypi/pypi_options.rs -expression: merged_opts ---- -index-url: "https://example.com/pypi" -extra-index-urls: - - "https://example.com/extra" - - "https://example.com/extra2" -find-links: - - path: /path/to/flat/index - - url: "https://flat.index/" - - path: /path/to/flat/index2 - - url: "https://flat.index2/" diff --git a/crates/pixi_manifest/src/pypi/snapshots/pixi__project__manifest__pypi__pypi_requirement__tests__from_args-2.snap b/crates/pixi_manifest/src/pypi/snapshots/pixi__project__manifest__pypi__pypi_requirement__tests__from_args-2.snap deleted file mode 100644 index b70da3016..000000000 --- a/crates/pixi_manifest/src/pypi/snapshots/pixi__project__manifest__pypi__pypi_requirement__tests__from_args-2.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: src/project/manifest/pypi/pypi_requirement.rs -expression: as_pypi_req.to_string() ---- -{ version = "*", extras = ["test", "extrastuff"] } diff --git a/crates/pixi_manifest/src/pypi/snapshots/pixi__project__manifest__pypi__pypi_requirement__tests__from_args.snap b/crates/pixi_manifest/src/pypi/snapshots/pixi__project__manifest__pypi__pypi_requirement__tests__from_args.snap deleted file mode 100644 index 15c626429..000000000 --- a/crates/pixi_manifest/src/pypi/snapshots/pixi__project__manifest__pypi__pypi_requirement__tests__from_args.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: src/project/manifest/pypi/pypi_requirement.rs -expression: as_pypi_req.to_string() ---- -"*" diff --git a/crates/pixi_pty/src/unix/pty_session.rs b/crates/pixi_pty/src/unix/pty_session.rs index 6e7a6b2e2..310cfd7f6 100644 --- a/crates/pixi_pty/src/unix/pty_session.rs +++ b/crates/pixi_pty/src/unix/pty_session.rs @@ -26,7 +26,7 @@ pub struct PtySession { /// ``` /// use std::process::Command; -/// use pixi::unix::PtySession; +/// use pixi_pty::unix::PtySession; /// /// let process = PtySession::new(Command::new("bash")).unwrap(); /// ``` From c84460b0a93474ae42da95d42f2ead5e69d4a798 Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Mon, 29 Jul 2024 15:44:02 +0200 Subject: [PATCH 4/8] Update crates/pixi_consts/Cargo.toml Co-authored-by: Bas Zalmstra --- crates/pixi_consts/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/pixi_consts/Cargo.toml b/crates/pixi_consts/Cargo.toml index 9f613bd3f..6e84c226f 100644 --- a/crates/pixi_consts/Cargo.toml +++ b/crates/pixi_consts/Cargo.toml @@ -8,7 +8,6 @@ readme.workspace = true repository.workspace = true version = "0.1.0" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] console = { workspace = true } From c4a8fa6e00db94dc01cf643bcc242c42f0c9d3a8 Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Mon, 29 Jul 2024 15:44:13 +0200 Subject: [PATCH 5/8] Update src/project/environment.rs Co-authored-by: Bas Zalmstra --- src/project/environment.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/project/environment.rs b/src/project/environment.rs index d866f22fa..ad9e421b3 100644 --- a/src/project/environment.rs +++ b/src/project/environment.rs @@ -27,7 +27,7 @@ use pixi_consts::consts; /// while this struct provides methods to easily interact with an environment /// without having to deal with the structure of the project model. /// -/// This type does not provide manipulation methods. To modify the data mode +/// This type does not provide manipulation methods. To modify the data model /// you should directly interact with the manifest instead. /// /// The lifetime `'p` refers to the lifetime of the project that this From 7f694fb3976e43d6b5186b29a23aa1cef6c6f4d0 Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Mon, 29 Jul 2024 15:46:23 +0200 Subject: [PATCH 6/8] fix: remove file --- crates/pixi_config/src/consts.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 crates/pixi_config/src/consts.rs diff --git a/crates/pixi_config/src/consts.rs b/crates/pixi_config/src/consts.rs deleted file mode 100644 index e69de29bb..000000000 From c70e4641fe6b8912c29b941fc0c7860fca546e18 Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Mon, 29 Jul 2024 15:56:27 +0200 Subject: [PATCH 7/8] fix: move from from to free function --- Cargo.lock | 1 - crates/pixi_config/Cargo.toml | 1 - crates/pixi_config/src/lib.rs | 21 --------------------- src/cli/exec.rs | 3 ++- src/project/repodata.rs | 5 +++-- src/utils/config.rs | 21 +++++++++++++++++++++ src/utils/mod.rs | 1 + tests/add_tests.rs | 12 ++++++++++-- 8 files changed, 37 insertions(+), 28 deletions(-) create mode 100644 src/utils/config.rs diff --git a/Cargo.lock b/Cargo.lock index 6989aebb6..f3bbfd1e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3515,7 +3515,6 @@ dependencies = [ "pixi_consts", "rattler", "rattler_conda_types", - "rattler_repodata_gateway", "rstest", "serde", "serde_ignored", diff --git a/crates/pixi_config/Cargo.toml b/crates/pixi_config/Cargo.toml index 56519515c..8c2d5f6b8 100644 --- a/crates/pixi_config/Cargo.toml +++ b/crates/pixi_config/Cargo.toml @@ -18,7 +18,6 @@ miette = { workspace = true } pixi_consts = { workspace = true } rattler = { workspace = true } rattler_conda_types = { workspace = true } -rattler_repodata_gateway = { workspace = true, features = ["gateway"] } serde = { workspace = true } serde_ignored = { workspace = true } serde_json = { workspace = true } diff --git a/crates/pixi_config/src/lib.rs b/crates/pixi_config/src/lib.rs index 5c7178f2f..fbeda395c 100644 --- a/crates/pixi_config/src/lib.rs +++ b/crates/pixi_config/src/lib.rs @@ -15,7 +15,6 @@ use rattler_conda_types::{ version_spec::{EqualityOperator, LogicalOperator, RangeOperator}, ChannelConfig, NamedChannelOrUrl, Version, VersionBumpType, VersionSpec, }; -use rattler_repodata_gateway::SourceConfig; use serde::{de::IntoDeserializer, Deserialize, Serialize}; use url::Url; @@ -896,26 +895,6 @@ pub fn config_path_global() -> Vec { .collect() } -impl<'c> From<&'c Config> for rattler_repodata_gateway::ChannelConfig { - fn from(config: &'c Config) -> Self { - let default_source_config = config - .repodata_config - .as_ref() - .map(|config| SourceConfig { - jlap_enabled: !config.disable_jlap.unwrap_or(false), - zstd_enabled: !config.disable_zstd.unwrap_or(false), - bz2_enabled: !config.disable_bzip2.unwrap_or(false), - cache_action: Default::default(), - }) - .unwrap_or_default(); - - Self { - default: default_source_config, - per_channel: Default::default(), - } - } -} - #[cfg(test)] mod tests { use rstest::rstest; diff --git a/src/cli/exec.rs b/src/cli/exec.rs index 765f48f3c..b06350692 100644 --- a/src/cli/exec.rs +++ b/src/cli/exec.rs @@ -18,6 +18,7 @@ use rattler_solve::{resolvo::Solver, SolverImpl, SolverTask}; use rattler_virtual_packages::VirtualPackage; use reqwest_middleware::ClientWithMiddleware; +use crate::utils::config::from_pixi_config; use crate::{ prefix::Prefix, progress::{await_in_progress, global_multi_progress, wrap_in_progress}, @@ -158,7 +159,7 @@ pub async fn create_exec_prefix( let gateway = Gateway::builder() .with_cache_dir(cache_dir.join("repodata")) .with_client(client.clone()) - .with_channel_config(rattler_repodata_gateway::ChannelConfig::from(config)) + .with_channel_config(from_pixi_config(config)) .finish(); // Determine the specs to use for the environment diff --git a/src/project/repodata.rs b/src/project/repodata.rs index 1b9325aea..92b763084 100644 --- a/src/project/repodata.rs +++ b/src/project/repodata.rs @@ -1,6 +1,7 @@ use crate::project::Project; -use rattler_repodata_gateway::{ChannelConfig, Gateway}; +use crate::utils::config::from_pixi_config; +use rattler_repodata_gateway::Gateway; use std::path::PathBuf; impl Project { @@ -17,7 +18,7 @@ impl Project { Gateway::builder() .with_client(self.authenticated_client().clone()) .with_cache_dir(cache_dir.join("repodata")) - .with_channel_config(ChannelConfig::from(&self.config)) + .with_channel_config(from_pixi_config(&self.config)) .finish() }) } diff --git a/src/utils/config.rs b/src/utils/config.rs new file mode 100644 index 000000000..8c468326d --- /dev/null +++ b/src/utils/config.rs @@ -0,0 +1,21 @@ +use pixi_config::Config; +use rattler_repodata_gateway::{ChannelConfig, SourceConfig}; + +/// Converts a [`Config`] into a rattler [`ChannelConfig`] +pub fn from_pixi_config(config: &Config) -> ChannelConfig { + let default_source_config = config + .repodata_config + .as_ref() + .map(|config| SourceConfig { + jlap_enabled: !config.disable_jlap.unwrap_or(false), + zstd_enabled: !config.disable_zstd.unwrap_or(false), + bz2_enabled: !config.disable_bzip2.unwrap_or(false), + cache_action: Default::default(), + }) + .unwrap_or_default(); + + ChannelConfig { + default: default_source_config, + per_channel: Default::default(), + } +} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 67f7c89e8..64befacad 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,4 +1,5 @@ pub mod conda_environment_file; +pub(crate) mod config; mod prefix_guard; pub mod reqwest; pub mod uv; diff --git a/tests/add_tests.rs b/tests/add_tests.rs index 4ce6abd12..9bc2fba92 100644 --- a/tests/add_tests.rs +++ b/tests/add_tests.rs @@ -281,8 +281,16 @@ async fn add_pypi_functionality() { let lock = pixi.lock_file().await.unwrap(); // assert!(lock.contains_pypi_package(DEFAULT_ENVIRONMENT_NAME, Platform::Linux64, "requests")); - assert!(lock.contains_pypi_package(DEFAULT_ENVIRONMENT_NAME, Platform::Linux64, "isort")); - assert!(lock.contains_pypi_package(DEFAULT_ENVIRONMENT_NAME, Platform::Linux64, "pytest")); + assert!(lock.contains_pypi_package( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::Linux64, + "isort" + )); + assert!(lock.contains_pypi_package( + consts::DEFAULT_ENVIRONMENT_NAME, + Platform::Linux64, + "pytest" + )); } /// Test the sdist support for pypi packages From e5a086fea20dc130c674876d82f6950f046c4c94 Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Mon, 29 Jul 2024 16:03:34 +0200 Subject: [PATCH 8/8] fix: doc --- crates/pixi_config/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/pixi_config/src/lib.rs b/crates/pixi_config/src/lib.rs index fbeda395c..046511ac3 100644 --- a/crates/pixi_config/src/lib.rs +++ b/crates/pixi_config/src/lib.rs @@ -694,9 +694,7 @@ impl Config { /// /// This roots the channel configuration to the current directory. When /// working with a project though the channel configuration should be rooted - /// in the project directory. Use - /// [`crate::Project::channel_config`] to get the project specific channel - /// configuration. + /// in the project directory. pub fn global_channel_config(&self) -> &ChannelConfig { &self.channel_config }