Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: new pixi global #1833

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
195d2d4
feat: pixi global manifest (#1802)
Hofer-Julian Aug 19, 2024
c3bb1da
Merge branch 'main' into feature/pixi-global
Hofer-Julian Aug 19, 2024
a4ddbd2
Merge branch 'main' into feature/pixi-global
Hofer-Julian Sep 2, 2024
05946ff
Merge branch 'main' into feature/pixi-global
Hofer-Julian Sep 2, 2024
c021fbb
feat: add `global sync` (#1835)
Hofer-Julian Sep 3, 2024
df961cf
Merge branch 'main' into feature/pixi-global
Hofer-Julian Sep 3, 2024
98a74c3
fix: integration tests for pixi global (#1972)
Hofer-Julian Sep 3, 2024
a31b9b6
Merge branch 'main' into feature/pixi-global
Hofer-Julian Sep 3, 2024
9f1a027
Merge branch 'main' into feature/pixi-global
Hofer-Julian Sep 5, 2024
4ebec3c
Merge branch 'main' into feature/pixi-global
nichmor Sep 10, 2024
9ccadc1
Merge branch 'main' into feature/pixi-global
Hofer-Julian Sep 17, 2024
a006941
Merge branch 'main' into feature/pixi-global
Hofer-Julian Sep 17, 2024
95779df
Merge branch 'main' into feature/pixi-global
Hofer-Julian Sep 19, 2024
e04e20e
feat: add migration path for new pixi global (#1975)
Hofer-Julian Sep 20, 2024
ebda8b1
fix: Remove `allow(unused` and fix resulting warnings (#2091)
Hofer-Julian Sep 20, 2024
6358be9
test: for `local_environment_matches_spec` (#2093)
Hofer-Julian Sep 20, 2024
e943408
feat: Give better info message for `pixi global sync` (#2100)
Hofer-Julian Sep 20, 2024
09c4868
Merge branch 'main' into feature/pixi-global
Hofer-Julian Sep 20, 2024
2a4c451
Merge branch 'main' into feature/pixi-global
Hofer-Julian Sep 23, 2024
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
22 changes: 20 additions & 2 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ tar = "0.4.40"
tempfile = "3.10.1"
thiserror = "1.0.58"
tokio = "1.37.0"
tokio-stream = "0.1.16"
tokio-util = "0.7.10"
toml_edit = "0.22.11"
tracing = "0.1.40"
Expand Down Expand Up @@ -265,6 +266,7 @@ tar = { workspace = true }
tempfile = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal"] }
tokio-stream = { workspace = true, features = ["fs"] }
tokio-util = { workspace = true }
toml_edit = { workspace = true, features = ["serde"] }
tracing = { workspace = true }
Expand Down Expand Up @@ -309,6 +311,7 @@ strip = false

[dev-dependencies]
async-trait = { workspace = true }
fake = "2.9.2"
http = { workspace = true }
insta = { workspace = true, features = ["yaml", "glob"] }
rstest = { workspace = true }
Expand Down
65 changes: 62 additions & 3 deletions crates/pixi_manifest/src/channel.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
use std::str::FromStr;

use itertools::Itertools;
use rattler_conda_types::NamedChannelOrUrl;
use serde::{de::Error, Deserialize, Deserializer};
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
use serde_with::serde_as;
use toml_edit::{Table, Value};

/// A channel with an optional priority.
/// If the priority is not specified, it is assumed to be 0.
/// The higher the priority, the more important the channel is.
#[serde_as]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub struct PrioritizedChannel {
pub channel: NamedChannelOrUrl,
pub priority: Option<i32>,
}

impl PrioritizedChannel {
/// The prioritized channels contain a priority, sort on this priority.
/// Higher priority comes first. [-10, 1, 0 ,2] -> [2, 1, 0, -10]
pub fn sort_channels_by_priority<'a, I>(
channels: I,
) -> impl Iterator<Item = &'a NamedChannelOrUrl>
where
I: IntoIterator<Item = &'a crate::PrioritizedChannel>,
{
channels
.into_iter()
.sorted_by(|a, b| {
let a = a.priority.unwrap_or(0);
let b = b.priority.unwrap_or(0);
b.cmp(&a)
})
.map(|prioritized_channel| &prioritized_channel.channel)
}
}

impl From<NamedChannelOrUrl> for PrioritizedChannel {
fn from(value: NamedChannelOrUrl) -> Self {
Self {
Expand Down Expand Up @@ -64,6 +85,19 @@ impl TomlPrioritizedChannelStrOrMap {
}
}

impl From<PrioritizedChannel> for TomlPrioritizedChannelStrOrMap {
fn from(channel: PrioritizedChannel) -> Self {
if let Some(priority) = channel.priority {
TomlPrioritizedChannelStrOrMap::Map(PrioritizedChannel {
channel: channel.channel,
priority: Some(priority),
})
} else {
TomlPrioritizedChannelStrOrMap::Str(channel.channel)
}
}
}

impl<'de> Deserialize<'de> for TomlPrioritizedChannelStrOrMap {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand All @@ -81,8 +115,20 @@ impl<'de> Deserialize<'de> for TomlPrioritizedChannelStrOrMap {
}
}

impl Serialize for TomlPrioritizedChannelStrOrMap {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match self {
TomlPrioritizedChannelStrOrMap::Map(map) => map.serialize(serializer),
TomlPrioritizedChannelStrOrMap::Str(str) => str.serialize(serializer),
}
}
}

/// Helper so that we can deserialize
/// [`crate::project::manifest::serde::PrioritizedChannel`] from a string or a
/// [`crate::channel::PrioritizedChannel`] from a string or a
/// map.
impl<'de> serde_with::DeserializeAs<'de, PrioritizedChannel> for TomlPrioritizedChannelStrOrMap {
fn deserialize_as<D>(deserializer: D) -> Result<PrioritizedChannel, D::Error>
Expand All @@ -93,3 +139,16 @@ impl<'de> serde_with::DeserializeAs<'de, PrioritizedChannel> for TomlPrioritized
Ok(prioritized_channel.into_prioritized_channel())
}
}

/// Helper so that we can serialize
/// [`crate::channel::PrioritizedChannel`] to a string or a
/// map.
impl serde_with::SerializeAs<PrioritizedChannel> for TomlPrioritizedChannelStrOrMap {
fn serialize_as<S>(source: &PrioritizedChannel, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let toml_prioritized_channel: TomlPrioritizedChannelStrOrMap = source.clone().into();
toml_prioritized_channel.serialize(serializer)
}
}
24 changes: 6 additions & 18 deletions crates/pixi_manifest/src/features_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use indexmap::IndexSet;
use rattler_conda_types::{NamedChannelOrUrl, Platform};
use rattler_solve::ChannelPriority;

use crate::{HasManifestRef, SpecType};
use crate::{HasManifestRef, PrioritizedChannel, SpecType};

use crate::has_features_iter::HasFeaturesIter;
use crate::{pypi::pypi_options::PypiOptions, SystemRequirements};
Expand Down Expand Up @@ -35,24 +35,12 @@ pub trait FeaturesExt<'source>: HasManifestRef<'source> + HasFeaturesIter<'sourc
fn channels(&self) -> IndexSet<&'source NamedChannelOrUrl> {
// Collect all the channels from the features in one set,
// deduplicate them and sort them on feature index, default feature comes last.
let channels: IndexSet<_> = self
.features()
.flat_map(|feature| match &feature.channels {
Some(channels) => channels,
None => &self.manifest().parsed.project.channels,
})
.collect();
let channels = self.features().flat_map(|feature| match &feature.channels {
Some(channels) => channels,
None => &self.manifest().parsed.project.channels,
});

// The prioritized channels contain a priority, sort on this priority.
// Higher priority comes first. [-10, 1, 0 ,2] -> [2, 1, 0, -10]
channels
.sorted_by(|a, b| {
let a = a.priority.unwrap_or(0);
let b = b.priority.unwrap_or(0);
b.cmp(&a)
})
.map(|prioritized_channel| &prioritized_channel.channel)
.collect()
PrioritizedChannel::sort_channels_by_priority(channels).collect()
}

/// Returns the channel priority, error on multiple values, return None if no value is set.
Expand Down
4 changes: 2 additions & 2 deletions crates/pixi_manifest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ pub use dependencies::{CondaDependencies, Dependencies, PyPiDependencies};
pub use manifests::manifest::{Manifest, ManifestKind};

pub use crate::environments::Environments;
pub use crate::parsed_manifest::ParsedManifest;
pub use crate::parsed_manifest::{deserialize_package_map, ParsedManifest};
pub use crate::solve_group::{SolveGroup, SolveGroups};
pub use activation::Activation;
pub use channel::PrioritizedChannel;
pub use channel::{PrioritizedChannel, TomlPrioritizedChannelStrOrMap};
pub use environment::{Environment, EnvironmentName};
pub use feature::{Feature, FeatureName};
use itertools::Itertools;
Expand Down
145 changes: 0 additions & 145 deletions src/cli/global/common.rs

This file was deleted.

Loading
Loading