MCPcopy Create free account
hub / github.com/ImageEngine/cortex / loadConfig

Function loadConfig

python/IECore/ConfigLoader.py:48–87  ·  view source on GitHub ↗
( searchPaths, contextDict = {}, raiseExceptions = False, subdirectory = "" )

Source from the content-addressed store, hash-verified

46# to pass objects which the config files will manipulate.
47# \ingroup python
48def loadConfig( searchPaths, contextDict = {}, raiseExceptions = False, subdirectory = "" ) :
49
50 if isinstance( searchPaths, str ) :
51 searchPaths = IECore.SearchPath( os.environ.get( searchPaths, "" ) )
52
53 paths = searchPaths.paths
54 paths.reverse()
55
56 visitedPaths = set()
57 for path in paths :
58
59 if path in visitedPaths :
60 continue
61 else :
62 visitedPaths.add( path )
63
64 pyExtTest = re.compile( r"^[^~].*\.py$" )
65 for dirPath, dirNames, fileNames in os.walk( os.path.join( path, subdirectory ) ) :
66 for fileName in filter( pyExtTest.search, sorted( fileNames ) ) :
67 fullFileName = os.path.abspath( os.path.join( dirPath, fileName ) )
68
69 IECore.msg( IECore.Msg.Level.Debug, "IECore.loadConfig", "Loading file \"%s\"" % fullFileName )
70
71 fileContextDict = contextDict.copy()
72 fileContextDict["__file__"] = fullFileName
73
74 try :
75 with open( fullFileName, encoding = "utf-8" ) as f :
76 exec(
77 compile( f.read(), fullFileName, "exec" ),
78 fileContextDict, fileContextDict
79 )
80 except Exception as m :
81 if raiseExceptions :
82 raise
83 else :
84 stacktrace = traceback.format_exc()
85 IECore.msg( IECore.Msg.Level.Error, "IECore.loadConfig", "Error executing file \"%s\" - \"%s\".\n %s" % ( fullFileName, m, stacktrace ) )
86
87 del fileContextDict["__file__"]
88
89loadConfig( "IECORE_CONFIG_PATHS", { "IECore" : IECore } )

Callers 2

ConfigLoader.pyFile · 0.85
__init__.pyFile · 0.85

Calls 8

SearchPathMethod · 0.80
compileMethod · 0.80
joinMethod · 0.80
msgMethod · 0.80
getMethod · 0.45
addMethod · 0.45
copyMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected