MCPcopy
hub / github.com/nonebot/nonebot2 / exec_module

Method exec_module

nonebot/plugin/manager.py:244–268  ·  view source on GitHub ↗
(self, module: ModuleType)

Source from the content-addressed store, hash-verified

242 return super().create_module(spec)
243
244 def exec_module(self, module: ModuleType) -> None:
245 if self.loaded:
246 return
247
248 # create plugin before executing
249 plugin = _new_plugin(self.name, module, self.manager)
250 setattr(module, "__plugin__", plugin)
251
252 # enter plugin context
253 _plugin_token = _current_plugin.set(plugin)
254
255 try:
256 super().exec_module(module)
257 except Exception:
258 _revert_plugin(plugin)
259 raise
260 finally:
261 # leave plugin context
262 _current_plugin.reset(_plugin_token)
263
264 # get plugin metadata
265 metadata: PluginMetadata | None = getattr(module, "__plugin_meta__", None)
266 plugin.metadata = metadata
267
268 return
269
270
271sys.meta_path.insert(0, PluginFinder())

Callers

nothing calls this directly

Calls 3

_new_pluginFunction · 0.85
_revert_pluginFunction · 0.85
setMethod · 0.80

Tested by

no test coverage detected