1
+ use std:: collections:: BTreeMap ;
2
+
1
3
use itertools:: Either ;
2
4
use pixi_spec:: TomlSpec ;
3
5
use pixi_toml:: { TomlFromStr , TomlWith } ;
4
6
use rattler_conda_types:: NamedChannelOrUrl ;
5
- use toml_span:: { de_helpers:: TableHelper , DeserError , Spanned , Value } ;
7
+ use toml_span:: { de_helpers:: TableHelper , value :: ValueInner , DeserError , Spanned , Value } ;
6
8
7
9
use crate :: {
8
10
build_system:: BuildBackend ,
@@ -16,6 +18,7 @@ pub struct TomlPackageBuild {
16
18
pub backend : PixiSpanned < TomlBuildBackend > ,
17
19
pub channels : Option < PixiSpanned < Vec < NamedChannelOrUrl > > > ,
18
20
pub additional_dependencies : UniquePackageMap ,
21
+ pub configuration : Option < serde_value:: Value > ,
19
22
}
20
23
21
24
#[ derive( Debug ) ]
@@ -74,10 +77,37 @@ impl TomlPackageBuild {
74
77
} ,
75
78
additional_dependencies,
76
79
channels : self . channels . map ( |channels| channels. value ) ,
80
+ configuration : self . configuration ,
77
81
} )
78
82
}
79
83
}
80
84
85
+ fn convert_toml_to_serde ( value : & mut Value ) -> Result < serde_value:: Value , DeserError > {
86
+ Ok ( match value. take ( ) {
87
+ ValueInner :: String ( s) => serde_value:: Value :: String ( s. to_string ( ) ) ,
88
+ ValueInner :: Integer ( i) => serde_value:: Value :: I64 ( i) ,
89
+ ValueInner :: Float ( f) => serde_value:: Value :: F64 ( f) ,
90
+ ValueInner :: Boolean ( b) => serde_value:: Value :: Bool ( b) ,
91
+ ValueInner :: Array ( mut arr) => {
92
+ let mut json_arr = Vec :: new ( ) ;
93
+ for item in & mut arr {
94
+ json_arr. push ( convert_toml_to_serde ( item) ?) ;
95
+ }
96
+ serde_value:: Value :: Seq ( json_arr)
97
+ }
98
+ ValueInner :: Table ( table) => {
99
+ let mut map = BTreeMap :: new ( ) ;
100
+ for ( key, mut val) in table {
101
+ map. insert (
102
+ serde_value:: Value :: String ( key. to_string ( ) ) ,
103
+ convert_toml_to_serde ( & mut val) ?,
104
+ ) ;
105
+ }
106
+ serde_value:: Value :: Map ( map)
107
+ }
108
+ } )
109
+ }
110
+
81
111
impl < ' de > toml_span:: Deserialize < ' de > for TomlBuildBackend {
82
112
fn deserialize ( value : & mut Value < ' de > ) -> Result < Self , DeserError > {
83
113
let mut th = TableHelper :: new ( value) ?;
@@ -107,11 +137,18 @@ impl<'de> toml_span::Deserialize<'de> for TomlPackageBuild {
107
137
span : Some ( s. span . start ..s. span . end ) ,
108
138
} ) ;
109
139
let additional_dependencies = th. optional ( "additional-dependencies" ) . unwrap_or_default ( ) ;
140
+
141
+ let configuration = th
142
+ . take ( "configuration" )
143
+ . map ( |( _, mut value) | convert_toml_to_serde ( & mut value) )
144
+ . transpose ( ) ?;
145
+
110
146
th. finalize ( None ) ?;
111
147
Ok ( Self {
112
148
backend : build_backend,
113
149
channels,
114
150
additional_dependencies,
151
+ configuration,
115
152
} )
116
153
}
117
154
}
@@ -131,6 +168,18 @@ mod test {
131
168
format_parse_error ( pixi_toml, parse_error)
132
169
}
133
170
171
+ #[ test]
172
+ fn test_configuration_parsing ( ) {
173
+ let toml = r#"
174
+ backend = { name = "foobar", version = "*" }
175
+ configuration = { key = "value", other = ["foo", "bar"], integer = 1234, nested = { abc = "def" } }
176
+ "# ;
177
+ let parsed = <TomlPackageBuild as crate :: toml:: FromTomlStr >:: from_toml_str ( toml)
178
+ . expect ( "parsing should succeed" ) ;
179
+
180
+ insta:: assert_debug_snapshot!( parsed) ;
181
+ }
182
+
134
183
#[ test]
135
184
fn test_disallow_source ( ) {
136
185
assert_snapshot ! ( expect_parse_failure(
0 commit comments