@@ -43,7 +43,7 @@ def get_dependencies(
4343
4444 if exit_code != 0 :
4545 location = self ._get_pip_location (executor , working_dir )
46- scope = "system" if location == "system" else "project"
46+ scope = "system" if self . _is_system_location ( location ) else "project"
4747 result : dict [str , Any ] = {"scope" : scope }
4848 if scope == "project" :
4949 result ["location" ] = location
@@ -62,7 +62,7 @@ def get_dependencies(
6262 }
6363
6464 location = self ._get_pip_location (executor , working_dir )
65- scope = "system" if location == "system" else "project"
65+ scope = "system" if self . _is_system_location ( location ) else "project"
6666
6767 # Build result with desired field order: scope, location, hash, dependencies
6868 final_result : dict [str , Any ] = {"scope" : scope }
@@ -77,23 +77,23 @@ def get_dependencies(
7777
7878 return final_result
7979
80+ def _is_system_location (self , location : str ) -> bool :
81+ """Check if a location path represents a system-wide installation."""
82+ return location .startswith (("/usr/lib" , "/usr/local/lib" ))
83+
8084 def _get_pip_location (self , executor : EnvironmentExecutor , working_dir : Optional [str ] = None ) -> str :
81- """Get the location of the pip environment, properly classifying system vs project scope ."""
85+ """Get the actual location path of the pip environment."""
8286 pip_command = self ._get_pip_command (executor , working_dir )
8387 stdout , _ , exit_code = executor .execute_command (f"{ pip_command } show pip" , working_dir )
8488
8589 if exit_code == 0 :
8690 for line in stdout .split ("\n " ):
8791 if line .startswith ("Location:" ):
8892 location = line .split (":" , 1 )[1 ].strip ()
89-
90- # Check if this is a system location
91- if location .startswith (("/usr/lib" , "/usr/local/lib" )):
92- return "system"
93-
9493 return location
9594
96- return "system"
95+ # Fallback: return a default system location when pip location cannot be determined
96+ return "/usr/lib/python3/dist-packages"
9797
9898 def _get_pip_command (self , executor : EnvironmentExecutor , working_dir : Optional [str ] = None ) -> str :
9999 """Get the appropriate pip command, activating venv if available."""
@@ -291,5 +291,6 @@ def _generate_location_hash(self, executor: EnvironmentExecutor, location: str)
291291 return ""
292292
293293 def has_system_scope (self , executor : EnvironmentExecutor , working_dir : Optional [str ] = None ) -> bool :
294- """PIP has system scope when no virtual environment is found."""
295- return self ._get_pip_location (executor , working_dir ) == "system"
294+ """PIP has system scope when pip is installed in a system location."""
295+ location = self ._get_pip_location (executor , working_dir )
296+ return self ._is_system_location (location )
0 commit comments