@@ -4,9 +4,7 @@ use std::str::FromStr;
44use std:: sync:: Arc ;
55use std:: vec;
66
7- use anstream:: eprint;
87use anyhow:: Result ;
9- use miette:: { Diagnostic , IntoDiagnostic } ;
108use owo_colors:: OwoColorize ;
119use thiserror:: Error ;
1210
@@ -42,96 +40,30 @@ use crate::settings::NetworkSettings;
4240
4341use super :: project:: default_dependency_groups;
4442
45- /// Create a virtual environment.
46- #[ allow( clippy:: unnecessary_wraps, clippy:: fn_params_excessive_bools) ]
47- pub ( crate ) async fn venv (
48- project_dir : & Path ,
49- path : Option < PathBuf > ,
50- python_request : Option < PythonRequest > ,
51- install_mirrors : PythonInstallMirrors ,
52- python_preference : PythonPreference ,
53- python_downloads : PythonDownloads ,
54- link_mode : LinkMode ,
55- index_locations : & IndexLocations ,
56- index_strategy : IndexStrategy ,
57- dependency_metadata : DependencyMetadata ,
58- keyring_provider : KeyringProviderType ,
59- network_settings : & NetworkSettings ,
60- prompt : uv_virtualenv:: Prompt ,
61- system_site_packages : bool ,
62- seed : bool ,
63- allow_existing : bool ,
64- exclude_newer : Option < ExcludeNewer > ,
65- concurrency : Concurrency ,
66- no_config : bool ,
67- no_project : bool ,
68- cache : & Cache ,
69- printer : Printer ,
70- relocatable : bool ,
71- preview : PreviewMode ,
72- ) -> Result < ExitStatus > {
73- match venv_impl (
74- project_dir,
75- path,
76- python_request,
77- install_mirrors,
78- link_mode,
79- index_locations,
80- index_strategy,
81- dependency_metadata,
82- keyring_provider,
83- network_settings,
84- prompt,
85- system_site_packages,
86- seed,
87- python_preference,
88- python_downloads,
89- allow_existing,
90- exclude_newer,
91- concurrency,
92- no_config,
93- no_project,
94- cache,
95- printer,
96- relocatable,
97- preview,
98- )
99- . await
100- {
101- Ok ( status) => Ok ( status) ,
102- Err ( err) => {
103- eprint ! ( "{err:?}" ) ;
104- Ok ( ExitStatus :: Failure )
105- }
106- }
107- }
108-
109- #[ derive( Error , Debug , Diagnostic ) ]
43+ #[ derive( Error , Debug ) ]
11044enum VenvError {
111- #[ error( "Failed to create virtualenv" ) ]
112- #[ diagnostic( code( uv:: venv:: creation) ) ]
45+ #[ error( "Failed to create virtual environment" ) ]
11346 Creation ( #[ source] uv_virtualenv:: Error ) ,
11447
115- #[ error( "Failed to install seed packages" ) ]
116- #[ diagnostic( code( uv:: venv:: seed) ) ]
48+ #[ error( "Failed to install seed packages into virtual environment" ) ]
11749 Seed ( #[ source] AnyErrorBuild ) ,
11850
119- #[ error( "Failed to extract interpreter tags" ) ]
120- #[ diagnostic( code( uv:: venv:: tags) ) ]
51+ #[ error( "Failed to extract interpreter tags for installing seed packages" ) ]
12152 Tags ( #[ source] uv_platform_tags:: TagsError ) ,
12253
12354 #[ error( "Failed to resolve `--find-links` entry" ) ]
124- #[ diagnostic( code( uv:: venv:: flat_index) ) ]
12555 FlatIndex ( #[ source] uv_client:: FlatIndexError ) ,
12656}
12757
12858/// Create a virtual environment.
129- #[ allow( clippy:: fn_params_excessive_bools) ]
130- async fn venv_impl (
59+ #[ allow( clippy:: unnecessary_wraps , clippy :: fn_params_excessive_bools) ]
60+ pub ( crate ) async fn venv (
13161 project_dir : & Path ,
13262 path : Option < PathBuf > ,
13363 python_request : Option < PythonRequest > ,
13464 install_mirrors : PythonInstallMirrors ,
65+ python_preference : PythonPreference ,
66+ python_downloads : PythonDownloads ,
13567 link_mode : LinkMode ,
13668 index_locations : & IndexLocations ,
13769 index_strategy : IndexStrategy ,
@@ -141,8 +73,6 @@ async fn venv_impl(
14173 prompt : uv_virtualenv:: Prompt ,
14274 system_site_packages : bool ,
14375 seed : bool ,
144- python_preference : PythonPreference ,
145- python_downloads : PythonDownloads ,
14676 allow_existing : bool ,
14777 exclude_newer : Option < ExcludeNewer > ,
14878 concurrency : Concurrency ,
@@ -152,7 +82,7 @@ async fn venv_impl(
15282 printer : Printer ,
15383 relocatable : bool ,
15484 preview : PreviewMode ,
155- ) -> miette :: Result < ExitStatus > {
85+ ) -> Result < ExitStatus > {
15686 let workspace_cache = WorkspaceCache :: default ( ) ;
15787 let project = if no_project {
15888 None
@@ -203,7 +133,7 @@ async fn venv_impl(
203133 // If the default dependency-groups demand a higher requires-python
204134 // we should bias an empty venv to that to avoid churn.
205135 let default_groups = match & project {
206- Some ( project) => default_dependency_groups ( project. pyproject_toml ( ) ) . into_diagnostic ( ) ?,
136+ Some ( project) => default_dependency_groups ( project. pyproject_toml ( ) ) ?,
207137 None => DefaultGroups :: default ( ) ,
208138 } ;
209139 let groups = DependencyGroups :: default ( ) . with_defaults ( default_groups) ;
@@ -218,8 +148,7 @@ async fn venv_impl(
218148 project_dir,
219149 no_config,
220150 )
221- . await
222- . into_diagnostic ( ) ?;
151+ . await ?;
223152
224153 // Locate the Python interpreter to use in the environment
225154 let interpreter = {
@@ -236,9 +165,8 @@ async fn venv_impl(
236165 install_mirrors. python_downloads_json_url . as_deref ( ) ,
237166 preview,
238167 )
239- . await
240- . into_diagnostic ( ) ?;
241- report_interpreter ( & python, false , printer) . into_diagnostic ( ) ?;
168+ . await ?;
169+ report_interpreter ( & python, false , printer) ?;
242170 python. into_interpreter ( )
243171 } ;
244172
@@ -265,8 +193,7 @@ async fn venv_impl(
265193 "Creating virtual environment {}at: {}" ,
266194 if seed { "with seed packages " } else { "" } ,
267195 path. user_display( ) . cyan( )
268- )
269- . into_diagnostic ( ) ?;
196+ ) ?;
270197
271198 let upgradeable = preview. is_enabled ( )
272199 && python_request
@@ -304,8 +231,7 @@ async fn venv_impl(
304231 }
305232
306233 // Instantiate a client.
307- let client = RegistryClientBuilder :: try_from ( client_builder)
308- . into_diagnostic ( ) ?
234+ let client = RegistryClientBuilder :: try_from ( client_builder) ?
309235 . cache ( cache. clone ( ) )
310236 . index_locations ( index_locations)
311237 . index_strategy ( index_strategy)
@@ -397,9 +323,7 @@ async fn venv_impl(
397323 . map_err ( |err| VenvError :: Seed ( err. into ( ) ) ) ?;
398324
399325 let changelog = Changelog :: from_installed ( installed) ;
400- DefaultInstallLogger
401- . on_complete ( & changelog, printer)
402- . into_diagnostic ( ) ?;
326+ DefaultInstallLogger . on_complete ( & changelog, printer) ?;
403327 }
404328
405329 // Determine the appropriate activation command.
@@ -428,7 +352,7 @@ async fn venv_impl(
428352 Some ( Shell :: Cmd ) => Some ( shlex_windows ( venv. scripts ( ) . join ( "activate" ) , Shell :: Cmd ) ) ,
429353 } ;
430354 if let Some ( act) = activation {
431- writeln ! ( printer. stderr( ) , "Activate with: {}" , act. green( ) ) . into_diagnostic ( ) ?;
355+ writeln ! ( printer. stderr( ) , "Activate with: {}" , act. green( ) ) ?;
432356 }
433357
434358 Ok ( ExitStatus :: Success )
0 commit comments