@@ -72,9 +72,9 @@ use crate::commands::project::lock::LockMode;
7272use crate :: commands:: project:: lock_target:: LockTarget ;
7373use crate :: commands:: project:: {
7474 EnvironmentSpecification , LinkErrorReporting , PreferenceLocation , ProjectEnvironment ,
75- ProjectError , ScriptEnvironment , ScriptInterpreter , UniversalState , WorkspacePython ,
76- default_dependency_groups , script_extra_build_requires, script_specification,
77- update_environment , validate_project_requires_python,
75+ ProjectError , ScriptEnvironment , UniversalState , WorkspacePython , default_dependency_groups ,
76+ script_extra_build_requires, script_specification, update_environment ,
77+ validate_project_requires_python,
7878} ;
7979use crate :: commands:: reporters:: PythonDownloadReporter ;
8080use crate :: commands:: { ExitStatus , diagnostics, project, read_env_files} ;
@@ -178,7 +178,6 @@ pub(crate) async fn run(
178178 let mut base_lock: Option < ( Lock , PathBuf ) > = None ;
179179
180180 // Determine whether the command to execute is a PEP 723 script.
181- let temp_dir;
182181 let script_interpreter = if let Some ( script) = script {
183182 match & script {
184183 Pep723Item :: Script ( script) => {
@@ -361,140 +360,105 @@ pub(crate) async fn run(
361360 }
362361 }
363362
364- // Install the script requirements, if necessary. Otherwise, use an isolated environment.
365- if let Some ( spec) = script_specification (
363+ // Install the script requirements, if necessary.
364+ let spec = script_specification (
365+ ( & script) . into ( ) ,
366+ & settings. resolver ,
367+ & cache,
368+ workspace_cache,
369+ client_builder. credentials_cache ( ) ,
370+ )
371+ . await ?;
372+ let script_extra_build_requires = script_extra_build_requires (
366373 ( & script) . into ( ) ,
367374 & settings. resolver ,
368375 & cache,
369376 workspace_cache,
370377 client_builder. credentials_cache ( ) ,
371378 )
372379 . await ?
373- {
374- let script_extra_build_requires = script_extra_build_requires (
375- ( & script) . into ( ) ,
376- & settings. resolver ,
377- & cache,
378- workspace_cache,
379- client_builder. credentials_cache ( ) ,
380- )
381- . await ?
382- . into_inner ( ) ;
383- let environment = ScriptEnvironment :: get_or_init (
384- ( & script) . into ( ) ,
385- python. as_deref ( ) . map ( PythonRequest :: parse) ,
386- & client_builder,
387- python_preference,
388- python_downloads,
389- & install_mirrors,
390- no_sync,
391- config_discovery,
392- active. map_or ( Some ( false ) , Some ) ,
393- & cache,
394- DryRun :: Disabled ,
395- printer,
396- )
397- . await ?
398- . into_environment ( ) ?;
380+ . into_inner ( ) ;
381+ let environment = ScriptEnvironment :: get_or_init (
382+ ( & script) . into ( ) ,
383+ python. as_deref ( ) . map ( PythonRequest :: parse) ,
384+ & client_builder,
385+ python_preference,
386+ python_downloads,
387+ & install_mirrors,
388+ no_sync,
389+ config_discovery,
390+ active. map_or ( Some ( false ) , Some ) ,
391+ & cache,
392+ DryRun :: Disabled ,
393+ printer,
394+ )
395+ . await ?
396+ . into_environment ( ) ?;
399397
400- let build_constraints = script
401- . metadata ( )
402- . tool
403- . as_ref ( )
404- . and_then ( |tool| {
405- tool. uv
406- . as_ref ( )
407- . and_then ( |uv| uv. build_constraint_dependencies . as_ref ( ) )
408- } )
409- . map ( |constraints| {
410- Constraints :: from_requirements (
411- constraints
412- . iter ( )
413- . map ( |constraint| Requirement :: from ( constraint. clone ( ) ) ) ,
414- )
415- } ) ;
416-
417- let _lock = environment
418- . lock ( )
419- . await
420- . inspect_err ( |err| {
421- warn ! ( "Failed to acquire environment lock: {err}" ) ;
422- } )
423- . ok ( ) ;
398+ let build_constraints = script
399+ . metadata ( )
400+ . tool
401+ . as_ref ( )
402+ . and_then ( |tool| {
403+ tool. uv
404+ . as_ref ( )
405+ . and_then ( |uv| uv. build_constraint_dependencies . as_ref ( ) )
406+ } )
407+ . map ( |constraints| {
408+ Constraints :: from_requirements (
409+ constraints
410+ . iter ( )
411+ . map ( |constraint| Requirement :: from ( constraint. clone ( ) ) ) ,
412+ )
413+ } ) ;
424414
425- match update_environment (
426- environment,
427- spec,
428- modifications,
429- python_platform. as_ref ( ) ,
430- SourceTreeEditablePolicy :: Project ,
431- build_constraints. unwrap_or_default ( ) ,
432- script_extra_build_requires,
433- & settings,
434- & client_builder,
435- & sync_state,
436- if show_resolution {
437- Box :: new ( DefaultResolveLogger )
438- } else {
439- Box :: new ( SummaryResolveLogger )
440- } ,
441- if show_resolution {
442- Box :: new ( DefaultInstallLogger )
443- } else {
444- Box :: new ( SummaryInstallLogger )
445- } ,
446- installer_metadata,
447- & concurrency,
448- & cache,
449- workspace_cache,
450- DryRun :: Disabled ,
451- printer,
452- preview,
453- )
415+ let _lock = environment
416+ . lock ( )
454417 . await
455- {
456- Ok ( update) => Some ( update. into_environment ( ) . into_interpreter ( ) ) ,
457- Err ( ProjectError :: Operation ( err) ) => {
458- return diagnostics:: OperationDiagnostic :: default ( )
459- . with_context ( "script" )
460- . report ( err)
461- . map_or ( Ok ( ExitStatus :: Failure ) , |err| Err ( err. into ( ) ) ) ;
462- }
463- Err ( err) => return Err ( err. into ( ) ) ,
464- }
465- } else {
466- // Create a virtual environment.
467- let interpreter = ScriptInterpreter :: discover (
468- ( & script) . into ( ) ,
469- python. as_deref ( ) . map ( PythonRequest :: parse) ,
470- & client_builder,
471- python_preference,
472- python_downloads,
473- & install_mirrors,
474- no_sync,
475- config_discovery,
476- active. map_or ( Some ( false ) , Some ) ,
477- & cache,
478- printer,
479- )
480- . await ?
481- . into_interpreter ( ) ;
482-
483- temp_dir = cache. venv_dir ( ) ?;
484- let environment = uv_virtualenv:: create_venv (
485- temp_dir. path ( ) ,
486- interpreter,
487- uv_virtualenv:: Prompt :: None ,
488- false ,
489- uv_virtualenv:: OnExisting :: Remove (
490- uv_virtualenv:: RemovalReason :: TemporaryEnvironment ,
491- ) ,
492- false ,
493- uv_virtualenv:: Seed :: Disabled ,
494- false ,
495- ) ?;
418+ . inspect_err ( |err| {
419+ warn ! ( "Failed to acquire environment lock: {err}" ) ;
420+ } )
421+ . ok ( ) ;
496422
497- Some ( environment. into_interpreter ( ) )
423+ match update_environment (
424+ environment,
425+ spec,
426+ modifications,
427+ python_platform. as_ref ( ) ,
428+ SourceTreeEditablePolicy :: Project ,
429+ build_constraints. unwrap_or_default ( ) ,
430+ script_extra_build_requires,
431+ & settings,
432+ & client_builder,
433+ & sync_state,
434+ if show_resolution {
435+ Box :: new ( DefaultResolveLogger )
436+ } else {
437+ Box :: new ( SummaryResolveLogger )
438+ } ,
439+ if show_resolution {
440+ Box :: new ( DefaultInstallLogger )
441+ } else {
442+ Box :: new ( SummaryInstallLogger )
443+ } ,
444+ installer_metadata,
445+ & concurrency,
446+ & cache,
447+ workspace_cache,
448+ DryRun :: Disabled ,
449+ printer,
450+ preview,
451+ )
452+ . await
453+ {
454+ Ok ( update) => Some ( update. into_environment ( ) . into_interpreter ( ) ) ,
455+ Err ( ProjectError :: Operation ( err) ) => {
456+ return diagnostics:: OperationDiagnostic :: default ( )
457+ . with_context ( "script" )
458+ . report ( err)
459+ . map_or ( Ok ( ExitStatus :: Failure ) , |err| Err ( err. into ( ) ) ) ;
460+ }
461+ Err ( err) => return Err ( err. into ( ) ) ,
498462 }
499463 }
500464 } else {
0 commit comments