-
Notifications
You must be signed in to change notification settings - Fork 224
feat: XBlock overrides #778
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e39435d
feat: add ability to override XBlock with xblock.v1.overrides entry_p…
nsprenkle 95f5385
test: xblock overrides
nsprenkle 5ea8118
chore: bump version to 5.1.0
nsprenkle 3e08b42
docs: add changelog entry
nsprenkle 72a35fd
refactor: move override behavior into default select
nsprenkle a75d479
refactor: update logic for checking override
nsprenkle d68b00d
refactor: split override / default select, use default select in over…
nsprenkle 35d2423
docs: update changelog entry
nsprenkle 5721586
feat: update override checking to include leading period
nsprenkle 607e7dc
refactor: make default select use overrides, raise if overridden bloc…
nsprenkle 3911cef
docs: update docstrings
nsprenkle b86898e
docs: add tutorial for overriding XBlock
nsprenkle f9b33d4
docs: update documentation
nsprenkle 2a8ade3
test: add test for override without base block
nsprenkle f623861
docs: update documentation
nsprenkle b9ac909
feat: raise AmbiguousPluginOverrideError for ambibuous plugin overrides
nsprenkle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -11,3 +11,4 @@ XBlocks and the edX Platform | |
| edx_lms | ||
| devstack | ||
| edx | ||
| overrides | ||
This file contains hidden or 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,75 @@ | ||
| .. _Replace a Preinstalled XBlock With a Custom Implementation: | ||
|
|
||
| ########################################################## | ||
| Replace a Preinstalled XBlock With a Custom Implementation | ||
| ########################################################## | ||
|
|
||
| In XBlock ``v5.1.0``, the ability was introduced to override an XBlock with a custom | ||
| implementation. | ||
|
|
||
| This can be done by: | ||
|
|
||
| 1. Creating an XBlock in a new or existing package installed into ``edx-platform``. | ||
|
|
||
| 2. Adding the ``xblock.v1.overrides`` entry point in ``setup.py``, pointing to your | ||
| custom XBlock. | ||
|
|
||
| This works with updated logic in ``load_class``'s ``default_select``, which gives | ||
| load priority to a class with the ``.overrides`` suffix. | ||
|
|
||
| This can be disabled by providing a different ``select`` kwarg to ``load_class`` which | ||
| ignores or otherwise changes override logic. | ||
|
|
||
| ******* | ||
| Example | ||
| ******* | ||
|
|
||
| Imagine there is an XBlock installed ``edx-platform``: | ||
|
|
||
| .. code:: python | ||
|
|
||
| # edx-platform/xblocks/video_block.py | ||
| class VideoBlock(XBlock): | ||
| ... | ||
|
|
||
| # edx-platform/setup.py | ||
| setup( | ||
| # ... | ||
|
|
||
| entry_points={ | ||
| "xblock.v1": [ | ||
| "video = xblocks.video_block::VideoBlock" | ||
| # ... | ||
| ] | ||
| } | ||
| ) | ||
|
|
||
| If you then create your own Python package with a custom version of that XBlock... | ||
|
|
||
| .. code:: python | ||
|
|
||
| # your_plugin/xblocks/video_block.py | ||
| class YourVideoBlock(XBlock): | ||
| ... | ||
|
|
||
| # your_plugin/setup.py | ||
| setup( | ||
| # ... | ||
| entry_points={ | ||
| "xblock.v1.overrides": [ | ||
| "video = your_plugin.xblocks.video_block::YourVideoBlock" | ||
| # ... | ||
| ], | ||
| } | ||
| ) | ||
|
|
||
| And install that package into your virtual environment, then your block should be | ||
| loaded instead of the existing implementation. | ||
|
|
||
| .. note:: | ||
|
|
||
| The ``load_class`` code will throw an error in the following cases: | ||
|
|
||
| 1. There are multiple classes attempting to override one XBlock implementation. | ||
|
|
||
| 2. There is an override provided where an existing XBlock implementation is not found. |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ | |
| XBlock Courseware Components | ||
| """ | ||
|
|
||
| __version__ = '5.0.0' | ||
| __version__ = '5.1.0' | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.