1616# Debug flag for library loading
1717DEBUG_LIBRARY_LOADING = False
1818
19- # Create a module-specific logger with NullHandler to avoid interfering with global configuration
20- logger = logging .getLogger ("c2pa" )
19+ # Create a module-specific logger with NullHandler
20+ # to avoid interfering with global configuration
21+ logger = logging .getLogger ("c2pa.loader" )
2122logger .addHandler (logging .NullHandler ())
2223
2324
@@ -107,8 +108,7 @@ def _load_single_library(lib_name: str,
107108 The loaded library or None if loading failed
108109 """
109110 if DEBUG_LIBRARY_LOADING : # pragma: no cover
110- logger .info (
111- f"Searching for library '{ lib_name } ' in paths: { [str (p ) for p in search_paths ]} " )
111+ logger .info (f"Searching for library '{ lib_name } ' in paths: { [str (p ) for p in search_paths ]} " )
112112 current_arch = _get_architecture ()
113113 if DEBUG_LIBRARY_LOADING : # pragma: no cover
114114 logger .info (f"Current architecture: { current_arch } " )
@@ -125,12 +125,10 @@ def _load_single_library(lib_name: str,
125125 except Exception as e :
126126 error_msg = str (e )
127127 if "incompatible architecture" in error_msg :
128- logger .error (
129- f"Architecture mismatch: Library at { lib_path } is not compatible with current architecture { current_arch } " )
128+ logger .error (f"Architecture mismatch: Library at { lib_path } is not compatible with current architecture { current_arch } " )
130129 logger .error (f"Error details: { error_msg } " )
131130 else :
132- logger .error (
133- f"Failed to load library from { lib_path } : { e } " )
131+ logger .error (f"Failed to load library from { lib_path } : { e } " )
134132 else :
135133 logger .debug (f"Library not found at: { lib_path } " )
136134 return None
@@ -216,16 +214,14 @@ def dynamically_load_library(
216214 env_lib_name = os .environ .get ("C2PA_LIBRARY_NAME" )
217215 if env_lib_name :
218216 if DEBUG_LIBRARY_LOADING : # pragma: no cover
219- logger .info (
220- f"Using library name from env var C2PA_LIBRARY_NAME: { env_lib_name } " )
217+ logger .info (f"Using library name from env var C2PA_LIBRARY_NAME: { env_lib_name } " )
221218 try :
222219 possible_paths = _get_possible_search_paths ()
223220 lib = _load_single_library (env_lib_name , possible_paths )
224221 if lib :
225222 return lib
226223 else :
227- logger .error (
228- f"Could not find library { env_lib_name } in any of the search paths" )
224+ logger .error (f"Could not find library { env_lib_name } in any of the search paths" )
229225 # Continue with normal loading if environment variable library
230226 # name fails
231227 except Exception as e :
@@ -241,12 +237,9 @@ def dynamically_load_library(
241237 if not lib :
242238 platform_id = get_platform_identifier ()
243239 current_arch = _get_architecture ()
244- logger .error (
245- f"Could not find { lib_name } in any of the search paths: { [str (p ) for p in possible_paths ]} " )
246- logger .error (
247- f"Platform: { platform_id } , Architecture: { current_arch } " )
248- raise RuntimeError (
249- f"Could not find { lib_name } in any of the search paths (Platform: { platform_id } , Architecture: { current_arch } )" )
240+ logger .error (f"Could not find { lib_name } in any of the search paths: { [str (p ) for p in possible_paths ]} " )
241+ logger .error (f"Platform: { platform_id } , Architecture: { current_arch } " )
242+ raise RuntimeError (f"Could not find { lib_name } in any of the search paths (Platform: { platform_id } , Architecture: { current_arch } )" )
250243 return lib
251244
252245 # Default path (no library name provided in the environment)
0 commit comments