@@ -723,11 +723,30 @@ def install_step(self):
723723
724724 def _sanity_check_ctypes_ld_library_path_patch (self ):
725725 """Check that the patch for ctypes that should be applied when filtering LD_LIBRARY_PATH works"""
726- cmd = "python -c 'import ctypes; print(ctypes.CDLL(\" libpython3.so\" ))'"
726+ # Try find_library first, since ctypes.CDLL relies on that to work correctly
727+ cmd = "python -c 'from ctypes import util; print(util.find_library(\" libpython3.so\" ))'"
727728 res = run_shell_cmd (cmd )
728729 out = res .output .strip ()
729730 escaped_python_root = re .escape (self .installdir )
730- pattern = rf"^<CDLL '{ escaped_python_root } .*', handle [a-f0-9]+ at 0x[a-f0-9]+>$"
731+ pattern = rf"^{ escaped_python_root } .*libpython3\.so$"
732+ match = re .match (pattern , out )
733+ self .log .debug (f"Matching regular expression pattern { pattern } to string { out } " )
734+ if match :
735+ msg = "Call to ctypes.util.find_library('libpython3.so') succesfully found libpython3.so under the prefix "
736+ msg += "of the current python installation. indicating that the patch that fixes ctypes when EasyBuild is "
737+ msg += "configured to filter LD_LIBRARY_PATH was applied succesfully."
738+ self .log .info (msg )
739+ else :
740+ msg = "Finding the library libpython3.so using ctypes.util.find_library('libpython3.so') failed. "
741+ msg += "Ctypes requires a patch when EasyBuild is configured to filter LD_LIBRARY_PATH. "
742+ msg += "Please check if you specified a patch through patch_ctypes_ld_library_path and check "
743+ msg += "the logs to see if it applied correctly."
744+ raise EasyBuildError (msg )
745+ # Now that we know find_library was patched correctly, check if ctypes.CDLL is also patched correctly
746+ cmd = "python -c 'import ctypes; print(ctypes.CDLL(\" libpython3.so\" ))'"
747+ res = run_shell_cmd (cmd )
748+ out = res .output .strip ()
749+ pattern = rf"^<CDLL '{ escaped_python_root } .*libpython3\.so', handle [a-f0-9]+ at 0x[a-f0-9]+>$"
731750 match = re .match (pattern , out )
732751 self .log .debug (f"Matching regular expression pattern { pattern } to string { out } " )
733752 if match :
0 commit comments