-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: XBlock overrides #778
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nsprenkle Thanks for creating the PR
- Didn't do the manual testing
- Done with the quick review, suggest some changes
- Was thinking we are merging then filtering the entrypoints here but to keep the signature of method seems alright to me
@farhan, thanks for the review. Have tried to address all your comments and is ready for your re-review |
@kdmccormick PR seems alright to me. Your review is mandatory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice implementation. Thanks so much for jumping in and making this happen. Just a few requests.
df98da0
to
e5b5967
Compare
@kdmccormick and @farhan , have updated to your suggestions. Ready for re-review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more comments but nothing that needs re-review. I haven't manually tested, so I'm approving on the assumption that you have.
Thank a bunch @nsprenkle ! This will be awesome for site operators to have 🎸
xblock/plugin.py
Outdated
# Get the default entry point | ||
default_plugin = _default_select_no_override(identifier, block_entry_points) | ||
|
||
# If we have an unambiguous override, that gets priority. Otherwise, return default. | ||
if len(overrides) == 1: | ||
return overrides[0] | ||
elif len(overrides) > 1: | ||
raise AmbiguousPluginError(all_entry_points) | ||
return default_plugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following approach seems clean to me.
@kdmccormick You can give a second thought
# Prioritize and return a single unambiguous override; otherwise, return the single entry point.
# Raise errors for missing, multiple entry points, or multiple overrides.
if len(all_entry_points) == 0:
raise PluginMissingError(identifier)
elif len(all_entry_points) > 1:
raise AmbiguousPluginError(all_entry_points)
elif len(overrides) > 1:
raise AmbiguousPluginOverrideError(overrides)
elif len(overrides) == 1:
return overrides[0]
else: # len(all_entry_points) == 1
return all_entry_points[0]
- Avoid introducing new method i-e-
_default_select_no_override
. - Put the the
_default_select_no_override
docs indefault_select
method docs. - Introduce separate Exception for multiple override. For example
AmbiguousPluginOverrideError
. We can also useAmbiguousPluginError
but passoverrides
and generate separate message for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding _default_select_no_override -- Yeah, I do not feel strongly since it is an internal implementation detail, but combining the functions does make it easier to follow IMO. If you are willing to make that change @nsprenkle, great; if not, I don't want to block merging on this concern.
Regarding the error message -- @farhan makes a very good point, we should make it clear whether there are multiple regular plugins vs. multiple overrides. As it is, the error cases would be indistinguishable to an operator.
@nsprenkle , I don't have a preference between a new exception class vs. the same exception with a different message. If you do go with separate exceptions, please just make AmbiguousPluginOverrideError a subclass of AmbiguousPluginError so that existing catch AmbiguousPluginError
statements will catch AmbiguousPluginOverrideError.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kdmccormick , added as a new Exception
xblock/plugin.py
Outdated
If multiple classes are found for either `{cls.entry_points}.overrides` or | ||
`{cls.entry_points}`, it will raise an `AmbiguousPluginError`. | ||
|
||
If `default` is provided, return it if no entry_point matching | ||
`identifier` is found. Otherwise, will raise a PluginMissingError | ||
If no classes are found for `{cls.entry_points}`, it will raise a `PluginMissingError`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swap both lines as per order
If no classes are found for `{cls.entry_points}`, it will raise a `PluginMissingError`.
If multiple classes are found for either `{cls.entry_points}.overrides` or
`{cls.entry_points}`, it will raise an `AmbiguousPluginError`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arguably, load_class
doesn't even care about those details since those reside in the select
function. I would prefer to delete them entirely than split hairs over the ordering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arguably, load_class doesn't even care about those details since those reside in the select function.
+1, they are good as is
FWIW they are helpful lines to have in the docstring
@kdmccormick / @farhan. Will merge / create a new release on Monday. Thanks, both! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nsprenkle Nice work 🌟
Rebase the branch, Squash merge it and release the new version
Co-authored-by: Kyle McCormick <[email protected]>
Co-authored-by: Kyle McCormick <[email protected]>
db7d24d
to
b9ac909
Compare
Add ability to override another XBlock with the
xblock.v1.overrides
entrypoint.Notes
Usage
Tests