@@ -16,6 +16,10 @@ use uv_settings::ToolOptions;
1616pub struct Tool {
1717 /// The requirements requested by the user during installation.
1818 requirements : Vec < Requirement > ,
19+ /// The constraints requested by the user during installation.
20+ constraints : Vec < Requirement > ,
21+ /// The overrides requested by the user during installation.
22+ overrides : Vec < Requirement > ,
1923 /// The Python requested by the user during installation.
2024 python : Option < String > ,
2125 /// A mapping of entry point names to their metadata.
@@ -26,7 +30,12 @@ pub struct Tool {
2630
2731#[ derive( Debug , Clone , Deserialize ) ]
2832struct ToolWire {
33+ #[ serde( default ) ]
2934 requirements : Vec < RequirementWire > ,
35+ #[ serde( default ) ]
36+ constraints : Vec < Requirement > ,
37+ #[ serde( default ) ]
38+ overrides : Vec < Requirement > ,
3039 python : Option < String > ,
3140 entrypoints : Vec < ToolEntrypoint > ,
3241 #[ serde( default ) ]
@@ -51,6 +60,8 @@ impl From<Tool> for ToolWire {
5160 . into_iter ( )
5261 . map ( RequirementWire :: Requirement )
5362 . collect ( ) ,
63+ constraints : tool. constraints ,
64+ overrides : tool. overrides ,
5465 python : tool. python ,
5566 entrypoints : tool. entrypoints ,
5667 options : tool. options ,
@@ -71,6 +82,8 @@ impl TryFrom<ToolWire> for Tool {
7182 RequirementWire :: Deprecated ( requirement) => Requirement :: from ( requirement) ,
7283 } )
7384 . collect ( ) ,
85+ constraints : tool. constraints ,
86+ overrides : tool. overrides ,
7487 python : tool. python ,
7588 entrypoints : tool. entrypoints ,
7689 options : tool. options ,
@@ -116,6 +129,8 @@ impl Tool {
116129 /// Create a new `Tool`.
117130 pub fn new (
118131 requirements : Vec < Requirement > ,
132+ constraints : Vec < Requirement > ,
133+ overrides : Vec < Requirement > ,
119134 python : Option < String > ,
120135 entrypoints : impl Iterator < Item = ToolEntrypoint > ,
121136 options : ToolOptions ,
@@ -124,6 +139,8 @@ impl Tool {
124139 entrypoints. sort ( ) ;
125140 Self {
126141 requirements,
142+ constraints,
143+ overrides,
127144 python,
128145 entrypoints,
129146 options,
@@ -140,25 +157,71 @@ impl Tool {
140157 pub ( crate ) fn to_toml ( & self ) -> Result < Table , toml_edit:: ser:: Error > {
141158 let mut table = Table :: new ( ) ;
142159
143- table. insert ( "requirements" , {
144- let requirements = self
145- . requirements
146- . iter ( )
147- . map ( |requirement| {
148- serde:: Serialize :: serialize (
149- & requirement,
150- toml_edit:: ser:: ValueSerializer :: new ( ) ,
151- )
152- } )
153- . collect :: < Result < Vec < _ > , _ > > ( ) ?;
160+ if !self . requirements . is_empty ( ) {
161+ table. insert ( "requirements" , {
162+ let requirements = self
163+ . requirements
164+ . iter ( )
165+ . map ( |requirement| {
166+ serde:: Serialize :: serialize (
167+ & requirement,
168+ toml_edit:: ser:: ValueSerializer :: new ( ) ,
169+ )
170+ } )
171+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
154172
155- let requirements = match requirements. as_slice ( ) {
156- [ ] => Array :: new ( ) ,
157- [ requirement] => Array :: from_iter ( [ requirement] ) ,
158- requirements => each_element_on_its_line_array ( requirements. iter ( ) ) ,
159- } ;
160- value ( requirements)
161- } ) ;
173+ let requirements = match requirements. as_slice ( ) {
174+ [ ] => Array :: new ( ) ,
175+ [ requirement] => Array :: from_iter ( [ requirement] ) ,
176+ requirements => each_element_on_its_line_array ( requirements. iter ( ) ) ,
177+ } ;
178+ value ( requirements)
179+ } ) ;
180+ }
181+
182+ if !self . constraints . is_empty ( ) {
183+ table. insert ( "constraints" , {
184+ let constraints = self
185+ . constraints
186+ . iter ( )
187+ . map ( |constraint| {
188+ serde:: Serialize :: serialize (
189+ & constraint,
190+ toml_edit:: ser:: ValueSerializer :: new ( ) ,
191+ )
192+ } )
193+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
194+
195+ let constraints = match constraints. as_slice ( ) {
196+ [ ] => Array :: new ( ) ,
197+ [ constraint] => Array :: from_iter ( [ constraint] ) ,
198+ constraints => each_element_on_its_line_array ( constraints. iter ( ) ) ,
199+ } ;
200+ value ( constraints)
201+ } ) ;
202+ }
203+
204+ if !self . overrides . is_empty ( ) {
205+ table. insert ( "overrides" , {
206+ let overrides = self
207+ . overrides
208+ . iter ( )
209+ . map ( |r#override| {
210+ serde:: Serialize :: serialize (
211+ & r#override,
212+ toml_edit:: ser:: ValueSerializer :: new ( ) ,
213+ )
214+ } )
215+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
216+
217+ let overrides = match overrides. as_slice ( ) {
218+ [ ] => Array :: new ( ) ,
219+ [ r#override] => Array :: from_iter ( [ r#override] ) ,
220+ overrides => each_element_on_its_line_array ( overrides. iter ( ) ) ,
221+ } ;
222+ value ( overrides)
223+ } ) ;
224+ }
162225
163226 if let Some ( ref python) = self . python {
164227 table. insert ( "python" , value ( python) ) ;
@@ -196,6 +259,14 @@ impl Tool {
196259 & self . requirements
197260 }
198261
262+ pub fn constraints ( & self ) -> & [ Requirement ] {
263+ & self . constraints
264+ }
265+
266+ pub fn overrides ( & self ) -> & [ Requirement ] {
267+ & self . overrides
268+ }
269+
199270 pub fn python ( & self ) -> & Option < String > {
200271 & self . python
201272 }
0 commit comments