@@ -9,21 +9,21 @@ use std::path::PathBuf;
99
1010/// The name of the library directory in a Python venv (e.g., "Lib" on Windows, "lib" on Unix)
1111#[ cfg( windows) ]
12- pub const PYTHON_LIB_DIR : & str = "Lib" ;
12+ const PYTHON_LIB_DIR : & str = "Lib" ;
1313#[ cfg( not( windows) ) ]
14- pub const PYTHON_LIB_DIR : & str = "lib" ;
14+ const PYTHON_LIB_DIR : & str = "lib" ;
1515
1616/// The name of the binaries/scripts directory in a Python venv (e.g., "Scripts" on Windows, "bin" on Unix)
1717#[ cfg( windows) ]
18- pub const PYTHON_BIN_DIR : & str = "Scripts" ;
18+ const PYTHON_BIN_DIR : & str = "Scripts" ;
1919#[ cfg( not( windows) ) ]
20- pub const PYTHON_BIN_DIR : & str = "bin" ;
20+ const PYTHON_BIN_DIR : & str = "bin" ;
2121
2222/// The name of the Python executable in a venv (e.g., "python.exe" on Windows, "python" on Unix)
2323#[ cfg( windows) ]
24- pub const PYTHON_EXE : & str = "python.exe" ;
24+ const PYTHON_EXE : & str = "python.exe" ;
2525#[ cfg( not( windows) ) ]
26- pub const PYTHON_EXE : & str = "python" ;
26+ const PYTHON_EXE : & str = "python" ;
2727
2828// Site Packages differences.
2929//
@@ -33,10 +33,10 @@ pub const PYTHON_EXE: &str = "python";
3333// Windows
3434// .venv/Lib/site-packages
3535
36- pub fn resolve_site_package_path ( venv_path : & PathBuf ) -> Result < PathBuf , VenvErr > {
36+ pub fn resolve_site_package_path ( venv_path : & PathBuf ) -> Result < PathBuf , BridgeError > {
3737 // Verify the venv_path exists and is a directory.
3838 if !venv_path. is_dir ( ) {
39- return Err ( VenvErr :: VenvDirNotFound ) ;
39+ return Err ( BridgeError :: VenvNotFound ( venv_path . to_path_buf ( ) ) ) ;
4040 }
4141
4242 #[ cfg( windows) ]
@@ -45,7 +45,10 @@ pub fn resolve_site_package_path(venv_path: &PathBuf) -> Result<PathBuf, VenvErr
4545
4646 // verify site_package_path exists
4747 if !site_packages. is_dir ( ) {
48- return Err ( VenvErr :: PackageDirNotFound ) ;
48+ return Err ( BridgeError :: Initialization ( format ! (
49+ "unable to locate package directory: {}" ,
50+ site_packages. display( )
51+ ) ) ) ;
4952 }
5053 Ok ( site_packages)
5154 }
@@ -55,37 +58,48 @@ pub fn resolve_site_package_path(venv_path: &PathBuf) -> Result<PathBuf, VenvErr
5558 let lib_dir = venv_path. join ( PYTHON_LIB_DIR ) ;
5659
5760 if !lib_dir. is_dir ( ) {
58- return Err ( VenvErr :: LibDirNotFound ) ;
61+ return Err ( BridgeError :: Initialization ( format ! (
62+ "unable to locate lib directory: {}" ,
63+ lib_dir. display( )
64+ ) ) ) ;
5965 }
6066
61- // FIXME Return a VenvError -> Map to BridgeError in Initialization process
62- let python_version_dir = std:: fs:: read_dir ( & lib_dir)
63- . map_err ( |e| format ! ( "Failed to read lib directory: {}" , e) ) ?
67+ let python_version_dir = fs:: read_dir ( & lib_dir)
68+ . map_err ( |e| {
69+ BridgeError :: Initialization ( format ! ( "Failed to read lib directory: {}" , e) )
70+ } ) ?
6471 . filter_map ( |e| e. ok ( ) )
6572 . find ( |e| e. file_name ( ) . to_string_lossy ( ) . starts_with ( "python" ) )
66- . ok_or_else ( || "No python directory found in venv" . to_string ( ) ) ?;
73+ . ok_or_else ( || {
74+ BridgeError :: Initialization ( "No python3.X directory found in venv/lib" . to_string ( ) )
75+ } ) ?;
6776
6877 let site_packages = python_version_dir. path ( ) . join ( "site-packages" ) ;
6978
7079 if !site_packages. is_dir ( ) {
71- return Err ( VenvErr :: LibDirNotFound ) ;
80+ return Err ( BridgeError :: Initialization ( format ! (
81+ "unable to locate package directory: {}" ,
82+ site_packages. display( )
83+ ) ) ) ;
7284 }
7385
7486 Ok ( site_packages)
7587 }
7688}
7789
78- pub fn resolve_python_path ( venv_path : & PathBuf ) -> Result < PathBuf , VenvErr > {
90+ pub fn resolve_python_path ( venv_path : & PathBuf ) -> Result < PathBuf , BridgeError > {
7991 // validate venv path is a valid directory
8092 if !venv_path. is_dir ( ) {
81- return Err ( VenvErr :: VenvDirNotFound ) ;
93+ return Err ( BridgeError :: VenvNotFound ( venv_path . to_path_buf ( ) ) ) ;
8294 }
8395
8496 let python_path = venv_path. join ( PYTHON_BIN_DIR ) . join ( PYTHON_EXE ) ;
85-
8697 // validate the interpreter path is valid
8798 if !python_path. is_file ( ) {
88- return Err ( VenvErr :: BinaryNotFound ) ;
99+ return Err ( BridgeError :: Initialization ( format ! (
100+ "Path to python binary is not valid: {}" ,
101+ python_path. display( )
102+ ) ) ) ;
89103 }
90104
91105 return Ok ( python_path) ;
0 commit comments