This adds a simple but hopefully very useful plugin system to our main script. It allows adding custom sub-commands to our cli.
In this attempt plugins are python modules with need:
- a module name looking like this
fdroid_makebuildserver.pywould work and the command for calling this would be
fdorid makebuildserver. Alternatively starting out with
fdroid_makebuildserver/__init__.pyshould also work.
- a function called
mainwhich works identical to what we've got in our sub-module scripts. So it's perfectly fine to just use ArgParse in there for example. It's also perfectly fine to support calling this plugin-scripts standalone.
- a variable called
summary. That's what gets displayed in the help listing to describe this plugin (
- to be located in on of the
sys.pathfolders or in the same directory where
Here's a simple example for a plugin:
#!/usr/evn/bin python3 fdroid_summary = "this is a trivial plugin" def main(): print("hello world")
Plugin lookup is using
pkgutil to iterate over all modules in
sys.path and select them by name-matching. This makes it easily possible to get plugins from your distro or pip.
Sadly this opens up quite some attack surface for downloading and executing malicious code. It should work as expected inside virtualenv. For making development/testing of plugins easier I've added I substantially improved this, see comments below.
sys.path. This also makes me unhappy about opening up more potential attack surface, eg. for privilege escalation. So I'd appreciate input on whether this is could be acceptable or how such risks could be minimized.
Overall I think we need a plugin-system to make contributing easier and give us room for experimental projects and projects which are not part of our core functionality.
NOTE: this change is based on !708 (merged)