@@ -91,16 +91,18 @@ struct PythonEnvironment {
9191impl PythonEnvironment {
9292 fn new ( project_path : & Path , venv_path : Option < & str > ) -> Option < Self > {
9393 if let Some ( path) = venv_path {
94+ let prefix = PathBuf :: from ( path) ;
9495 // If an explicit path is provided and it's a valid venv, use it immediately.
95- if let Some ( env) = Self :: from_venv_prefix ( & PathBuf :: from ( path ) ) {
96+ if let Some ( env) = Self :: from_venv_prefix ( & prefix ) {
9697 return Some ( env) ;
9798 }
9899 // Explicit path was provided but was invalid. Continue searching.
99100 }
100101
101102 if let Ok ( virtual_env) = env:: var ( "VIRTUAL_ENV" ) {
102103 if !virtual_env. is_empty ( ) {
103- if let Some ( env) = Self :: from_venv_prefix ( & PathBuf :: from ( virtual_env) ) {
104+ let prefix = PathBuf :: from ( virtual_env) ;
105+ if let Some ( env) = Self :: from_venv_prefix ( & prefix) {
104106 return Some ( env) ;
105107 }
106108 }
@@ -157,12 +159,12 @@ impl PythonEnvironment {
157159 Ok ( p) => p,
158160 Err ( _) => return None ,
159161 } ;
160- let mut sys_path = Vec :: new ( ) ;
161-
162162 // which() might return a path inside a bin/Scripts dir, or directly the executable
163163 // We need the prefix, which is usually two levels up from the executable in standard layouts
164164 let bin_dir = python_path. parent ( ) ?;
165165 let prefix = bin_dir. parent ( ) ?;
166+
167+ let mut sys_path = Vec :: new ( ) ;
166168 sys_path. push ( bin_dir. to_path_buf ( ) ) ;
167169
168170 if let Some ( site_packages) = Self :: find_site_packages ( prefix) {
0 commit comments