Code-Society-Lab / Code-Society-Lab/matrixpy
Extension Reload
- Dominant language
- Python
- Stars
- 14
- Forks
- 7
- Avg merge
- 8d 19h
- Merged PRs (30d)
- 5
Description
Once an extension is loaded there is no way to pick up code changes without restarting the entire bot. `load_extension` and `unload_extension` already exist in `bot.py`, but there is no `reload_extension` that does both atomically and re-imports the underlying Python module.
The idea is to add `bot.reload_extension(name)` which unloads the running extension, re-imports its module with `importlib.reload`, re-instantiates the extension, and loads it back in. This makes the development loop significantly tighter without requiring a full bot restart.
**Proposed API**
```python
bot.reload_extension("moderation")
```
```python
# Or trigger it from inside a command
@bot.command()
async def reload(ctx, name: str):
bot.reload_extension(name)
await ctx.reply(f"Reloaded {name}.")
```
The critical detail is that `importlib.reload` only re-executes the module, it does not re-create the extension object, so `reload_extension` must also instantiate a fresh `Extension` from the reloaded module before calling `load_extension`. This means the framework needs a way to locate the extension's module (the mapping from extension name to module path should be stored at load time). State held inside the old extension instance is lost on reload, which is expected behaviour but should be documented clearly.
Contributor guide
Research direction
Start in bot.py by reading the existing load_extension and unload_extension implementations and tracing how extension names map to modules and instances. Confirm the lifecycle needed for bot.reload_extension(name), including re-importing the module and creating a fresh extension instance. Done means the API reloads an extension without restarting the bot and documents that instance state is lost.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100