I'm working on my first plugin and I still have a ...
# nextflow-plugins
m
I'm working on my first plugin and I still have a couple of doubts that I hope you could help me clear up. I'm still uncertain regarding the whole plugin initialization process. Looking at the nf-hello plugin, for example: 1. I guess that the HelloPlugin constructor is required but does it serve any purpose to me as a plugin developer? 2. The HelloExtension has an init method with access to the session instance that is called by nextflow. So far so clear. The HelloFactory instead has a create method which should initialize observers. I would like to grant my observer access to the configuration. Could I do so from the
HelloFactory
passing a config object to my observer's constructor? Or should I avoid adding a constructor to my observer entirely and instead rely on access to the session instance in the onFlowCreate method as done here for the nf-quilt plugin? Having no clue about gradle, I'm also wondering how I can include and refer to non-Groovy assets. I would like to distribute a JSON file with my plugin that I will need to use in my plugin code. Could you give me some pointers on how to do that, please? Thank you very much in advance.
a
Not a Groovy expert either, but if youโ€™re simply looking to bundle assets then the
nf-azure
plugin can offer some guidance https://github.com/nextflow-io/nextflow/tree/master/plugins/nf-azure/src/resources/nextflow/cloud/azure It bundles JSON files which enumerate the available VMs per region
๐Ÿ‘ 1
m
Cool, thank you for the hint. That's encouraging. I didn't clearly see yet where/how the files get loaded into Groovy, though. ๐Ÿค”
j
about 1, it depends of your plugin. If you need to initialize resources or check environment the constructor can be a good point to do it. HelloPlugin it's the "starting" point used for the subsystem to load and initialize the plugin (nextflow uses pf4j library for it) but from a nextflow developer point of view it's more interesting the ExtensionPoint.
The ExtesionPoint is initialized at runtime if the dsl contains the include clause. NF provides to the extension the Session to allow them access to the config (for example)
The aim of the extension point is to provide to the dsl new "features" as operators or functions. So here is where you declare them using then annotations Factory, Operator and Function
About HelloFactory I think the name is not very descriptive because it's an example of how extend Observality , so mabye HelloTraceFactory is better
HelloFactory (or HelloTraceFactory) receive the session and from it you can access to the configuration for example: with a nextflow.config
Copy code
docker{
....
}
myplugin{
   instances = 3
}
session.config.navigate('myplugin') as Map
will returns a Map as [ instances: 3 ]
about resources, all files under
resources
folder are included in the jar and can be accesibles using standard java functions as ClassLoader.getResource("/myfile.json")
m
Super helpful, thank you Jorge. I hope to have a working Slack plugin tomorrow then ๐Ÿ™‚
๐Ÿ™Œ 1
a
Thanks Jorge - this is ๐Ÿฅ‡ !