Skip to content

Commit

Permalink
Add support for the Open edX Redwood release
Browse files Browse the repository at this point in the history
* Update the test matrix to test:
  -  Python 3.8 & Xblock 1.8 (Quince)
  -  Python 3.11,3.12 & Xblock 4.0 (Redwood)

* Update requirements to keep in sync with edx-platform

TODO
  • Loading branch information
Maari Tamm committed Aug 6, 2024
1 parent 41a2034 commit 1bf2936
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 22 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ jobs:
matrix:
python-version:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
pip-version:
- 22.0.4
Expand Down
63 changes: 52 additions & 11 deletions hastexo/hastexo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@

from xblock.core import XBlock, XML_NAMESPACES
from xblock.fields import Scope, Float, String, Dict, List, Integer, Boolean
from xblock.fragment import Fragment
try: # XBlock 2+
from web_fragments.fragment import Fragment
from xblock.utils.resources import ResourceLoader
from xblock.utils.settings import XBlockWithSettingsMixin
from xblock.utils.studio_editable import (
NestedXBlockSpec,
StudioContainerWithNestedXBlocksMixin,
StudioEditableXBlockMixin
)
except ImportError: # Compatibility with XBlock<2
from xblock.fragment import Fragment
from xblockutils.resources import ResourceLoader
from xblockutils.settings import XBlockWithSettingsMixin
from xblockutils.studio_editable import (
NestedXBlockSpec,
StudioContainerWithNestedXBlocksMixin,
StudioEditableXBlockMixin,
)

from xblock.scorable import ScorableXBlockMixin, Score
from xblockutils.resources import ResourceLoader
from xblockutils.studio_editable import (
NestedXBlockSpec,
StudioContainerWithNestedXBlocksMixin,
StudioEditableXBlockMixin,
)
from xblockutils.settings import XBlockWithSettingsMixin


from distutils.util import strtobool
from django.db import transaction
Expand Down Expand Up @@ -305,12 +317,22 @@ def parse_attributes(tag, node, block):
block.providers.append(provider)

@classmethod
def parse_xml(cls, node, runtime, keys, id_generator):
def parse_xml(cls, node, runtime, keys, id_generator=None):
"""
Use `node` to construct a new block.
"""
block = runtime.construct_xblock_from_class(cls, keys)

# Prior to XBlock 2.0, id_generator is passed in.
# Since XBlock 2.0, we grab it from the runtime.
#
# TODO: Once we decide to drop support for versions prior to
# XBlock 2 (i.e. Open edX releases before Redwood), we can
# drop id_generator from the method signature, and always rely
# on runtime.id_generator.
if not id_generator:
id_generator = runtime.id_generator

if 'filename' in node.attrib:
# Read xml content from file.
url_name = node.get('url_name', node.get('slug'))
Expand Down Expand Up @@ -351,7 +373,15 @@ def parse_xml(cls, node, runtime, keys, id_generator):
child.tag))
# Import nested blocks
for child in node:
block.runtime.add_node_as_child(block, child, id_generator)
# Prior to XBlock 2.0, id_generator needs to be passed here.
#
# TODO: Once we decide to drop support for versions prior to
# XBlock 2 (i.e. Open edX releases before Redwood), we can
# drop the try/except block and passing the id_generator here.
try:
block.runtime.add_node_as_child(block, child, id_generator)
except TypeError:
block.runtime.add_node_as_child(block, child)
else:
for child in node:
if child.tag is etree.Comment:
Expand All @@ -368,7 +398,18 @@ def parse_xml(cls, node, runtime, keys, id_generator):
cls.parse_attributes(child.tag, child, block)
else:
# Import nested blocks
block.runtime.add_node_as_child(block, child, id_generator)

# Prior to XBlock 2.0, id_generator needs to be passed.
#
# TODO: Once we decide to drop support for versions prior
# to XBlock 2 (i.e. Open edX releases before Redwood),
# we can drop the try/except block here and stop passing
# the id_generator.
try:
block.runtime.add_node_as_child(
block, child, id_generator)
except TypeError:
block.runtime.add_node_as_child(block, child)

# Attributes become fields.
for name, value in list(node.items()): # lxml has no iteritems
Expand Down
4 changes: 2 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ python-novaclient>=7.1.2,<16
tenacity>=6.2,<8

# for hastexo_guacamole_client
django<=4.2.8
django<=4.2.14
channels<=4.0.0
daphne<=4.0.0
twisted<24 # drop this restriction once we drop Python 3.8 and 3.9 support
mysqlclient<=2.2.1 # keep in sync with edx-platform
mysqlclient<=2.2.4 # keep in sync with edx-platform
jsonfield>=3.1.0,<4 # keep in sync with edx-platform
pyguacamole>=0.11
3 changes: 2 additions & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
-r base.txt

# These package versions must be kept in sync with edx-platform as much as possible.
xblock-utils<=3.0.0
xblock-sdk<0.9.0;python_version<"3.9"
xblock-sdk;python_version>="3.9"
six==1.16.0
lazy<=1.5
django-pyfs==3.1.0
Expand Down
8 changes: 2 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
[tox]
envlist = flake8,pipdeptree{,-requirements},py{38,39,310,311,312}-xblock{17,18,19}-celery5
envlist = flake8,pipdeptree{,-requirements},py38-xblock18-celery5,py{311,312}-xblock{40}-celery5

[gh-actions]
python =
3.8: flake8,pipdeptree,pipdeptree-requirements,py38
3.9: flake8,pipdeptree,pipdeptree-requirements,py39
3.10: flake8,pipdeptree,pipdeptree-requirements,py310
3.11: flake8,pipdeptree,pipdeptree-requirements,py311
3.12: flake8,pipdeptree,pipdeptree-requirements,py312

Expand All @@ -29,10 +27,8 @@ exclude_lines =
deps =
-rrequirements/setup.txt
-rrequirements/test.txt
xblock-sdk<0.9.0
xblock17: XBlock>=1.7,<1.8
xblock18: XBlock>=1.8,<1.9
xblock19: XBlock>=1.9,<2
xblock40: XBlock>=4.0,<5
celery5: celery>=5,<6
commands =
python run_tests.py []
Expand Down

0 comments on commit 1bf2936

Please sign in to comment.