-
Notifications
You must be signed in to change notification settings - Fork 0
Python guidelines
Alright, here we are :) If you are reading these lines that means you choose to develop your plugin for AVA in Python
...
Great choice!
You'll see there are only 4 rules to create your plugin... "What only 4? this guy has to be kidding me"
- Python version:
We are using Python3
, only!
- Plugin conception:
You plugin must be conceived as a Python
class and named in the same way as the plugin as well as the folder in which it's located!
This class must have as attribute a dictionnary binding the commands to catch and the methods of your class to execute, and the get_commands
method which returns this dictionnary.
- The dictionnary
Ok take again our git
plugin as example:
import subprocess
class git(object):
"""Git plugin"""
def __init__(self):
self.commands = {
'log': self.log,
'version': self.version,
}
def log(self):
subprocess.call(["git", "log"])
def version(self):
subprocess.call(["git", "version"])
As you can see, in the __init__
method, I am binding the commands that I am expecting, to the methods of my class to execute.
self.commands #is my dicitonnary
- The get_commands method:
Ok, one last thing, implement the get_commands
method to return our dictionnary. let's complete our example to see how it works!
import subprocess
class git(object):
"""Git plugin"""
def __init__(self):
self.commands = {
'log': self.log,
'version': self.version,
}
def log(self):
subprocess.call(["git", "log"])
def version(self):
subprocess.call(["git", "version"])
def get_commands(self):
return self.commands
That's all! You are completely ready to write your own plugin :)
Don't forget to checkout our website if you want to share/discover some awesome plugins!