Skip to content

Plugin architecture #376

Open
Open

Description

@NSPC911

This was something I was thinking of during the hiatus

Store plugins in a folder, maybe ~/AppData/Roaming/rovr/plugins; likewise, versions for other platforms

Then, in this folder, you can install a plugin, so like

~/AppData/Roaming/rovr/plugins
|-> everything/
| |-> .git/
| |-> README.md
| |-> main.py       # contains main widget
| \-> other stuff/  # yes
|
|-> plocate/
| |-> .git/
| |-> README.md
| |-> main.py       # contains main widget

main.py contains source code; the main widget must be a button that can be placed in the menu area, along with copy, cut, paste, rename, delete, etc

An example file would be

from textual.widgets import Button

class EverythingSearchButton(Button):
    def on_mount(self) -> None:
        self.app.action_open_everything = self.action_open_everything
        self.display = False

    async def action_open_everything(self) -> None:
        ...

__widget__ = EverythingSearchButton

Then rovr will check each folder for __widget__, check mro for Button and if so, mounts it to #menu, boom plugin system
This also means people can monkeypatch, but just mark that as a feature, I guess, pros and cons of using Python

Then we could add onto rovr, like I guess rovr --plug clone <link to git repo> and rovr will clone with shallow, check contents, ast.parse check for __widget__, if not list and is class, import it, check issubclass, if it is, then allow plugin to exist

Also consider a --ignore-plugins to run without plugins in the case that anything fails.


For enabling and disabling, we could just extend the [plugins] table, kind of like

[plugins.bat]
...
[plugins.everything]
enabled = true
executable = "es.exe"

If the plugin's enabled is not there, assume it is disabled


Loading a plugin into a namespace is also the best idea to support child imports, so

import importlib.util, sys, types
from pathlib import Path

def load_plugin(folder: Path) -> types.ModuleType:
    # Assume folder.name is a validated, unique Python identifier.
    name = f"_rovr_plugin_{folder.name}"
    spec = importlib.util.spec_from_file_location(
        name,
        folder / "main.py",
        submodule_search_locations=[str(folder)],
    )
    if spec is None or spec.loader is None:
        raise ImportError(f"Cannot load plugin: {folder.name}")
    module = importlib.util.module_from_spec(spec)
    sys.modules[name] = module
    try:
        spec.loader.exec_module(module)
    except BaseException:
        for key in tuple(sys.modules):
            if key == name or key.startswith(name + "."):
                del sys.modules[key]
        raise
    return module

so that such loaded modules are now under

_rovr_plugin_everything
_rovr_plugin_everything.search_screen

and importing becomes

from .search_screen import EverythingSearchScreen

Preferably don't add hot reloading; it becomes an absolute mess.


Also, since rovr is importing the plugin into its own venv (or is using the compiled executable), importing external modules is probably not possible unless the modules do some fancy importing with importlib (actually, I think that seems quite reasonable; I could see people doing that tbh).

However, need to consider certain widgets not being compiled because Nuitka is actually considering the lazy importing of textual.widgets, which means certain widgets like DataTable, MarkdownViewer, Tree may not be available (didn't check though; should check)

Activity

  1. added
    backlogplanned to add/fix, but a definite deadline is not set _yet_
    enhancementenhanced something by removing or adding something
    difficulty: extreme demonit is as hard as beating an extreme demon in geometry dash (which means it is insanely difficult)
    on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backlogplanned to add/fix, but a definite deadline is not set _yet_difficulty: extreme demonit is as hard as beating an extreme demon in geometry dash (which means it is insanely difficult)enhancementenhanced something by removing or adding somethingfeature-requestnew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions