-
Notifications
You must be signed in to change notification settings - Fork 4
Development Guide
As we mentioned, FAVITES was designed to be modular such that future development of module implementations would be simple and clean for developers.
Each module is defined by an abstract class located inside the modules folder following the naming convention MODULENAME.py
, which contains a class MODULENAME
that defines the functions that must be implemented. For example, the EndCriteria module is defined by the EndCriteria
class in the EndCriteria.py file. Do not modify these abstract classes! Simply use them to guide you in your implementation.
To actually implement a given module, you will create a new Python 3 script in the modules folder. Let's say we wish to implement a module named MODULENAME
, and our implementation's name is called IMPLEMENTATIONNAME
. To follow the naming convention FAVITES uses, we would create a new file called MODULENAME_IMPLEMENTATIONNAME.py
. For example, one of the implementations of the EndCriteria module is called Time
, so the Python 3 script we created to implement the module is EndCriteria_Time.py.
When you create your new MODULENAME_IMPLEMENTATIONNAME.py
file, it should contain a class called MODULENAME_IMPLEMENTATIONNAME
, and this class must be derived from the MODULENAME
class. The syntax to do so is the following:
from MODULENAME import MODULENAME
class MODULENAME_IMPLEMENTATIONNAME(MODULENAME):
# fill in the class
For example, below is how the EndCriteria_Time implementation of the EndCriteria module would look:
from EndCriteria import EndCriteria
class EndCriteria_Time(EndCriteria):
# fill in the class
To simplify the process of loading the available module implementations, we have created a JSON database, FAVITES_ModuleList.json, which contains the usage information for each module implementation. Specifically, for each module, it contains all implementations, and for each implementation, it contains a list of required user arguments to be contained in the user's configuration file. Below is the general structure of the database:
{
"MODULE1": {
"IMPLEMENTATION1": {
"req": ["req1", "req2", ...]
},
"IMPLEMENTATION2": {
...
},
...
},
"MODULE2": {
...
},
...
}
If you look through the existing implementations of FAVITES modules, you will notice that many include the following import:
import FAVITES_GlobalContext as GC
Basically, instead of having variables be passed around as function arguments, we created this "Global Context" that is accessible by all module implementations. If your module implementation requires global variables, we recommend storing them here instead of as static variables of the class.
Niema Moshiri & Siavash Mirarab 2016