@@ -145,8 +145,7 @@ def _find_venv_path(self, executor: EnvironmentExecutor, working_dir: Optional[s
145145 self ._venv_path_searched = True
146146 return venv_path
147147
148- # 3. Extract venv path from pip show pip location (fallback method) - check immediately
149- # Use basic pip command to avoid circular dependency with _get_pip_command
148+ # 3. Extract venv path from pip show pip location
150149 stdout , _ , exit_code = executor .execute_command ("pip show pip" , working_dir )
151150 if exit_code == 0 :
152151 for line in stdout .split ("\n " ):
@@ -163,22 +162,30 @@ def _find_venv_path(self, executor: EnvironmentExecutor, working_dir: Optional[s
163162
164163 # 4. Batch search for remaining venv locations
165164 # Collect all paths and use single find command for efficiency (fewer executor calls)
166- search_paths = []
165+ search_paths = set ()
167166 common_venv_names = ["venv" , ".venv" , "env" , ".env" , "virtualenv" ]
168167
169- # Check working directory and its subdirectories ( if working_dir specified)
168+ # Check working directory, if specified
170169 if working_dir :
171- search_paths .append (working_dir ) # working_dir itself
170+ search_paths .add (working_dir ) # working_dir itself
172171 for venv_name in common_venv_names :
173- search_paths .append (f"{ working_dir } /{ venv_name } " )
172+ search_paths .add (f"{ working_dir } /{ venv_name } " )
173+
174+ # Check current directory, if running in container environment
175+ if not isinstance (executor , HostExecutor ):
176+ pwd_stdout , _ , pwd_exit_code = executor .execute_command ("pwd" )
177+ if pwd_exit_code == 0 and pwd_stdout .strip ():
178+ current_dir = pwd_stdout .strip ()
179+ for venv_name in common_venv_names :
180+ search_paths .add (f"{ current_dir } /{ venv_name } " )
174181
175182 # Check home directory subdirectories (always check)
176183 # Resolve home directory explicitly to avoid tilde expansion issues
177184 home_stdout , _ , home_exit_code = executor .execute_command ("echo $HOME" )
178185 if home_exit_code == 0 and home_stdout .strip ():
179186 home_dir = home_stdout .strip ()
180187 for venv_name in common_venv_names :
181- search_paths .append (f"{ home_dir } /{ venv_name } " )
188+ search_paths .add (f"{ home_dir } /{ venv_name } " )
182189
183190 # External venv locations (project-specific, only if working_dir specified)
184191 if working_dir :
@@ -194,7 +201,7 @@ def _find_venv_path(self, executor: EnvironmentExecutor, working_dir: Optional[s
194201 f"{ home_dir } /.cache/pypoetry/virtualenvs/{ project_name } " ,
195202 f"{ home_dir } /.pyenv/versions/{ project_name } " ,
196203 ]
197- search_paths .extend (external_locations )
204+ search_paths .update (external_locations )
198205
199206 if search_paths :
200207 escaped_paths = [f"'{ path } '" for path in search_paths ]
0 commit comments