Retrieve a register plugin class from the provided file. This method also validates that the class implements all the abstract methods from the base plugin class. :param base_class: Base plugin class. :param base_class: ``class`` :param file_path: File absolute path to th
(base_class, file_path, class_name)
| 126 | |
| 127 | |
| 128 | def register_plugin_class(base_class, file_path, class_name): |
| 129 | """ |
| 130 | Retrieve a register plugin class from the provided file. |
| 131 | |
| 132 | This method also validates that the class implements all the abstract methods |
| 133 | from the base plugin class. |
| 134 | |
| 135 | :param base_class: Base plugin class. |
| 136 | :param base_class: ``class`` |
| 137 | |
| 138 | :param file_path: File absolute path to the plugin module file. |
| 139 | :type file_path: ``str`` |
| 140 | |
| 141 | :param class_name: Class name of a plugin. |
| 142 | :type class_name: ``str`` |
| 143 | """ |
| 144 | plugin_dir = os.path.dirname(os.path.realpath(file_path)) |
| 145 | _register_plugin_path(plugin_dir) |
| 146 | module_name = _get_plugin_module(file_path) |
| 147 | |
| 148 | if module_name is None: |
| 149 | return None |
| 150 | |
| 151 | spec = importlib.util.spec_from_file_location(module_name, file_path) |
| 152 | module = importlib.util.module_from_spec(spec) |
| 153 | spec.loader.exec_module(module) |
| 154 | klass = getattr(module, class_name, None) |
| 155 | |
| 156 | if not klass: |
| 157 | raise Exception( |
| 158 | 'Plugin file "%s" doesn\'t expose class named "%s"' |
| 159 | % (file_path, class_name) |
| 160 | ) |
| 161 | |
| 162 | _register_plugin(base_class, klass) |
| 163 | return klass |
| 164 | |
| 165 | |
| 166 | def register_plugin(plugin_base_class, plugin_abs_file_path): |
nothing calls this directly
no test coverage detected