@@ -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
@@ -206,7 +136,7 @@ async fn venv_impl(
206136 // If the default dependency-groups demand a higher requires-python
207137 // we should bias an empty venv to that to avoid churn.
208138 let default_groups = match & project {
209- Some ( project) => default_dependency_groups ( project. pyproject_toml ( ) ) . into_diagnostic ( ) ?,
139+ Some ( project) => default_dependency_groups ( project. pyproject_toml ( ) ) ?,
210140 None => DefaultGroups :: default ( ) ,
211141 } ;
212142 let groups = DependencyGroups :: default ( ) . with_defaults ( default_groups) ;
@@ -221,8 +151,7 @@ async fn venv_impl(
221151 project_dir,
222152 no_config,
223153 )
224- . await
225- . into_diagnostic ( ) ?;
154+ . await ?;
226155
227156 // Locate the Python interpreter to use in the environment
228157 let interpreter = {
@@ -239,9 +168,8 @@ async fn venv_impl(
239168 install_mirrors. python_downloads_json_url . as_deref ( ) ,
240169 preview,
241170 )
242- . await
243- . into_diagnostic ( ) ?;
244- report_interpreter ( & python, false , printer) . into_diagnostic ( ) ?;
171+ . await ?;
172+ report_interpreter ( & python, false , printer) ?;
245173 python. into_interpreter ( )
246174 } ;
247175
@@ -268,8 +196,7 @@ async fn venv_impl(
268196 "Creating virtual environment {}at: {}" ,
269197 if seed { "with seed packages " } else { "" } ,
270198 path. user_display( ) . cyan( )
271- )
272- . into_diagnostic ( ) ?;
199+ ) ?;
273200
274201 let upgradeable = preview. is_enabled ( )
275202 && python_request
@@ -307,8 +234,7 @@ async fn venv_impl(
307234 }
308235
309236 // Instantiate a client.
310- let client = RegistryClientBuilder :: try_from ( client_builder)
311- . into_diagnostic ( ) ?
237+ let client = RegistryClientBuilder :: try_from ( client_builder) ?
312238 . cache ( cache. clone ( ) )
313239 . index_locations ( index_locations)
314240 . index_strategy ( index_strategy)
@@ -400,9 +326,7 @@ async fn venv_impl(
400326 . map_err ( |err| VenvError :: Seed ( err. into ( ) ) ) ?;
401327
402328 let changelog = Changelog :: from_installed ( installed) ;
403- DefaultInstallLogger
404- . on_complete ( & changelog, printer)
405- . into_diagnostic ( ) ?;
329+ DefaultInstallLogger . on_complete ( & changelog, printer) ?;
406330 }
407331
408332 // Determine the appropriate activation command.
@@ -431,7 +355,7 @@ async fn venv_impl(
431355 Some ( Shell :: Cmd ) => Some ( shlex_windows ( venv. scripts ( ) . join ( "activate" ) , Shell :: Cmd ) ) ,
432356 } ;
433357 if let Some ( act) = activation {
434- writeln ! ( printer. stderr( ) , "Activate with: {}" , act. green( ) ) . into_diagnostic ( ) ?;
358+ writeln ! ( printer. stderr( ) , "Activate with: {}" , act. green( ) ) ?;
435359 }
436360
437361 Ok ( ExitStatus :: Success )
0 commit comments