Get the bundle handler for the given bundle id and plugin id. :param bundle_id: bundle id. :return: the plugin.
(bundle_id: str)
| 22 | |
| 23 | |
| 24 | def get_bundle_handler(bundle_id: str): |
| 25 | |
| 26 | """ |
| 27 | Get the bundle handler for the given bundle id and plugin id. |
| 28 | :param bundle_id: bundle id. |
| 29 | :return: the plugin. |
| 30 | """ |
| 31 | if __bundle_handlers.get(bundle_id): |
| 32 | return __bundle_handlers[bundle_id] |
| 33 | |
| 34 | if bundle_id not in __bundle_handlers: |
| 35 | __bundle_handlers[bundle_id] = {} |
| 36 | |
| 37 | try: |
| 38 | # Get the corresponding plugin class |
| 39 | model_class = __load_bundle_handler_class(bundle_id) |
| 40 | # Instantiate the model class |
| 41 | __bundle_handlers[bundle_id] = model_class() |
| 42 | except (ImportError, AttributeError): |
| 43 | raise Exception(f"get_bundle_handler: error loading bundle_handler of {bundle_id}") |
| 44 | |
| 45 | return __bundle_handlers[bundle_id] |
| 46 | |
| 47 | |
| 48 | # Automatically search and import all providers |
no test coverage detected