@@ -31,6 +31,11 @@ pub struct Args {
3131/// Defaults to the default environment. 
3232#[ arg( short,  long) ]  
3333    pub  environment :  Option < String > , 
34+ 
35+     /// The name to use for the rendered conda environment. 
36+ /// Defaults to the environment name. 
37+ #[ arg( short,  long) ]  
38+     pub  name :  Option < String > , 
3439} 
3540
3641fn  format_pip_extras ( extras :  & [ ExtraName ] )  -> String  { 
@@ -128,11 +133,12 @@ fn build_env_yaml(
128133    platform :  & Platform , 
129134    environment :  & Environment , 
130135    config :  & ChannelConfig , 
136+     name :  String , 
131137)  -> miette:: Result < EnvironmentYaml >  { 
132138    let  channels =
133139        channels_with_nodefaults ( environment. channels ( ) . into_iter ( ) . cloned ( ) . collect_vec ( ) ) ; 
134140    let  mut  env_yaml = rattler_conda_types:: EnvironmentYaml  { 
135-         name :  Some ( environment . name ( ) . as_str ( ) . to_string ( ) ) , 
141+         name :  Some ( name) , 
136142        channels, 
137143        ..Default :: default ( ) 
138144    } ; 
@@ -228,8 +234,16 @@ pub async fn execute(args: Args) -> miette::Result<()> {
228234    let  environment = workspace. environment_from_name_or_env_var ( args. environment ) ?; 
229235    let  platform = args. platform . unwrap_or_else ( || environment. best_platform ( ) ) ; 
230236    let  config = workspace. config ( ) ; 
237+     let  name = args
238+         . name 
239+         . unwrap_or_else ( || environment. name ( ) . as_str ( ) . to_string ( ) ) ; 
231240
232-     let  env_yaml = build_env_yaml ( & platform,  & environment,  config. global_channel_config ( ) ) ?; 
241+     let  env_yaml = build_env_yaml ( 
242+         & platform, 
243+         & environment, 
244+         config. global_channel_config ( ) , 
245+         name, 
246+     ) ?; 
233247
234248    if  let  Some ( output_path)  = args. output_path  { 
235249        env_yaml
@@ -259,6 +273,7 @@ mod tests {
259273            platform :  Some ( Platform :: Osx64 ) , 
260274            environment :  Some ( "default" . to_string ( ) ) , 
261275            workspace_config :  WorkspaceConfig :: default ( ) , 
276+             name :  None , 
262277        } ; 
263278        let  environment = workspace
264279            . environment_from_name_or_env_var ( args. environment ) 
@@ -269,6 +284,7 @@ mod tests {
269284            & platform, 
270285            & environment, 
271286            workspace. config ( ) . global_channel_config ( ) , 
287+             environment. name ( ) . as_str ( ) . to_string ( ) , 
272288        ) ; 
273289        insta:: assert_snapshot!( 
274290            "test_export_conda_env_yaml" , 
@@ -285,6 +301,7 @@ mod tests {
285301            platform :  None , 
286302            environment :  Some ( "default" . to_string ( ) ) , 
287303            workspace_config :  WorkspaceConfig :: default ( ) , 
304+             name :  None , 
288305        } ; 
289306        let  environment = workspace
290307            . environment_from_name_or_env_var ( args. environment ) 
@@ -295,6 +312,7 @@ mod tests {
295312            & platform, 
296313            & environment, 
297314            workspace. config ( ) . global_channel_config ( ) , 
315+             environment. name ( ) . as_str ( ) . to_string ( ) , 
298316        ) ; 
299317        insta:: assert_snapshot!( 
300318            "test_export_conda_env_yaml_with_pip_extras" , 
@@ -312,6 +330,7 @@ mod tests {
312330            platform :  None , 
313331            environment :  Some ( "default" . to_string ( ) ) , 
314332            workspace_config :  WorkspaceConfig :: default ( ) , 
333+             name :  None , 
315334        } ; 
316335        let  environment = workspace
317336            . environment_from_name_or_env_var ( args. environment ) 
@@ -322,6 +341,7 @@ mod tests {
322341            & platform, 
323342            & environment, 
324343            workspace. config ( ) . global_channel_config ( ) , 
344+             environment. name ( ) . as_str ( ) . to_string ( ) , 
325345        ) ; 
326346        insta:: assert_snapshot!( 
327347            "test_export_conda_env_yaml_with_source_editable" , 
@@ -344,6 +364,7 @@ mod tests {
344364            platform :  None , 
345365            environment :  Some ( "alternative" . to_string ( ) ) , 
346366            workspace_config :  WorkspaceConfig :: default ( ) , 
367+             name :  None , 
347368        } ; 
348369        let  environment = workspace
349370            . environment_from_name_or_env_var ( args. environment ) 
@@ -354,6 +375,7 @@ mod tests {
354375            & platform, 
355376            & environment, 
356377            workspace. config ( ) . global_channel_config ( ) , 
378+             environment. name ( ) . as_str ( ) . to_string ( ) , 
357379        ) ; 
358380        insta:: assert_snapshot!( 
359381            "test_export_conda_env_yaml_with_pip_custom_registry" , 
@@ -371,6 +393,7 @@ mod tests {
371393            platform :  None , 
372394            environment :  Some ( "default" . to_string ( ) ) , 
373395            workspace_config :  WorkspaceConfig :: default ( ) , 
396+             name :  None , 
374397        } ; 
375398        let  environment = workspace
376399            . environment_from_name_or_env_var ( args. environment ) 
@@ -381,6 +404,7 @@ mod tests {
381404            & platform, 
382405            & environment, 
383406            workspace. config ( ) . global_channel_config ( ) , 
407+             environment. name ( ) . as_str ( ) . to_string ( ) , 
384408        ) ; 
385409        insta:: assert_snapshot!( 
386410            "test_export_conda_env_yaml_with_pip_find_links" , 
@@ -397,6 +421,7 @@ mod tests {
397421            platform :  Some ( Platform :: OsxArm64 ) , 
398422            environment :  Some ( "default" . to_string ( ) ) , 
399423            workspace_config :  WorkspaceConfig :: default ( ) , 
424+             name :  None , 
400425        } ; 
401426        let  environment = workspace
402427            . environment_from_name_or_env_var ( args. environment ) 
@@ -407,6 +432,7 @@ mod tests {
407432            & platform, 
408433            & environment, 
409434            workspace. config ( ) . global_channel_config ( ) , 
435+             environment. name ( ) . as_str ( ) . to_string ( ) , 
410436        ) ; 
411437        insta:: assert_snapshot!( 
412438            "test_export_conda_env_yaml_pyproject_panic" , 
@@ -431,6 +457,7 @@ mod tests {
431457            platform :  Some ( Platform :: Osx64 ) , 
432458            environment :  None , 
433459            workspace_config :  WorkspaceConfig :: default ( ) , 
460+             name :  None , 
434461        } ; 
435462        let  environment = workspace
436463            . environment_from_name_or_env_var ( args. environment ) 
@@ -441,6 +468,7 @@ mod tests {
441468            & platform, 
442469            & environment, 
443470            workspace. config ( ) . global_channel_config ( ) , 
471+             environment. name ( ) . as_str ( ) . to_string ( ) , 
444472        ) ; 
445473        insta:: assert_snapshot!( 
446474            "test_export_conda_env_yaml_with_defaults" , 
@@ -464,4 +492,34 @@ mod tests {
464492            ] 
465493        ) ; 
466494    } 
495+ 
496+     #[ test]  
497+     fn  test_specify_output_name ( )  { 
498+         let  path = Path :: new ( env ! ( "CARGO_WORKSPACE_DIR" ) ) 
499+             . join ( "tests/data/mock-projects/test-project-export/pixi.toml" ) ; 
500+         let  workspace = Workspace :: from_path ( & path) . unwrap ( ) ; 
501+         let  env_name = "custom_env_name" . to_string ( ) ; 
502+         let  args = Args  { 
503+             output_path :  None , 
504+             platform :  Some ( Platform :: Osx64 ) , 
505+             environment :  Some ( "default" . to_string ( ) ) , 
506+             workspace_config :  WorkspaceConfig :: default ( ) , 
507+             name :  Some ( env_name. clone ( ) ) , 
508+         } ; 
509+         let  environment = workspace
510+             . environment_from_name_or_env_var ( args. environment ) 
511+             . unwrap ( ) ; 
512+         let  platform = args. platform . unwrap_or_else ( || environment. best_platform ( ) ) ; 
513+ 
514+         let  env_yaml = build_env_yaml ( 
515+             & platform, 
516+             & environment, 
517+             workspace. config ( ) . global_channel_config ( ) , 
518+             env_name, 
519+         ) ; 
520+         insta:: assert_snapshot!( 
521+             "test_export_conda_env_yaml_custom_name" , 
522+             env_yaml. unwrap( ) . to_yaml_string( ) 
523+         ) ; 
524+     } 
467525} 
0 commit comments