Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor: refactor pixi::consts and pixi::config into separate crates #1684

Merged
merged 9 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 }
Expand Down
31 changes: 31 additions & 0 deletions crates/pixi_config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 }
baszalmstra marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
30 changes: 29 additions & 1 deletion src/config.rs → crates/pixi_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@
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;

Check failure on line 18 in crates/pixi_config/src/lib.rs

View workflow job for this annotation

GitHub Actions / Check intra-doc links

unresolved import `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.
Expand Down Expand Up @@ -63,6 +70,7 @@
}
}

// 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.
Expand Down Expand Up @@ -888,6 +896,26 @@
.collect()
}

impl<'c> From<&'c Config> for rattler_repodata_gateway::ChannelConfig {

Check failure on line 899 in crates/pixi_config/src/lib.rs

View workflow job for this annotation

GitHub Actions / Check intra-doc links

cannot find type `ChannelConfig` in crate `rattler_repodata_gateway`
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(),
}
}
}
baszalmstra marked this conversation as resolved.
Show resolved Hide resolved

#[cfg(test)]
mod tests {
use rstest::rstest;
Expand Down
17 changes: 17 additions & 0 deletions crates/pixi_consts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
tdejager marked this conversation as resolved.
Show resolved Hide resolved

[dependencies]
console = { workspace = true }
lazy_static = { workspace = true }
pixi_manifest = { workspace = true }
url = { workspace = true }
2 changes: 1 addition & 1 deletion src/consts.rs → crates/pixi_consts/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ pub use pixi_manifest::consts::*;
pub const PROJECT_MANIFEST: &str = "pixi.toml";
ruben-arts marked this conversation as resolved.
Show resolved Hide resolved
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";
Expand Down
1 change: 1 addition & 0 deletions crates/pixi_consts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod consts;
1 change: 1 addition & 0 deletions crates/pixi_manifest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
6 changes: 5 additions & 1 deletion crates/pixi_manifest/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use url::Url;

pub const PYPI_DEPENDENCIES: &str = "pypi-dependencies";
pub const DEFAULT_ENVIRONMENT_NAME: &str = "default";
pub const PROJECT_MANIFEST: &str = "pixi.toml";
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();
}
2 changes: 1 addition & 1 deletion crates/pixi_manifest/src/pypi/pypi_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl From<PypiOptions> 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())
Expand Down
2 changes: 1 addition & 1 deletion src/cli/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ 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},
project::{
grouped_environment::GroupedEnvironment, has_features::HasFeatures, DependencyType, Project,
},
};
use pixi_config::ConfigCli;

/// Adds dependencies to the project
///
Expand Down
6 changes: 4 additions & 2 deletions src/cli/clean.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -222,15 +222,15 @@ fn load_config(common_args: &CommonArgs) -> miette::Result<Config> {

fn determine_config_write_path(common_args: &CommonArgs) -> miette::Result<PathBuf> {
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 {
return Ok(root.join(consts::PIXI_DIR).join(consts::CONFIG_FILE));
}
}

let mut global_locations = config::config_path_global();
let mut global_locations = pixi_config::config_path_global();
let mut to = global_locations
.pop()
.expect("should have at least one global config path");
Expand Down
4 changes: 2 additions & 2 deletions src/cli/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ use rattler_virtual_packages::VirtualPackage;
use reqwest_middleware::ClientWithMiddleware;

use crate::{
config::{self, Config, ConfigCli},
prefix::Prefix,
progress::{await_in_progress, global_multi_progress, wrap_in_progress},
utils::{reqwest::build_reqwest_clients, PrefixGuard},
};
use pixi_config::{self, Config, ConfigCli};

/// Run a command in a temporary environment.
#[derive(Parser, Debug, Default)]
Expand Down Expand Up @@ -92,7 +92,7 @@ impl EnvironmentHash {
/// CLI entry point for `pixi runx`
pub async fn execute(args: Args) -> 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",))?;
Expand Down
8 changes: 2 additions & 6 deletions src/cli/global/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/cli/global/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/cli/global/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion src/cli/global/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/cli/global/upgrade_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
Loading
Loading