diff --git a/bindings/sysman/python/source/pyzes.py b/bindings/sysman/python/source/pyzes.py index d6329fde..f7841f50 100644 --- a/bindings/sysman/python/source/pyzes.py +++ b/bindings/sysman/python/source/pyzes.py @@ -67,13 +67,9 @@ def _LoadZeLibrary(): # load the library libName = "ze_loader" if sys.platform.startswith("linux"): - print("Loading Linux library") libName = "/usr/lib/x86_64-linux-gnu/lib" + libName + ".so.1" else: - print("Loading Windows library") # Try multiple common locations for Windows Intel GPU drivers - import os - possible_paths = [ # Try system PATH first libName + "64.dll", @@ -86,42 +82,29 @@ def _LoadZeLibrary(): library_loaded = False for path in possible_paths: - try: - if "*" in path: - # Handle wildcard paths for driver store - import glob - - matching_paths = glob.glob(path) - for match_path in matching_paths: - try: - print(f"Trying: {match_path}") - gpuLib = CDLL(match_path) - library_loaded = True - print(f"Successfully loaded: {match_path}") - break - except Exception as e: - print(f"Failed to load {match_path}: {e}") - continue - else: - if os.path.exists(path): - print(f"Trying: {path}") - gpuLib = CDLL(path) - library_loaded = True - print(f"Successfully loaded: {path}") - break - else: - print(f"Trying: {path}") - gpuLib = CDLL(path) - library_loaded = True - print(f"Successfully loaded: {path}") - break - except Exception as e: - print(f"Failed to load {path}: {e}") - continue - if library_loaded: break + if "*" in path: + # Handle wildcard paths for driver store + import glob + + matching_paths = glob.glob(path) + for match_path in matching_paths: + try: + gpuLib = CDLL(match_path) + library_loaded = True + break + except OSError: + pass # Try next path + else: + # Try loading the library directly + try: + gpuLib = CDLL(path) + library_loaded = True + except OSError: + pass # Try next path + if not library_loaded: raise Exception( f"Failed to load Intel GPU library. Tried paths: {possible_paths}" diff --git a/bindings/sysman/python/test/unit_tests/test_init.py b/bindings/sysman/python/test/unit_tests/test_init.py index 13fa42a9..c2585dee 100644 --- a/bindings/sysman/python/test/unit_tests/test_init.py +++ b/bindings/sysman/python/test/unit_tests/test_init.py @@ -118,13 +118,9 @@ def test_GivenLibraryAlreadyLoadedWhenCallingLoadZeLibraryThenReturnsEarly(self) try: # This should return early without any library loading - with patch("builtins.print") as mock_print: - self.pyzes._LoadZeLibrary() - # Should not print "Loading Linux library" because it returns early - print_calls = [ - call.args[0] for call in mock_print.call_args_list if call.args - ] - self.assertNotIn("Loading Linux library", print_calls) + self.pyzes._LoadZeLibrary() + # Verify gpuLib remains unchanged (early return) + self.assertEqual(self.pyzes.gpuLib, mock_lib) finally: # Restore original state self.pyzes.gpuLib = original_gpuLib @@ -201,11 +197,10 @@ def test_GivenValidLibraryWhenGettingNewFunctionPointerThenCachesAndReturnsFunct @patch("sys.platform", "win32") @patch("pyzes.gpuLib", None) - @patch("builtins.print") @patch("os.path.exists") @patch("pyzes.CDLL") def test_GivenWindowsPlatformWhenLoadingLibraryThenLibraryIsLoaded( - self, mock_cdll, mock_exists, mock_print + self, mock_cdll, mock_exists ): # Test Windows library loading path with deterministic mocking mock_exists.return_value = True @@ -214,10 +209,9 @@ def test_GivenWindowsPlatformWhenLoadingLibraryThenLibraryIsLoaded( self.pyzes._LoadZeLibrary() - # Verify Windows-specific print was called - mock_print.assert_any_call("Loading Windows library") # Verify successful library loading mock_cdll.assert_called() + self.assertIsNotNone(self.pyzes.gpuLib) if __name__ == "__main__":