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 all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 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
30 changes: 30 additions & 0 deletions crates/pixi_config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[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 }
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 }
13 changes: 9 additions & 4 deletions src/config.rs → crates/pixi_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ 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 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 +69,7 @@ pub fn home_path() -> Option<PathBuf> {
}
}

// 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 @@ -687,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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: src/config.rs
source: crates/pixi_config/src/lib.rs
expression: debug
---
Config {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: src/config.rs
source: crates/pixi_config/src/lib.rs
expression: results
---
### Strategy: 'Semver'
Expand Down
16 changes: 16 additions & 0 deletions crates/pixi_consts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[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"


[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 @@ -12,6 +12,7 @@ version = "0.1.0"
dunce = { workspace = true }
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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion crates/pixi_pty/src/unix/pty_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
/// ```
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
7 changes: 4 additions & 3 deletions src/cli/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ 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::{
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 +93,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 Expand Up @@ -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
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
Loading
Loading