3. Writing a GNAThub plug-in

3.1. Location for user-defined plug-ins

Store your plug-ins in the extra directory. GNAThub attempts to load all files in this directory except the ones whose name starts with an underscore (_), which are expected to be support files referenced by multiple plug-ins.

3.2. Structure

A GNAThub plug-in is a Python class that extends the GNAThub.Plugin abstract class. It must override the GNAThub.Plugin.execute() method and set the name property.

Additionally, the user can override the two following methods:

These will be called respectively before and after the GNAThub.Plugin.execute() method.

3.3. Execution

The plug-in is discovered and loaded by the GNAThub driver unless explicitly disabled in the project file using the Plugins_Off attribute. If it remains enabled, it is executed along with the other plugins without any further action.

3.4. Logging

Plug-ins can integrate with the logging mechanism provided by the GNAThub API through the log property of the GNAThub.Plugin class, e.g.:

self.log.debug('resource found at %s', resource)

Note that the GNAThub API provides its own logging.Handler implementation to integrate with the standard Python logging facility meaning that one can use the logging Python module directly and automatically benefit from this integration. This becomes particularly useful when importing thirdparty modules that already rely on this logging facility (e.g. Python requests).