-
Notifications
You must be signed in to change notification settings - Fork 0
Avoid confusion between hook constants and hook strings #125
Comments
@regisb No rush on this one, but it's ready for your opinion when you have the time. |
The more general problem here is the high level hooks API. Personally, I'm unhappy with:
(I realise that I may be getting carried along a little too far in the last bullet point... We should probably implement proposed changes only up to the last item) |
@regisb great points.
I agree that "catalog" is better than "consts", but I think the best solution is to get rid of the nesting altogether. As you mention there are ways to import anything from the API:
The docs are structured to reflect the long form, but all our examples and the cookiecutter use the short form. I think we should choose one form and get rid of the other. In interest of making the API feel concise and preserving backwards compatibility with our published examples, I propose just flattening the entire API into the If you're worried about breaking backwards compatibility so soon after the V1 release, we could stub out the With that restructuring done, we could achieve this:
by renaming
Agreed, I will make an issue to improve the hooks API reference docs.
I don't think just docs would be sufficient, but I think renaming |
@regisb This came up again today, so I'd like to try to come up with a concrete plan here. What do you think of:
|
The hooks API had several issues which are summarized in this comment: openedx-unsupported/wg-developer-experience#125 (comment) 1. "consts" was a bad name 2. "hooks.filters" and "hooks.Filters" could easily be confused 3. docs made it difficult to understand that plugin developers should use the catalog To address these issues, we: 1. move "consts.py" to "catalog.py" 2. Remove "hooks.actions", "hooks.filters", "hooks.contexts" from the API. 3. re-organize the docs and give better usage examples in the catalog. This change is a partial fix for openedx-unsupported/wg-developer-experience#125
@kdmccormick your plan is sound, but I think it's possible to make more lightweight changes that address the misunderstandings. I created a PR to resolve the confusions. Please let me know what you think. |
The hooks API had several issues which are summarized in this comment: openedx-unsupported/wg-developer-experience#125 (comment) 1. "consts" was a bad name 2. "hooks.filters" and "hooks.Filters" could easily be confused 3. docs made it difficult to understand that plugin developers should use the catalog To address these issues, we: 1. move "consts.py" to "catalog.py" 2. Remove "hooks.actions", "hooks.filters", "hooks.contexts" from the API. 3. re-organize the docs and give better usage examples in the catalog. This change is a partial fix for openedx-unsupported/wg-developer-experience#125
The hooks API had several issues which are summarized in this comment: openedx-unsupported/wg-developer-experience#125 (comment) 1. "consts" was a bad name 2. "hooks.filters" and "hooks.Filters" could easily be confused 3. docs made it difficult to understand that plugin developers should use the catalog To address these issues, we: 1. move "consts.py" to "catalog.py" 2. Remove "hooks.actions", "hooks.filters", "hooks.contexts" from the API. 3. re-organize the docs and give better usage examples in the catalog. This change is a partial fix for openedx-unsupported/wg-developer-experience#125
The hooks API had several issues which are summarized in this comment: openedx-unsupported/wg-developer-experience#125 (comment) 1. "consts" was a bad name 2. "hooks.filters" and "hooks.Filters" could easily be confused 3. docs made it difficult to understand that plugin developers should use the catalog To address these issues, we: 1. move "consts.py" to "catalog.py" 2. Remove "hooks.actions", "hooks.filters", "hooks.contexts" from the API. 3. re-organize the docs and give better usage examples in the catalog. This change is a partial fix for openedx-unsupported/wg-developer-experience#125
The hooks API had several issues which are summarized in this comment: openedx-unsupported/wg-developer-experience#125 (comment) 1. "consts" was a bad name 2. "hooks.filters" and "hooks.Filters" could easily be confused 3. docs made it difficult to understand that plugin developers should use the catalog To address these issues, we: 1. move "consts.py" to "catalog.py" 2. Remove "hooks.actions", "hooks.filters", "hooks.contexts" from the API. 3. re-organize the docs and give better usage examples in the catalog. This change is a partial fix for openedx-unsupported/wg-developer-experience#125
At this point the docs build correctly with python 3.8, but not with python 3.10. I have already spent too much time on this problem and I don't know how to improve it. Sphinx is making me mad. We are at a point where we have a viable conf.py file and I'd rather not change it too much. Here are the errors on python 3.10: /home/data/regis/projets/overhang/repos/overhang/tutor/tutor/hooks/catalog.py:docstring of tutor.hooks.Actions.COMPOSE_PROJECT_STARTED:1: WARNING: py:class reference target not found: tutor.core.hooks.actions.Action[(<class 'str'>, typing.Dict[str, typing.Union[str, float, NoneType, bool, typing.List[str], typing.List[typing.Any], typing.Dict[str, typing.Any], typing.Dict[typing.Any, typing.Any]]], <class 'str'>)] /home/data/regis/projets/overhang/repos/overhang/tutor/tutor/hooks/catalog.py:docstring of tutor.hooks.Actions.DO_JOB:1: WARNING: py:class reference target not found: tutor.core.hooks.actions.Action[(<class 'str'>, typing.Any)] /home/data/regis/projets/overhang/repos/overhang/tutor/tutor/hooks/catalog.py:docstring of tutor.hooks.Actions.PLUGIN_UNLOADED:1: WARNING: py:class reference target not found: tutor.core.hooks.actions.Action[(<class 'str'>, <class 'str'>, typing.Dict[str, typing.Union[str, float, NoneType, bool, typing.List[str], typing.List[typing.Any], typing.Dict[str, typing.Any], typing.Dict[typing.Any, typing.Any]]])] /home/data/regis/projets/overhang/repos/overhang/tutor/tutor/hooks/catalog.py:docstring of tutor.hooks.Actions.PROJECT_ROOT_READY:1: WARNING: py:class reference target not found: tutor.core.hooks.actions.Action[(<class 'str'>,)] /home/data/regis/projets/overhang/repos/overhang/tutor/tutor/hooks/catalog.py:docstring of tutor.hooks.Filters.COMPOSE_MOUNTS:1: WARNING: py:class reference target not found: tutor.core.hooks.filters.Filter[list[tuple[str, str]], (<class 'str'>,)] This PR addresses this developer experience issue: openedx-unsupported/wg-developer-experience#125
At this point the docs build correctly with python 3.8, but not with python 3.10. I have already spent too much time on this problem and I don't know how to improve it. Sphinx is making me mad. We are at a point where we have a viable conf.py file and I'd rather not change it too much. Here are the errors on python 3.10: /home/data/regis/projets/overhang/repos/overhang/tutor/tutor/hooks/catalog.py:docstring of tutor.hooks.Actions.COMPOSE_PROJECT_STARTED:1: WARNING: py:class reference target not found: tutor.core.hooks.actions.Action[(<class 'str'>, typing.Dict[str, typing.Union[str, float, NoneType, bool, typing.List[str], typing.List[typing.Any], typing.Dict[str, typing.Any], typing.Dict[typing.Any, typing.Any]]], <class 'str'>)] /home/data/regis/projets/overhang/repos/overhang/tutor/tutor/hooks/catalog.py:docstring of tutor.hooks.Actions.DO_JOB:1: WARNING: py:class reference target not found: tutor.core.hooks.actions.Action[(<class 'str'>, typing.Any)] /home/data/regis/projets/overhang/repos/overhang/tutor/tutor/hooks/catalog.py:docstring of tutor.hooks.Actions.PLUGIN_UNLOADED:1: WARNING: py:class reference target not found: tutor.core.hooks.actions.Action[(<class 'str'>, <class 'str'>, typing.Dict[str, typing.Union[str, float, NoneType, bool, typing.List[str], typing.List[typing.Any], typing.Dict[str, typing.Any], typing.Dict[typing.Any, typing.Any]]])] /home/data/regis/projets/overhang/repos/overhang/tutor/tutor/hooks/catalog.py:docstring of tutor.hooks.Actions.PROJECT_ROOT_READY:1: WARNING: py:class reference target not found: tutor.core.hooks.actions.Action[(<class 'str'>,)] /home/data/regis/projets/overhang/repos/overhang/tutor/tutor/hooks/catalog.py:docstring of tutor.hooks.Filters.COMPOSE_MOUNTS:1: WARNING: py:class reference target not found: tutor.core.hooks.filters.Filter[list[tuple[str, str]], (<class 'str'>,)] This PR addresses this developer experience issue: openedx-unsupported/wg-developer-experience#125
The hooks API had several issues which are summarized in this comment: openedx-unsupported/wg-developer-experience#125 (comment) 1. "consts" was a bad name 2. "hooks.filters" and "hooks.Filters" could easily be confused 3. docs made it difficult to understand that plugin developers should use the catalog To address these issues, we: 1. move "consts.py" to "catalog.py" 2. Remove "hooks.actions", "hooks.filters", "hooks.contexts" from the API. 3. re-organize the docs and give better usage examples in the catalog. This change is a partial fix for openedx-unsupported/wg-developer-experience#125
The hooks API had several issues which are summarized in this comment: openedx-unsupported/wg-developer-experience#125 (comment) 1. "consts" was a bad name 2. "hooks.filters" and "hooks.Filters" could easily be confused 3. docs made it difficult to understand that plugin developers should use the catalog To address these issues, we: 1. move "consts.py" to "catalog.py" 2. Remove "hooks.actions", "hooks.filters", "hooks.contexts" from the API. 3. re-organize the docs and give better usage examples in the catalog. This change is a partial fix for openedx-unsupported/wg-developer-experience#125
The hooks API had several issues which are summarized in this comment: openedx-unsupported/wg-developer-experience#125 (comment) 1. "consts" was a bad name 2. "hooks.filters" and "hooks.Filters" could easily be confused 3. docs made it difficult to understand that plugin developers should use the catalog To address these issues, we: 1. move "consts.py" to "catalog.py" 2. Remove "hooks.actions", "hooks.filters", "hooks.contexts" from the API. 3. re-organize the docs and give better usage examples in the catalog. This change is a partial fix for openedx-unsupported/wg-developer-experience#125
I believe we can close this now that this PR was merged. |
Context
Users can add hook callbacks in two ways:
hooks.filters.add_item("filter:name", callback)
hooks.Filters.FILTER_NAME.add_item(callback)
These two methods look quite similar. I watched this confuse a plugin developer--they were trying to write
hooks.filters.add_item("FILTER_NAME", callback)
. You can see why it'd be hard to notice why there was anything wrong with that line. And, since there is no error reporting when you add a callback to a non-existent filter (like"FILTER_NAME"
), they were stuck on this problem for quite a while.If you subscribe to the Zen of Python, I think we're violating two principles here:
Proposed Acceptance Criteria
Rename the
Action.get
andFilter.get
method toAction.define
andFilter.define
. These methods should be called once-- and exactly once --for every hook. Re-defining a hook would raise an error, as would trying to reference a hook that isn't defined.Remove the string-based
add
function (and its variants) from the API interface. API consumer would only be able to add callbacks by referencing the defined Action and Filter constants. In other words, deprecate method (1) in favor of method (2) above.We may need to do some thinking in order to make this work with template-string-based hooks, but I think it's doable.
The text was updated successfully, but these errors were encountered: