Skip to content

Commit 224df0c

Browse files
committed
IECore module : Add DLL directory for DLL dependencies
This fixes `scons testCorePython` and provides a mechanism for folks to fix imports in their own environments. At first I tried to just hardcode the directory to match the directory layout used by Gaffer, using a path relative to `__file__`. But that didn't work, because when we run `scons testCorePython`, we haven't installed the IECore module yet (we test it in place in the local dir). The `IECORE_DLL_DIRECTORIES` environment variable was the only other option I could see, and I suppose it at least gives folks a hand if they have their own installation layouts.
1 parent 045266c commit 224df0c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

SConstruct

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,7 @@ if testEnv["PLATFORM"] == "darwin" :
14961496
testEnv["ENV"][testEnv["TEST_LIBRARY_PATH_ENV_VAR"]] = os.pathsep.join( [ testEnv["ENV"].get(testEnv["TEST_LIBRARY_PATH_ENV_VAR"], ""), testEnvLibPath ] )
14971497
if testEnv["TEST_LIBRARY_PATH_ENV_VAR"] != libraryPathEnvVar :
14981498
testEnv["ENV"][libraryPathEnvVar] = os.pathsep.join( [ testEnv["ENV"].get(libraryPathEnvVar, ""), testEnvLibPath ] )
1499+
testEnv["ENV"]["IECORE_DLL_DIRECTORIES"] = testEnv["ENV"][libraryPathEnvVar]
14991500
testEnv["ENV"]["IECORE_OP_PATHS"] = os.path.join( "test", "IECore", "ops" )
15001501

15011502
c = configureSharedLibrary( testEnv )

python/IECore/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#
3939
# Some parts of the IECore library are defined purely in Python. These are shown below.
4040

41-
import os, sys, ctypes
41+
import os, sys, ctypes, pathlib
4242
if os.name == "posix" and os.environ.get( "IECORE_RTLD_GLOBAL", "1" ) == "1" :
4343
# Historically, we had problems with cross-module RTTI on Linux, whereby
4444
# different Python modules and/or libraries could end up with their own
@@ -56,8 +56,15 @@
5656
sys.getdlopenflags() | ctypes.RTLD_GLOBAL
5757
)
5858

59+
if hasattr( os, "add_dll_directory" ) and "IECORE_DLL_DIRECTORIES" in os.environ :
60+
for directory in os.environ.get( "IECORE_DLL_DIRECTORIES" ).split( os.pathsep ) :
61+
directory = pathlib.Path( directory ).resolve()
62+
if directory.is_dir() :
63+
os.add_dll_directory( directory )
64+
del directory
65+
5966
# Remove pollution of IECore namespace
60-
del os, sys, ctypes
67+
del os, sys, ctypes, pathlib
6168

6269
__import__( "imath" )
6370

0 commit comments

Comments
 (0)