(plugin_base_class, plugin_abs_file_path)
| 164 | |
| 165 | |
| 166 | def 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 | |
| 199 | def load_meta_file(file_path): |
nothing calls this directly
no test coverage detected