From 85f3c9c5b56c7a86aa95c6a5630816b4a0106f3d Mon Sep 17 00:00:00 2001 From: "Kyle D. McCormick" Date: Tue, 19 Mar 2024 12:11:11 -0400 Subject: [PATCH 1/4] docs: document XBLOCK_MIXINS and XBLOCK_EXTRA_MIXINS --- cms/envs/common.py | 17 ++++++++++++++--- lms/envs/common.py | 24 ++++++++++++++++++++---- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index a33c415789bd..9c9d900a1af9 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -995,16 +995,27 @@ from xmodule.modulestore.inheritance import InheritanceMixin from xmodule.x_module import XModuleMixin -# These are the Mixins that should be added to every XBlock. -# This should be moved into an XBlock Runtime/Application object -# once the responsibility of XBlock creation is moved out of modulestore - cpennington +# These are the Mixins that will be added to every Blocklike upon instantiation. +# DO NOT EXPAND THIS LIST!! We want it eventually to be EMPTY. Why? Because dynamically adding functions/behaviors to +# objects at runtime is confusing for both developers and static tooling (pylint/mypy). Instead... +# - to add special Blocklike behaviors just for your site: override `XBLOCK_EXTRA_MIXINS` with your own XBlockMixins. +# - to add new functionality to all Blocklikes: add it to the base Blocklike class in the core openedx/XBlock repo. XBLOCK_MIXINS = ( + # TODO: For each of these, either + # (a) merge their functionality into the base Blocklike class, or + # (b) refactor their functionality out of the Blocklike objects and into the edx-platform block runtimes. LmsBlockMixin, InheritanceMixin, XModuleMixin, EditInfoMixin, AuthoringMixin, ) + +# .. setting_name: XBLOCK_EXTRA_MIXINS +# .. setting_default: () +# .. setting_description: Custom mixins that will be dynamically added to every XBlock and XBlockAside instance. +# These can be classes or dotted-path references to classes. +# For example: `XBLOCK_EXTRA_MIXINS = ('my_custom_package.my_module.MyCustomMixin',)` XBLOCK_EXTRA_MIXINS = () # Paths to wrapper methods which should be applied to every XBlock's FieldData. diff --git a/lms/envs/common.py b/lms/envs/common.py index 27e689035204..30ba71f62aad 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1640,12 +1640,28 @@ def _make_mako_template_dirs(settings): from xmodule.modulestore.inheritance import InheritanceMixin # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position from xmodule.x_module import XModuleMixin # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position -# These are the Mixins that should be added to every XBlock. -# This should be moved into an XBlock Runtime/Application object -# once the responsibility of XBlock creation is moved out of modulestore - cpennington -XBLOCK_MIXINS = (LmsBlockMixin, InheritanceMixin, XModuleMixin, EditInfoMixin) +# These are the Mixins that will be added to every Blocklike upon instantiation. +# DO NOT EXPAND THIS LIST!! We want it eventually to be EMPTY. Why? Because dynamically adding functions/behaviors to +# objects at runtime is confusing for both developers and static tooling (pylint/mypy). Instead... +# - to add special Blocklike behaviors just for your site: override `XBLOCK_EXTRA_MIXINS` with your own XBlockMixins. +# - to add new functionality to all Blocklikes: add it to the base Blocklike class in the core openedx/XBlock repo. +XBLOCK_MIXINS = ( + # TODO: For each of these, either + # (a) merge their functionality into the base Blocklike class, or + # (b) refactor their functionality out of the Blocklike objects and into the edx-platform block runtimes. + LmsBlockMixin, + InheritanceMixin, + XModuleMixin, + EditInfoMixin, +) if SkillTaggingMixin: XBLOCK_MIXINS += (SkillTaggingMixin,) + +# .. setting_name: XBLOCK_EXTRA_MIXINS +# .. setting_default: () +# .. setting_description: Custom mixins that will be dynamically added to every XBlock and XBlockAside instance. +# These can be classes or dotted-path references to classes. +# For example: `XBLOCK_EXTRA_MIXINS = ('my_custom_package.my_module.MyCustomMixin',)` XBLOCK_EXTRA_MIXINS = () # .. setting_name: XBLOCK_FIELD_DATA_WRAPPERS From 5ebecd17483c5c70df2fa27a1df1a316ea4f0600 Mon Sep 17 00:00:00 2001 From: "Kyle D. McCormick" Date: Tue, 13 Feb 2024 11:51:16 -0500 Subject: [PATCH 2/4] chore: remove reference to deprecated HierarchyMixin This has been a no-op for a long time anyway, since HierarchyMixin has been explicitly mixed into XBlock for as long as I remember. Ref: https://github.com/openedx/XBlock/issues/714 --- xmodule/tests/xml/factories.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xmodule/tests/xml/factories.py b/xmodule/tests/xml/factories.py index 0c183ebd72a4..23a57898b6dc 100644 --- a/xmodule/tests/xml/factories.py +++ b/xmodule/tests/xml/factories.py @@ -9,7 +9,6 @@ from factory import Factory, Sequence, lazy_attribute, post_generation from fs.osfs import OSFS from lxml import etree -from xblock.mixins import HierarchyMixin from xmodule.modulestore.inheritance import InheritanceMixin from xmodule.x_module import XModuleMixin @@ -70,7 +69,7 @@ class Meta: model = XmlImportData filesystem = OSFS(mkdtemp()) - xblock_mixins = (InheritanceMixin, XModuleMixin, HierarchyMixin) + xblock_mixins = (InheritanceMixin, XModuleMixin) url_name = Sequence(str) attribs = {} policy = {} From e64ecb97877f5862897ff8b12566876158d73200 Mon Sep 17 00:00:00 2001 From: "Kyle D. McCormick" Date: Tue, 19 Mar 2024 15:28:55 -0400 Subject: [PATCH 3/4] chore: tweak tests to work with XBlock==3.0.0 --- xmodule/modulestore/tests/test_api.py | 2 +- xmodule/modulestore/tests/test_inheritance.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xmodule/modulestore/tests/test_api.py b/xmodule/modulestore/tests/test_api.py index e42d3ded46c2..4e665c9eecbc 100644 --- a/xmodule/modulestore/tests/test_api.py +++ b/xmodule/modulestore/tests/test_api.py @@ -46,7 +46,7 @@ def test_get_xblock_root_module_name(): mixed_done_xblock = runtime.construct_xblock_from_class(DoneXBlock, Mock()) - assert mixed_done_xblock.__module__ == 'xblock.internal' # Mixed classes has a runtime generated module name. + assert mixed_done_xblock.__module__ == 'xblock.core' assert mixed_done_xblock.unmixed_class == DoneXBlock, 'The unmixed_class property retains the original property.' assert get_xblock_root_module_name(mixed_done_xblock) == 'done' diff --git a/xmodule/modulestore/tests/test_inheritance.py b/xmodule/modulestore/tests/test_inheritance.py index eb98cbc4f9f9..253a9f7abf23 100644 --- a/xmodule/modulestore/tests/test_inheritance.py +++ b/xmodule/modulestore/tests/test_inheritance.py @@ -15,7 +15,7 @@ from xmodule.modulestore.inheritance import InheritanceMixin -class TestXBlock: +class TestXBlock(XBlock): """ An empty Xblock, to be used, when creating a block with mixins. """ From cef968e728ed173164f648aa842e983ec4b7a6e7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 10 Apr 2024 15:31:51 -0400 Subject: [PATCH 4/4] chore: upgrade XBlock version to 3.0.0 --- requirements/edx/base.txt | 2 +- requirements/edx/development.txt | 2 +- requirements/edx/doc.txt | 2 +- requirements/edx/testing.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index 90c285aa784c..6ccc229e715a 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -1222,7 +1222,7 @@ webob==1.8.7 # xblock wrapt==1.16.0 # via -r requirements/edx/paver.txt -xblock[django]==2.0.0 +xblock[django]==3.1.0 # via # -r requirements/edx/kernel.in # acid-xblock diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index 6896af46785e..71e7c88f8a98 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -2185,7 +2185,7 @@ wrapt==1.16.0 # -r requirements/edx/doc.txt # -r requirements/edx/testing.txt # astroid -xblock[django]==2.0.0 +xblock[django]==3.1.0 # via # -r requirements/edx/doc.txt # -r requirements/edx/testing.txt diff --git a/requirements/edx/doc.txt b/requirements/edx/doc.txt index e6af73a92e37..29f323f9fb86 100644 --- a/requirements/edx/doc.txt +++ b/requirements/edx/doc.txt @@ -1488,7 +1488,7 @@ webob==1.8.7 # xblock wrapt==1.16.0 # via -r requirements/edx/base.txt -xblock[django]==2.0.0 +xblock[django]==3.1.0 # via # -r requirements/edx/base.txt # acid-xblock diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index bb47b75566ed..821e29efbf54 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -1604,7 +1604,7 @@ wrapt==1.16.0 # via # -r requirements/edx/base.txt # astroid -xblock[django]==2.0.0 +xblock[django]==3.1.0 # via # -r requirements/edx/base.txt # acid-xblock