Skip to content

Commit ea2f4f4

Browse files
authored
fix: remove logging to std out during import (#450)
Related-To: NEO-18404 --------- Signed-off-by: shubham kumar <shubham.kumar@intel.com>
1 parent 4cbc765 commit ea2f4f4

2 files changed

Lines changed: 25 additions & 48 deletions

File tree

bindings/sysman/python/source/pyzes.py

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,9 @@ def _LoadZeLibrary():
6767
# load the library
6868
libName = "ze_loader"
6969
if sys.platform.startswith("linux"):
70-
print("Loading Linux library")
7170
libName = "/usr/lib/x86_64-linux-gnu/lib" + libName + ".so.1"
7271
else:
73-
print("Loading Windows library")
7472
# Try multiple common locations for Windows Intel GPU drivers
75-
import os
76-
7773
possible_paths = [
7874
# Try system PATH first
7975
libName + "64.dll",
@@ -86,42 +82,29 @@ def _LoadZeLibrary():
8682

8783
library_loaded = False
8884
for path in possible_paths:
89-
try:
90-
if "*" in path:
91-
# Handle wildcard paths for driver store
92-
import glob
93-
94-
matching_paths = glob.glob(path)
95-
for match_path in matching_paths:
96-
try:
97-
print(f"Trying: {match_path}")
98-
gpuLib = CDLL(match_path)
99-
library_loaded = True
100-
print(f"Successfully loaded: {match_path}")
101-
break
102-
except Exception as e:
103-
print(f"Failed to load {match_path}: {e}")
104-
continue
105-
else:
106-
if os.path.exists(path):
107-
print(f"Trying: {path}")
108-
gpuLib = CDLL(path)
109-
library_loaded = True
110-
print(f"Successfully loaded: {path}")
111-
break
112-
else:
113-
print(f"Trying: {path}")
114-
gpuLib = CDLL(path)
115-
library_loaded = True
116-
print(f"Successfully loaded: {path}")
117-
break
118-
except Exception as e:
119-
print(f"Failed to load {path}: {e}")
120-
continue
121-
12285
if library_loaded:
12386
break
12487

88+
if "*" in path:
89+
# Handle wildcard paths for driver store
90+
import glob
91+
92+
matching_paths = glob.glob(path)
93+
for match_path in matching_paths:
94+
try:
95+
gpuLib = CDLL(match_path)
96+
library_loaded = True
97+
break
98+
except OSError:
99+
pass # Try next path
100+
else:
101+
# Try loading the library directly
102+
try:
103+
gpuLib = CDLL(path)
104+
library_loaded = True
105+
except OSError:
106+
pass # Try next path
107+
125108
if not library_loaded:
126109
raise Exception(
127110
f"Failed to load Intel GPU library. Tried paths: {possible_paths}"

bindings/sysman/python/test/unit_tests/test_init.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,9 @@ def test_GivenLibraryAlreadyLoadedWhenCallingLoadZeLibraryThenReturnsEarly(self)
118118

119119
try:
120120
# This should return early without any library loading
121-
with patch("builtins.print") as mock_print:
122-
self.pyzes._LoadZeLibrary()
123-
# Should not print "Loading Linux library" because it returns early
124-
print_calls = [
125-
call.args[0] for call in mock_print.call_args_list if call.args
126-
]
127-
self.assertNotIn("Loading Linux library", print_calls)
121+
self.pyzes._LoadZeLibrary()
122+
# Verify gpuLib remains unchanged (early return)
123+
self.assertEqual(self.pyzes.gpuLib, mock_lib)
128124
finally:
129125
# Restore original state
130126
self.pyzes.gpuLib = original_gpuLib
@@ -201,11 +197,10 @@ def test_GivenValidLibraryWhenGettingNewFunctionPointerThenCachesAndReturnsFunct
201197

202198
@patch("sys.platform", "win32")
203199
@patch("pyzes.gpuLib", None)
204-
@patch("builtins.print")
205200
@patch("os.path.exists")
206201
@patch("pyzes.CDLL")
207202
def test_GivenWindowsPlatformWhenLoadingLibraryThenLibraryIsLoaded(
208-
self, mock_cdll, mock_exists, mock_print
203+
self, mock_cdll, mock_exists
209204
):
210205
# Test Windows library loading path with deterministic mocking
211206
mock_exists.return_value = True
@@ -214,10 +209,9 @@ def test_GivenWindowsPlatformWhenLoadingLibraryThenLibraryIsLoaded(
214209

215210
self.pyzes._LoadZeLibrary()
216211

217-
# Verify Windows-specific print was called
218-
mock_print.assert_any_call("Loading Windows library")
219212
# Verify successful library loading
220213
mock_cdll.assert_called()
214+
self.assertIsNotNone(self.pyzes.gpuLib)
221215

222216

223217
if __name__ == "__main__":

0 commit comments

Comments
 (0)