Want To Contribute - ninadmhatre/pylrn GitHub Wiki
If you want to contribute by adding new implementations of different algorithms or data structures, follow this guide
addonpy comes with "addon_generator.py" which can generate addon schema for you.
$ addon_generator.py -n LinkedListDS --type DATA_STRUCTURE --author <YOUR_NAME> -o <PATH/TO/DIR>"
You can check other options by running it with --h
Above will generate 2 files,
- Addon.py : Source
- Addon.info : Meta
Please edit "Addon.info" as required and make sure help url is actually helpful ;)
Default will look something like below JSON file [(-->) indicates comments]
{
"uuid": "5417b374-8723-4db9-910f-99bac796d649", --> Different for every addon
"name": "<NAME>Addon", --> Name that you give on command line
"type": "DATA_STRUCTURE", --> Type of addon
"description": "<Very Brief Info>",
"execution_seq": ["start", "execute"], --> leave it as is
"stop_seq": ["stop"], --> leave it as is
"version": "0.1", --> Change with every release of addon
"author": "<Please Specify Author>",
"help_url": "http://www.google.com/helppage/QueueDSAddon" --> This is default, open and edit this URL
}
This is how it will look when you create addon
__author__ = '<Please Specify Author>'
from addonpy.IAddonInfo import IAddonInfo
class LinkedListDSAddon(IAddonInfo):
def start(self):
raise NotImplemented
def stop(self):
raise NotImplemented
def execute(self):
raise NotImplemented
@staticmethod
def __addon__():
return 'LinkedListDSAddon'
Change it to,
__author__ = 'Ninad Mhatre'
from addonpy.IAddonInfo import IAddonInfo
from pylrn.Helper import Common
import pylrn.Helper as Helper
class LinkedListDSAddon(IAddonInfo):
def info(self):
raise NotImplemented
def execute(self):
pass
def logic(self):
raise NotImplemented
def info_online(self):
raise NotImplemented
def show_code(self):
raise NotImplemented
@staticmethod
def __addon__():
return 'LinkedListDSAddon'
Now Add actual code,
__author__ = 'Ninad Mhatre'
from addonpy.IAddonInfo import IAddonInfo
from pylrn.Helper import Common
import pylrn.Helper as Helper
class LinkedListDSAddon(IAddonInfo):
def info(self):
print("""
***********************************************************************
<TITLE> (Source <WIKI|GOOGLE>)
***********************************************************************
Add something which will give basic understanding of the algorithm and
make sure you don`t go beyond 72 columns.
""")
@Helper.MeasureTime
def execute(self, data, output=True, reverse=False, very_verbose=False):
# Do Something before
self.logic
# Do Something after
def logic(self, data, output=True, reverse=False, very_verbose=False):
# Keep 'execute' & 'logic' signature same!
one = self._do_one_thing(data)
[print(i) for i in one] # py2 will fail here
# Do something more logical here ...
def _do_one_thing(self, data):
# I am returning input
return data
def info_online(self):
url = self.get_help_url() # This comes from IAddonInfo
print("Opening URL '{0}'".format(url))
Helper.open_url(url)
def show_code(self):
# Default only prints "logic" source but if you are calling some other function
# from "logic" then add it here
self.show_source(['_do_one_thing'])
@staticmethod
def __addon__():
return 'LinkedListDSAddon'
from pylrn.pylrn import AlgorithmsDemo
import pylrn.Helpers
demo = AlgorithmsDemo()
demo.add_search_dirs([r'<PATH/TO/DIR/WHERE/NEW/ADDON/EXIST>'])
demo.load(verbose_flag=True) # Make sure your addon is not exception list
demo.list_all_algorithms() # Is your addon listed?
ur_addon = demo.get_instance('YourTest')
ur_addon.print_addon_info() # Print information from .info file.
ur_addon.execute(data) # Other options if you want to use!
# verify if above is doing what its suppose to do!