声明依赖插件。 参数: name: 插件模块名或插件标识符,仅在已声明插件的情况下可使用标识符。 异常: RuntimeError: 插件无法加载
(name: str)
| 186 | |
| 187 | |
| 188 | def require(name: str) -> ModuleType: |
| 189 | """声明依赖插件。 |
| 190 | |
| 191 | 参数: |
| 192 | name: 插件模块名或插件标识符,仅在已声明插件的情况下可使用标识符。 |
| 193 | |
| 194 | 异常: |
| 195 | RuntimeError: 插件无法加载 |
| 196 | """ |
| 197 | if "." in name: |
| 198 | # name is a module name |
| 199 | plugin = get_plugin(_module_name_to_plugin_id(name)) |
| 200 | else: |
| 201 | # name is a plugin id or simple module name (equals to plugin id) |
| 202 | plugin = get_plugin(name) |
| 203 | |
| 204 | # if plugin not loaded |
| 205 | if plugin is None: |
| 206 | # plugin already declared, module name / plugin id |
| 207 | if manager := _find_manager_by_name(name): |
| 208 | plugin = manager.load_plugin(name) |
| 209 | |
| 210 | # plugin not declared, try to declare and load it |
| 211 | else: |
| 212 | plugin = load_plugin(name) |
| 213 | |
| 214 | if plugin is None: |
| 215 | raise RuntimeError(f'Cannot load plugin "{name}"!') |
| 216 | return plugin.module |
| 217 | |
| 218 | |
| 219 | def inherit_supported_adapters(*names: str) -> set[str] | None: |
no test coverage detected