brainstorm3
brainstorm3 copied to clipboard
[Plugin] Move plugin definition to external Json file
Hello,
Recently, I was thinking about the possibility for the users to have additional plugin that are not officially integrated to brainstorm (typically code that are in .brainstorm/process). For example, I have a lot of code related to nirs project that I sometime needs to share with colleague and currently it makes it hard to track version of the scripts. With a plugin system, I could make sure all the script are always up-to-date between me and my colleagues and between my different computers :)
For the main plugin, this would allow some user to change the version of the external-software they want to use more easily.
To do that I was thinking to move the definition of the plugin to two files: but_plugin.json in the main brainstorm folder. and allows users to create a user_plugin.json in .brainstorm folder to specify user-specific
https://github.com/brainstorm-tools/brainstorm3/blob/master/toolbox/core/bst_plugin.m#L128-L599 would then be only reading of the json files.
Here is a proof of concept of how the file would looks like
PlugDesc = struct();
PlugDesc.Name = 'bci2000';
PlugDesc.Version = 'latest';
PlugDesc.Category = 'I/O';
PlugDesc.URLzip = 'https://bci2000.org/downloads/mex.zip';
PlugDesc.URLinfo = 'https://www.bci2000.org/mediawiki/index.php/User_Reference:Matlab_MEX_Files';
PlugDesc.TestFile = 'load_bcidat.m';
PlugDesc.CompiledStatus = 0;
txt = jsonencode(PlugDesc,PrettyPrint=true)
value = jsondecode(txt);
PlugDescDecode = struct_copy_fields(bst_plugin('GetStruct','bci2000'), value, 1); % same as existing struct
Let me know if you think that is a good idea. I can start working on a PR then.
Edouard
Yes, this sounds like a very interesting idea! You can go ahead with your experiments, I'll help you wrap them up :)
ok. I will work on it this weekend :)
I'm looking a bit deeper into this idea and I'm not sure that the basic Brainstorm plugins currently defined in bst_plugins.m
should be moved to a json file:
- Some of the elements in the structure depend on the OS, therefore it can't be one single .json file
- It's going to slow down a bit the startup
- It has no benefit for flexibility, as users would not modify it.
=> I don't think the
bst_plugin.json
is a good idea.
For user plugins, it makes much more sense. And it could even be more modular than a single user_plugin.json file. One json file = one plugin would be more modular.
I was thinking about maybe parsing all the .json files in the .brainstorm/plugin folder, for user plugins definition. Or maybe there is no need to actually parse the .json files there, and you could add a menu "Import plugin" in the plugin menu. This would ask for loading a .json file from the hard drive or from a URL, and then install it. Once installed, it can be updated without the json I guess?
I realize what I wrote is a bit messy, I haven't thought much about it, but wanted to share quickly these ideas before you spend too much time with the implementation.
Few months ago, we revamped the bst-users repo, it may be helpful for these user plugins.
- The user plugins and their definition (json or plugin struct) can be added there as submodules.
- Then, the user can install them through the GUI
Does it make some sense?
Few months ago, we revamped the bst-users repo, it may be helpful for these user plugins.
@Edouard2laire Maybe you could push there one of your (future) user plugins, as an example?