openedx / wg-devops

Issue repository for the DevOps Working Group
1 stars 1 forks source link

Pass `config` to hook handlers whenever possible #32

Open kdmccormick opened 2 years ago

kdmccormick commented 2 years ago

Context

When reacting to an action or adding to a filter, plugin authors may want to look into the Tutor configuration dictionary. Some actions and filters pass their handlers config as an argument, others don't.

For those hooks that don't pass config, plugin authors could still load the config dictionary themselves in a hacky way:

from tutor import hooks, config

@hooks.SOME_ACTION.add()
def handle_some_action(...)
    root = ... # do some hackery to determine project root
    cfg = config.load_config(root)
    # then, handle action based on `cfg`

but this is clearly not something we want plugin authors resorting to.

I can't think of a good heuristic for whether or not a hook should pass config as an argument... so my gut feeling is that we should pass config as an argument to every single hook, in case plugin authors find it useful. (That being said, there are some hooks, like CONFIG_DEFAULTS, that we cannot possibly pass config to because the hook itself is used to build config.)

My proposal

In the interest of making the Plugin API as powerful as possible (without sacrificing our ability to maintain Tutor) , I propose that the config argument is passed to every hook, except for those hooks which are run before config is available.

Acceptance Criteria

TBD