diff --git a/binarycpython/utils/custom_logging_functions.py b/binarycpython/utils/custom_logging_functions.py index 73136f00c80e55b5d7aced5204984e3589af085d..94a5b669169ad72a4c47433793660d364b4dee06 100644 --- a/binarycpython/utils/custom_logging_functions.py +++ b/binarycpython/utils/custom_logging_functions.py @@ -7,6 +7,7 @@ import os import uuid import ctypes import socket +import platform import textwrap import subprocess @@ -14,6 +15,28 @@ from typing import Tuple, Optional from binarycpython.utils.functions import temp_dir, remove_file, verbose_print +def get_dynamic_library_file_extension(): + """ + Function to find the correct file extension + + It will return .so except for exceptions based on platform.platform() + """ + + current_platform = platform.platform() + + # Set up exception list + exception_dict = { + 'macOS-12.4': 'dylib' + } + + # Check in the exception dict, to see if the current platform starts with any of the keys in there. + for exception_platform_key in exception_dict.keys(): + if current_platform.startswith(exception_platform_key): + return exception_dict[exception_platform_key] + + # Otherwise return .so + return 'so' + def autogen_C_logging_code(logging_dict: dict, verbosity: int = 0) -> Optional[str]: """ @@ -410,9 +433,12 @@ def create_and_load_logging_function( # Create the sub dir for the custom_logging code os.makedirs(custom_logging_dir, exist_ok=True) + # Get the correct filename extension (can depend per system) + extension = get_dynamic_library_file_extension() + # library_name = os.path.join( - custom_logging_dir, "libcustom_logging_{}.so".format(uuid.uuid4().hex) + custom_logging_dir, "libcustom_logging_{}.{}".format(uuid.uuid4().hex, extension) ) compile_shared_lib( @@ -429,9 +455,9 @@ def create_and_load_logging_function( ) # Loading library - _ = ctypes.CDLL("libgslcblas.so", mode=ctypes.RTLD_GLOBAL) - _ = ctypes.CDLL("libgsl.so", mode=ctypes.RTLD_GLOBAL) - _ = ctypes.CDLL("libbinary_c.so", mode=ctypes.RTLD_GLOBAL) + _ = ctypes.CDLL("libgslcblas.{}".format(extension), mode=ctypes.RTLD_GLOBAL) + _ = ctypes.CDLL("libgsl.{}".format(extension), mode=ctypes.RTLD_GLOBAL) + _ = ctypes.CDLL("libbinary_c.{}".format(extension), mode=ctypes.RTLD_GLOBAL) libcustom_logging = ctypes.CDLL( library_name,