MCPcopy Create free account
hub / github.com/StackStorm/st2 / register_plugin

Function register_plugin

st2common/st2common/util/loader.py:166–196  ·  view source on GitHub ↗
(plugin_base_class, plugin_abs_file_path)

Source from the content-addressed store, hash-verified

164
165
166def register_plugin(plugin_base_class, plugin_abs_file_path):
167 registered_plugins = []
168 plugin_dir = os.path.dirname(os.path.realpath(plugin_abs_file_path))
169 _register_plugin_path(plugin_dir)
170
171 module_name = _get_plugin_module(plugin_abs_file_path)
172 if module_name is None:
173 return None
174
175 spec = importlib.util.spec_from_file_location(module_name, plugin_abs_file_path)
176 module = importlib.util.module_from_spec(spec)
177 spec.loader.exec_module(module)
178 klasses = _get_plugin_classes(module)
179
180 # Try registering classes in plugin file. Some may fail.
181 for klass in klasses:
182 try:
183 _register_plugin(plugin_base_class, klass)
184 registered_plugins.append(klass)
185 except Exception as e:
186 LOG.exception(e)
187 LOG.debug("Skipping class %s as it doesn't match specs.", klass)
188 continue
189
190 if len(registered_plugins) == 0:
191 raise Exception(
192 'Found no classes in plugin file "%s" matching requirements.'
193 % (plugin_abs_file_path)
194 )
195
196 return registered_plugins
197
198
199def load_meta_file(file_path):

Callers

nothing calls this directly

Calls 4

_register_plugin_pathFunction · 0.85
_get_plugin_moduleFunction · 0.85
_get_plugin_classesFunction · 0.85
_register_pluginFunction · 0.85

Tested by

no test coverage detected