-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate to plugins.v1 with filters & actions
This is a very large refactoring which aims at making Tutor both more extendable and more generic. Historically, the Tutor plugin system was designed as an ad-hoc solution to allow developers to modify their own Open edX platforms without having to fork Tutor. The plugin API was simple, but limited, because of its ad-hoc nature. As a consequence, there were many things that plugin developers could not do, such as extending different parts of the CLI or adding custom template filters. Here, we refactor the whole codebase to make use of a generic plugin system. This system was inspired by the Wordpress plugin API and the Open edX "hooks and filters" API. The various components are added to a small core thanks to a set of actions and filters. Actions are callback functions that can be triggered at different points of the application lifecycle. Filters are functions that modify some data. Both actions and filters are collectively named as "hooks". Hooks can optionally be created within a certain context, which makes it easier to keep track of which application created which callback. This new hooks system allows us to provide a Python API that developers can use to extend their applications. The API reference is added to the documentation, along with a new plugin development tutorial. The plugin v0 API remains supported for backward compatibility of existing plugins. Done: - Do not load commands from plugins which are not enabled. - Load enabled plugins once on start. - Implement contexts for actions and filters, which allow us to keep track of the source of every hook. - Migrate patches - Migrate commands - Migrate plugin detection - Migrate templates_root - Migrate config - Migrate template environment globals and filters - Migrate hooks to tasks - Generate hook documentation - Generate patch reference documentation - Add the concept of action priority
- Loading branch information
Showing
68 changed files
with
3,419 additions
and
1,501 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,16 @@ | ||
#!/usr/bin/env python3 | ||
from tutor.plugins import OfficialPlugin | ||
from tutor import hooks | ||
from tutor.commands.cli import main | ||
from tutor.plugins.v0 import OfficialPlugin | ||
|
||
|
||
@hooks.Actions.INSTALL_PLUGINS.add() | ||
def _install_official_plugins() -> None: | ||
# Manually install plugins: that's because entrypoint plugins are not properly | ||
# detected within the binary bundle. | ||
OfficialPlugin.install_all() | ||
|
||
# Manually install plugins (this is for creating the bundle) | ||
for plugin_name in [ | ||
"android", | ||
"discovery", | ||
"ecommerce", | ||
"forum", | ||
"license", | ||
"mfe", | ||
"minio", | ||
"notes", | ||
"richie", | ||
"webui", | ||
"xqueue", | ||
]: | ||
try: | ||
OfficialPlugin.load(plugin_name) | ||
except ImportError: | ||
pass | ||
|
||
if __name__ == "__main__": | ||
# Call the regular main function, which will not detect any entrypoint plugin | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
""" | ||
This module is heavily inspired by Django's djangodocs.py: | ||
https://github.com/django/django/blob/main/docs/_ext/djangodocs.py | ||
""" | ||
from sphinx.application import Sphinx | ||
|
||
|
||
def setup(app: Sphinx) -> None: | ||
# https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx.application.Sphinx.add_crossref_type | ||
app.add_crossref_type( | ||
directivename="patch", | ||
rolename="patch", | ||
indextemplate="pair: %s; patch", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
docs/plugins/gettingstarted.rst → docs/plugins/v0/gettingstarted.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.. warning:: The v0 plugin API is no longer the recommended way of developing plugins for Tutor, starting from Tutor v13.2.0. See our new :ref:`plugin creation tutorial <plugin_development_tutorial>` to learn more about the new v1 plugin API. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
CLI Reference | ||
============= | ||
Reference | ||
========= | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
reference/cli/tutor | ||
reference/cli/config | ||
reference/cli/dev | ||
reference/cli/images | ||
reference/cli/k8s | ||
reference/cli/local | ||
reference/cli/plugins | ||
reference/api | ||
reference/cli | ||
reference/patches |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
=== | ||
API | ||
=== | ||
|
||
Hooks | ||
===== | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
api/hooks/actions | ||
api/hooks/filters | ||
api/hooks/contexts | ||
api/hooks/consts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.. _actions: | ||
|
||
======= | ||
Actions | ||
======= | ||
|
||
Actions are one of the two types of hooks (with :ref:`filters`) that can be used to extend Tutor. Actions are function callbacks that are called at various points during the application life cycle. Each action has a name, and callback functions can be attached to it. These functions are called in sequence and each can trigger side effects, independently from one another. | ||
|
||
.. autofunction:: tutor.hooks.actions::get | ||
.. autofunction:: tutor.hooks.actions::get_template | ||
.. autofunction:: tutor.hooks.actions::add | ||
.. autofunction:: tutor.hooks.actions::do | ||
.. autofunction:: tutor.hooks.actions::clear | ||
.. autofunction:: tutor.hooks.actions::clear_all | ||
|
||
.. autoclass:: tutor.hooks.actions.Action | ||
.. autoclass:: tutor.hooks.actions.ActionTemplate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
========= | ||
Constants | ||
========= | ||
|
||
Actions | ||
======= | ||
|
||
.. autoclass:: tutor.hooks.Actions | ||
:members: | ||
|
||
Filters | ||
======= | ||
|
||
.. autoclass:: tutor.hooks.Filters | ||
:members: | ||
|
||
Contexts | ||
======== | ||
|
||
.. autoclass:: tutor.hooks.Contexts | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
======== | ||
Contexts | ||
======== | ||
|
||
.. autofunction:: tutor.hooks.contexts::enter | ||
|
||
.. autoclass:: tutor.hooks.contexts.Context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.. _filters: | ||
|
||
======= | ||
Filters | ||
======= | ||
|
||
Filters are one of the two types of hooks (with :ref:`actions`) that can be used to extend Tutor. Filters are used to modify data. Each filter has a name, and callback functions can be attached to it. These functions are called in sequence; the result of each callback function is passed as the first argument to the next callback function. | ||
|
||
.. autofunction:: tutor.hooks.filters::get | ||
.. autofunction:: tutor.hooks.filters::get_template | ||
.. autofunction:: tutor.hooks.filters::add | ||
.. autofunction:: tutor.hooks.filters::add_item | ||
.. autofunction:: tutor.hooks.filters::add_items | ||
.. autofunction:: tutor.hooks.filters::apply | ||
.. autofunction:: tutor.hooks.filters::iterate | ||
.. autofunction:: tutor.hooks.filters::clear | ||
.. autofunction:: tutor.hooks.filters::clear_all | ||
|
||
.. autoclass:: tutor.hooks.filters.Filter | ||
.. autoclass:: tutor.hooks.filters.FilterTemplate |
Oops, something went wrong.