@@ -423,7 +423,7 @@ fn find_workspace_for_project(project_path: &Path) -> Option<PythonEnvironment>
423423/// Builds a `PythonEnvironment` for a uv workspace root if it has a `.venv` with a valid
424424/// uv-managed pyvenv.cfg.
425425fn build_workspace_env ( workspace_root : & Path ) -> Option < PythonEnvironment > {
426- let prefix = resolve_dot_venv ( workspace_root) ;
426+ let prefix = resolve_dot_venv ( workspace_root) ? ;
427427 let pyvenv_cfg = prefix. join ( "pyvenv.cfg" ) ;
428428 if !pyvenv_cfg. exists ( ) {
429429 trace ! (
@@ -466,25 +466,30 @@ fn list_envs_in_directory(path: &Path) -> Vec<PythonEnvironment> {
466466 let Some ( pyproject) = pyproject else {
467467 return envs;
468468 } ;
469- let pyvenv_cfg = resolve_dot_venv ( path) . join ( "pyvenv.cfg" ) ;
470469 let prefix = resolve_dot_venv ( path) ;
471- let unix_executable = prefix. join ( "bin/python" ) ;
472- let windows_executable = prefix. join ( "Scripts/python.exe" ) ;
473- let executable = if unix_executable. exists ( ) {
474- Some ( unix_executable)
475- } else if windows_executable. exists ( ) {
476- Some ( windows_executable)
477- } else {
478- None
479- } ;
470+ let uv_venv = prefix
471+ . as_ref ( )
472+ . map ( |p| p. join ( "pyvenv.cfg" ) )
473+ . and_then ( |cfg| UvVenv :: maybe_from_file ( & cfg) ) ;
474+ let executable = prefix. as_ref ( ) . and_then ( |p| {
475+ let unix_executable = p. join ( "bin/python" ) ;
476+ let windows_executable = p. join ( "Scripts/python.exe" ) ;
477+ if unix_executable. exists ( ) {
478+ Some ( unix_executable)
479+ } else if windows_executable. exists ( ) {
480+ Some ( windows_executable)
481+ } else {
482+ None
483+ }
484+ } ) ;
480485 if pyproject
481486 . tool
482487 . and_then ( |t| t. uv )
483488 . and_then ( |uv| uv. workspace )
484489 . is_some ( )
485490 {
486491 trace ! ( "Workspace found in {}" , path. display( ) ) ;
487- if let Some ( uv_venv) = UvVenv :: maybe_from_file ( & pyvenv_cfg ) {
492+ if let ( Some ( uv_venv) , Some ( prefix ) ) = ( uv_venv , prefix ) {
488493 trace ! ( "uv-managed venv found for workspace in {}" , path. display( ) ) ;
489494 let env = PythonEnvironmentBuilder :: new ( Some ( PythonEnvironmentKind :: UvWorkspace ) )
490495 . name ( Some ( uv_venv. prompt ) )
@@ -502,7 +507,7 @@ fn list_envs_in_directory(path: &Path) -> Vec<PythonEnvironment> {
502507 }
503508 // prioritize the workspace over the project if it's the same venv
504509 } else if let Some ( project) = pyproject. project {
505- if let Some ( uv_venv) = UvVenv :: maybe_from_file ( & pyvenv_cfg ) {
510+ if let ( Some ( uv_venv) , Some ( prefix ) ) = ( uv_venv , prefix ) {
506511 trace ! ( "uv-managed venv found for project in {}" , path. display( ) ) ;
507512 let env = PythonEnvironmentBuilder :: new ( Some ( PythonEnvironmentKind :: Uv ) )
508513 . name ( Some ( uv_venv. prompt ) )
0 commit comments