33//! This module provides compile-time constants for directories and files that differ
44//! between Windows and Unix-like systems in Python virtual environments.
55
6+ use super :: errors:: BridgeError ;
7+ use std:: fs;
68use std:: path:: PathBuf ;
79
8- #[ derive( Debug ) ]
9- pub enum VenvErr {
10- BinaryNotFound ,
11- PackageNotFound ,
12- PackageDirNotFound ,
13- LibDirNotFound ,
14- VenvDirNotFound ,
15- IOError ( std:: io:: Error ) ,
16- }
17-
1810/// The name of the library directory in a Python venv (e.g., "Lib" on Windows, "lib" on Unix)
1911#[ cfg( windows) ]
2012pub const PYTHON_LIB_DIR : & str = "Lib" ;
@@ -66,6 +58,7 @@ pub fn resolve_site_package_path(venv_path: &PathBuf) -> Result<PathBuf, VenvErr
6658 return Err ( VenvErr :: LibDirNotFound ) ;
6759 }
6860
61+ // FIXME Return a VenvError -> Map to BridgeError in Initialization process
6962 let python_version_dir = std:: fs:: read_dir ( & lib_dir)
7063 . map_err ( |e| format ! ( "Failed to read lib directory: {}" , e) ) ?
7164 . filter_map ( |e| e. ok ( ) )
@@ -81,3 +74,19 @@ pub fn resolve_site_package_path(venv_path: &PathBuf) -> Result<PathBuf, VenvErr
8174 Ok ( site_packages)
8275 }
8376}
77+
78+ pub fn resolve_python_path ( venv_path : & PathBuf ) -> Result < PathBuf , VenvErr > {
79+ // validate venv path is a valid directory
80+ if !venv_path. is_dir ( ) {
81+ return Err ( VenvErr :: VenvDirNotFound ) ;
82+ }
83+
84+ let python_path = venv_path. join ( PYTHON_BIN_DIR ) . join ( PYTHON_EXE ) ;
85+
86+ // validate the interpreter path is valid
87+ if !python_path. is_file ( ) {
88+ return Err ( VenvErr :: BinaryNotFound ) ;
89+ }
90+
91+ return Ok ( python_path) ;
92+ }
0 commit comments