How does a plugin command access the Tutor configuration?


I’m a bit stumped on this issue, maybe someone can help. What’s the “proper” way for a plugin command (i.e. the command attribute that a plugin can define, as explained here) to access the rendered Tutor configuration?

In patches we can simply use {{ PLUGINNAME_VARIABLE }} and Jinja2 will do the rest, but I can’t quite wrap my head around what’s the proper way to do this in Python. I am guessing it has something to do with passing the Click context with a @click.pass_obj decorator and then somehow retrieving a configuration object, but I haven’t made much progress beyond that.

If anyone could enlighten me there, I would much appreciate that. :slight_smile: Thanks!


The only built-in mechanism is the tuto.config.load function – which is not an official API, but I’m pretty confident it will be maintained. You should draw some inspiration from the existing commands, for instance: tutor/ at bbba7b6c4e7e8b08b3d4be7323445ce78c2ce954 · overhangio/tutor · GitHub

You’ll want to write something along the lines of:

from tutor import config as tutor_config

def yourcommand(context: Context, ...) -> None:
    config = tutor_config.load(context.root)

Excellent, thank you!

Will that also reliably take care of name prefix mangling for configuration values defined by plugins? In other words, if my plugin is named foo and it has a config option named BAR, can I expect that this will allow me to grab both config['FOO_BAR'] (a config option for my own plugin), and config['LMS_HOST'] from Tutor itself?

For anyone following this, Régis has just merged a documentation patch related to the question raised in this thread:

1 Like