Skip to content

Developing Addons

NightDawnEX edited this page Mar 28, 2024 · 3 revisions

Specification

An Addon in this project must adhere to the following structure:

  • The Addon must be contained within a directory. The directory name and the class name of the Addon must be identical.
  • The Addon directory must contain an __init__.py file. This file must import the Addon class so it can be recognized by the system.
  • The Addon directory must contain an info.yaml file at its root. This file contains information about the Addon.
MyAddon/ 
│ 
├── __init__.py 
├── info.yaml 
└── my_addon.py

In __init__.py:

from .my_addon import MyAddon

In my_addon.py:

class MyAddon:
    # Addon code goes here

In info.yaml:

name: My Addon
version: 1.0.0
description: This is my addon.

Example

You can find two example addons that can be used as a reference:

Interactive Script

To develop an add-on, you can use the provided Python script to initialize the add-on file structure interactively. This script will create the necessary files and directories as per the specification mentioned above.

python scripts/addon.py

Config

In MAGI, configuration for an addon can be defined using a dataclass. This configuration will be automatically loaded and saved by MAGI, and the WebUI will generate a user interface for it. For more details, refer to the WebUI page.

Here is an example of how to define a configuration:

from magi.managers import SettingManager
from dataclasses import dataclass

@SettingManager.register
@dataclass
class Config:
  content: str = "Hello World!"
  submitting_file: str = "output.txt"

Hooks

Hooks are used to extend the functionality of an addon at specific points. For more details, refer to the pluggy documentation.

Here is an example of a hook:

@hookimpl
def grade(self):
  pass

The AddonSpec class in magi\common\addon.py defines the hooks that an addon can implement:

class AddonSpec:
  def before_generating(self)
  def generate(self)
  def after_generating(self)
  def before_grading(self)
  def grade(self)
  def after_grading(self)
  def generate_documentation(self)

FAQ

always no stdout since we need that for logging

info shown to student needs to be in output field

use provided run interface block network and accessing to result file

do not use os.remove shutil.rmtree etc

Clone this wiki locally