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: use toml-span for deserialization #2718

Merged
merged 18 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 17 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
164 changes: 110 additions & 54 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ csv = "1.3.1"
dashmap = "6.1.0"
deno_task_shell = "0.20.2"
dialoguer = "0.11.0"
digest = "0.10"
dirs = "5.0.1"
dunce = "1.0.5"
fd-lock = "4.0.2"
flate2 = "1.0.35"
fs-err = { version = "3.0.0" }
fs_extra = "1.3.0"
futures = "0.3.31"
hex = "0.4.3"
http = "1.2.0"
http-cache-reqwest = "0.15.0"
human_bytes = "0.4.3"
Expand Down Expand Up @@ -78,13 +80,15 @@ shlex = "1.3.0"
signal-hook = "0.3.17"
spdx = "0.10.7"
strsim = "0.11.1"
strum = "0.26.3"
tabwriter = "1.4.0"
tar = "0.4.43"
tempfile = "3.14.0"
thiserror = "2.0.9"
tokio = "1.42.0"
tokio-stream = "0.1.17"
tokio-util = "0.7.13"
toml-span = "0.4.1"
toml_edit = "0.22.22"
tracing = "0.1.41"
tracing-subscriber = "0.3.19"
Expand All @@ -97,6 +101,7 @@ uv-pep508 = { git = "https://github.com/wolfv/uv", branch = "ignore-rayon-init"
uv-platform-tags = { git = "https://github.com/wolfv/uv", branch = "ignore-rayon-init" }
uv-pypi-types = { git = "https://github.com/wolfv/uv", branch = "ignore-rayon-init" }
uv-requirements-txt = { git = "https://github.com/wolfv/uv", branch = "ignore-rayon-init" }

wax = "0.6.0"
which = "7.0.1"

Expand Down Expand Up @@ -150,6 +155,7 @@ pixi_manifest = { path = "crates/pixi_manifest" }
pixi_progress = { path = "crates/pixi_progress" }
pixi_record = { path = "crates/pixi_record" }
pixi_spec = { path = "crates/pixi_spec" }
pixi_toml = { path = "crates/pixi_toml" }
pixi_utils = { path = "crates/pixi_utils", default-features = false }
pixi_uv_conversions = { path = "crates/pixi_uv_conversions" }
pypi_mapping = { path = "crates/pypi_mapping" }
Expand Down Expand Up @@ -258,10 +264,14 @@ pixi_consts = { workspace = true }
pixi_default_versions = { workspace = true }
pixi_git = { workspace = true }
pixi_glob = { workspace = true }
pixi_manifest = { workspace = true, features = ["rattler_lock"] }
pixi_manifest = { workspace = true, features = [
"rattler_lock",
"rattler_solve",
] }
pixi_progress = { workspace = true }
pixi_record = { workspace = true }
pixi_spec = { workspace = true }
pixi_toml = { workspace = true }
pixi_utils = { workspace = true, default-features = false }
pixi_uv_conversions = { workspace = true }
pypi_mapping = { workspace = true }
Expand All @@ -286,6 +296,7 @@ tempfile = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal"] }
tokio-util = { workspace = true }
toml-span = { workspace = true }
toml_edit = { workspace = true, features = ["serde"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/pixi_build_frontend/tests/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use jsonrpsee::types::Request;
use miette::{Diagnostic, GraphicalReportHandler, GraphicalTheme};
use pixi_build_frontend::{BuildFrontend, InProcessBackend, SetupRequest};
use pixi_build_types::procedures::initialize::InitializeParams;
use pixi_manifest::toml::{ExternalWorkspaceProperties, TomlManifest};
use pixi_manifest::toml::{ExternalWorkspaceProperties, FromTomlStr, TomlManifest};
use tokio::io::{AsyncBufReadExt, AsyncRead, AsyncWrite, BufReader};
use tokio_stream::wrappers::ReceiverStream;
use tokio_util::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: crates/pixi_build_frontend/tests/diagnostics.rs
expression: snapshot
---
× failed to setup a build backend, the pixi.toml could not be parsed
╰─▶ × missing field `channels`
╰─▶ × missing field 'channels' in table
╭─[pixi.toml:1:1]
1 │ [workspace]
· ───────────
Expand Down
7 changes: 4 additions & 3 deletions crates/pixi_manifest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ pep440_rs = { workspace = true }
pep508_rs = { workspace = true }
pixi_consts = { workspace = true }
pixi_spec = { workspace = true }
pixi_toml = { workspace = true }
pixi_utils = { workspace = true }
regex = { workspace = true }
serde = { workspace = true }
serde-untagged = { workspace = true }
serde-value = { workspace = true }
serde_with = { workspace = true }
spdx = { workspace = true }
strsim = { workspace = true }
strum = { workspace = true, features = ["derive"] }
thiserror = { workspace = true }
toml-span = { workspace = true, features = ["serde"] }
toml_edit = { workspace = true }
tracing = { workspace = true }
url = { workspace = true }
Expand All @@ -36,11 +37,11 @@ pyproject-toml = { workspace = true }

# Rattler crates
rattler_conda_types = { workspace = true }
rattler_solve = { workspace = true, features = ["serde"] }
rattler_virtual_packages = { workspace = true }

# These rattler crates are optionally used in the build system
rattler_lock = { workspace = true, optional = true }
rattler_solve = { workspace = true, optional = true }

# TODO: Remove these dependencies
console = { workspace = true }
Expand Down
48 changes: 45 additions & 3 deletions crates/pixi_manifest/src/activation.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,52 @@
use indexmap::IndexMap;
use serde::Deserialize;
use toml_span::{de_helpers::TableHelper, DeserError, Value};

#[derive(Default, Clone, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
use pixi_toml::TomlIndexMap;

#[derive(Default, Clone, Debug)]
pub struct Activation {
pub scripts: Option<Vec<String>>,
/// Environment variables to set before running the scripts.
pub env: Option<IndexMap<String, String>>,
}

impl<'de> toml_span::Deserialize<'de> for Activation {
fn deserialize(value: &mut Value<'de>) -> Result<Self, DeserError> {
let mut th = TableHelper::new(value)?;
let scripts = th.optional("scripts");
let env = th.optional::<TomlIndexMap<_, _>>("env");
th.finalize(None)?;
Ok(Activation {
scripts,
env: env.map(TomlIndexMap::into_inner),
})
}
}

#[cfg(test)]
mod test {
use super::*;
use crate::toml::FromTomlStr;

#[test]
fn deserialize_activation() {
let input = r#"
scripts = ["echo 'Hello, World!'"]
[env]
FOO = "bar"
"#;

let activation = Activation::from_toml_str(input).unwrap();
assert_eq!(
activation.scripts,
Some(vec!["echo 'Hello, World!'".to_string()])
);
assert_eq!(
activation.env,
Some(IndexMap::from_iter(vec![(
"FOO".to_string(),
"bar".to_string()
)]))
);
}
}
1 change: 1 addition & 0 deletions crates/pixi_manifest/src/build_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use indexmap::IndexMap;
use pixi_spec::BinarySpec;
use rattler_conda_types::NamedChannelOrUrl;

use crate::toml::FromTomlStr;
use crate::{toml::TomlBuildSystem, TomlError};

/// A build section in the pixi manifest.
Expand Down
5 changes: 1 addition & 4 deletions crates/pixi_manifest/src/channel.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use itertools::Itertools;
use rattler_conda_types::NamedChannelOrUrl;
use serde::{Deserialize, Serialize};
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, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct PrioritizedChannel {
pub channel: NamedChannelOrUrl,
pub priority: Option<i32>,
Expand Down
11 changes: 8 additions & 3 deletions crates/pixi_manifest/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use std::{

use miette::Diagnostic;
use regex::Regex;
use serde::{self, Deserialize, Deserializer};
use serde_with::SerializeDisplay;
use serde::{self, Deserialize, Deserializer, Serialize};
use thiserror::Error;

use crate::{consts::DEFAULT_ENVIRONMENT_NAME, solve_group::SolveGroupIdx};
Expand All @@ -22,13 +21,19 @@ pub struct ParseEnvironmentNameError {

/// The name of an environment. This is either a string or default for the
/// default environment.
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, SerializeDisplay)]
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
pub enum EnvironmentName {
#[default]
Default,
Named(String),
}

impl Serialize for EnvironmentName {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.as_str().serialize(serializer)
}
}

impl Hash for EnvironmentName {
fn hash<H: Hasher>(&self, state: &mut H) {
self.as_str().hash(state)
Expand Down
Loading
Loading