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

Method load

python/IECore/ClassLoader.py:138–178  ·  view source on GitHub ↗
( self, name, version = None )

Source from the content-addressed store, hash-verified

136 # It also adds two class attributes named "path" and "version"
137 # with the info necessary to reload the Op from ClassLoader.
138 def load( self, name, version = None ) :
139
140 with self.__loadMutex:
141
142 c = self.__findClass( name )
143
144 if not version :
145 version = self.getDefaultVersion( name )
146
147 if not version in self.versions( name ) :
148 raise RuntimeError( "Class \"%s\" has no version %d." % (name, version) )
149
150 if version in c["imports"] :
151 return c["imports"][version]
152
153 nameTail = os.path.basename( name )
154 fileName = os.path.join( name, nameTail + "-" + str(version) + ".py" )
155 fileName = self.__searchPaths.find( fileName )
156 if fileName=="" :
157 raise IOError( "Unable to find implementation file for class \"%s\" version %d." % (name, version) )
158
159 moduleName = "IECoreClassLoader" + name.replace( ".", "_" ) + str( version )
160
161 spec = importlib.util.spec_from_file_location( moduleName, fileName )
162 module = importlib.util.module_from_spec( spec )
163 spec.loader.exec_module( module )
164
165 if not getattr( module, nameTail, None ) :
166 raise IOError( "File \"%s\" does not define a class named \"%s\"." % ( fileName, nameTail ) )
167
168 result = getattr( module, nameTail )
169
170 if getattr( result, 'staticTypeName', None ) == getattr( result.__bases__[0], 'staticTypeName', None ) :
171 warning( "Class \"%s\" has the same staticTypeName as its Base Class. Perhaps you should call registerRunTimeTyped." % name )
172
173 result.path = name
174 result.version = version
175
176 c["imports"][version] = result
177
178 return result
179
180 ## The ClassLoader uses a caching mechanism to speed
181 # up frequent reloads of the same class. This method

Callers 9

testMethod · 0.95
testDotsInPathMethod · 0.95
testClassLoaderMethod · 0.95
testMultiplyMethod · 0.95
testReadParsingMethod · 0.95
testEvalParsingMethod · 0.95
setClassMethod · 0.45
__parseObjectFunction · 0.45
setClassMethod · 0.45

Calls 7

__findClassMethod · 0.95
getDefaultVersionMethod · 0.95
versionsMethod · 0.95
warningFunction · 0.90
joinMethod · 0.80
strFunction · 0.50
findMethod · 0.45

Tested by

no test coverage detected