Write your own plugin¶
Minimum example¶
A plugin is a subclass of Plugin
.
Define such a class in a python file located in the right directory.
from evariste import plugins
class Foo(plugins.Plugin):
"""Example plugin"""
keyword = "foo"
The only mandatory attribute or method is the keyword
attribute, which must be unique. It will be used to enable your plugin in the setup file.
That’s it! You can now enable it in the setup file:
[setup]
plugins = foo
You are now a proud owner of a plugin that does… nothing. To interact with Évariste, you can:
implement some hooks;
for some plugin types, implement some methods (see for instance VCS plugins or Action plugins).
Of cours, your plugin can do everything listed above, at once.
Attributes¶
Several useful attributes are defined for every Plugin
instance; they are defined in the class documentation. The most complex one are Plugin.shared
and Plugin.local
.
Plugin.local
¶
Most of the time, your plugin will only access its own section in the setup file, or in the other attributes of the Plugin.shared attribute. To make things easier, the very same data is also available in Plugin.local
. Let’s consider an instance foo
of a plugin foo
foo.local.setup
is a dictionary of the options offoo
in the setup file:foo.local.setup
is a shortcut forfoo.shared.setup["foo"]
.foo.local.plugin
is a shortcut forfoo.shared.plugin["foo"]
(cached data for this plugin).Given a
Tree
objectmytree
, thenfoo.local.tree[mytree]
is a shortcut forfoo.shared.tree[mytree]["foo"]
.
Plugin.default_setup
and Plugin.global_default_setup
¶
For any plugin, attributes Plugin.default_setup
is default setup of the section Plugin.keyword
, while Plugin.global_default_setup
is the whole default setup (for all sections).
When reading the setup file, options that are not set are filled with options of Plugin.default_setup
, and sections that are not set are filled with sections of Plugin.global_default_setup
.
For instance, consider the following plugin:
class Foo(Plugin):
keyword = "foo"
default_setup = {
"foo1": "default1",
"foo2": "default2",
}
global_default_setup = {
"bar": {
"bar1": "global1",
"bar2": "global2",
},
"foo": {
"foo1": "global1",
"foo3": "global3",
},
}
Now, this plugin is loaded with the following setup file:
[setup]
plugins = foo
[foo]
foo2 = setup2
foo4 = setup4
[bar]
bar1 = setup1
bar3 = setup3
Then, once the setup file, and both Plugin.default_setup
and Plugin.global_default_setup
has been taken into account, the resulting setup is equivalent to:
[setup]
plugins = foo
[foo]
foo1 = default1
foo2 = setup2
foo4 = setup4
[bar]
bar1 = setup1
bar2 = global2
bar3 = setup3
Notice that:
whatever have been set in the setup file is kept;
options of
Plugin.default_setup
andPlugin.global_default_setup
may be overwritten by the setup file;whole sections of
Plugin.global_default_setup
may be overwritten by the section ofPlugin.default_setup
.
Current working directory¶
Note that as early as possible, the working directory is changed to the directory of the setup file given in argument to evariste.
Interacting with Évariste¶
Note that it is also possible to write evs plugins.