From 141f9a4e10cc9cbc0c445b02f59c7c1e5e907fcd Mon Sep 17 00:00:00 2001 From: Maari Tamm Date: Wed, 24 Jul 2024 12:52:11 +0200 Subject: [PATCH 1/4] Add support for Open edX Redwood release * Update the import statement for xblock-utils The `xblock-utils` library has been deprecated as a separate package; the `utils` library has been moved into the `XBlock` and should now be imported from `xblock.utils` instead. (https://github.com/openedx/XBlock/issues/675) * Upgrade to XBlock 2 Remove the use of deprecated `xblock.fragment` and direct id_generator parameters. 9https://github.com/openedx/XBlock/pull/680) * Add Python 3.11 to test matrix; Drop Python 3.8 from test matrix * Add a version compatibility matrix to the README Fixes: #38 --- .github/workflows/tox.yml | 6 +++--- README.md | 13 +++++++++++++ markdown_xblock/html.py | 12 ++++++------ requirements/base.txt | 3 +-- requirements/test.txt | 2 +- setup.py | 2 +- tox.ini | 4 ++-- 7 files changed, 27 insertions(+), 15 deletions(-) diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index d7f56db..c6c683f 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -10,8 +10,8 @@ jobs: strategy: matrix: python-version: - - '3.8' - '3.10' + - '3.11' pip-version: - 22.0.4 - 23.2.1 @@ -49,10 +49,10 @@ jobs: uses: actions/checkout@v1 - name: Download artifacts uses: actions/download-artifact@v2 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v2 with: - python-version: 3.8 + python-version: '3.10' - name: Install dependencies run: | pip install coverage diff --git a/README.md b/README.md index a25a786..7830d23 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,19 @@ This XBlock allows course authors to create and edit course content in Markdown and displays it as HTML. +## Version compatibility matrix + +You must install a supported release of this plugin to match the Open +edX and Tutor version you are deploying. + +| Open edX release | Tutor version | Xblock version | +|------------------|-------------------|----------------| +| Olive | `>=15.0, <16` | `<2.0` | +| Palm | `>=16.0, <17` | `<2.0` | +| Quince | `>=17.0, <18` | `<2.0` | +| Redwood | `>=18.0, <19` | `>=2.0` | + + ## Installation with [Tutor](https://docs.tutor.edly.io) You may install the markdown-xblock to your Tutor environment by adding it to the `OPENEDX_EXTRA_PIP_REQUIREMENTS` list in `config.yml`: ``` diff --git a/markdown_xblock/html.py b/markdown_xblock/html.py index c3aeefc..736171a 100644 --- a/markdown_xblock/html.py +++ b/markdown_xblock/html.py @@ -8,10 +8,10 @@ from django.conf import settings as django_settings from xblock.core import XBlock from xblock.fields import List, Scope, String -from xblock.fragment import Fragment -from xblockutils.resources import ResourceLoader -from xblockutils.settings import XBlockWithSettingsMixin -from xblockutils.studio_editable import StudioEditableXBlockMixin, loader +from web_fragments.fragment import Fragment +from xblock.utils.resources import ResourceLoader +from xblock.utils.settings import XBlockWithSettingsMixin +from xblock.utils.studio_editable import StudioEditableXBlockMixin, loader from .utils import _ @@ -276,7 +276,7 @@ def get_editable_fields(self): return fields @classmethod - def parse_xml(cls, node, runtime, keys, id_generator): + def parse_xml(cls, node, runtime, keys): """ Use `node` to construct a new block. """ @@ -284,7 +284,7 @@ def parse_xml(cls, node, runtime, keys, id_generator): # Read markdown content from file and add to editor. url_name = node.get('url_name', node.get('slug')) - location = id_generator.create_definition(node.tag, url_name) + location = runtime.id_generator.create_definition(node.tag, url_name) filename = node.get('filename') pointer_path = "{category}/{url_path}".format( diff --git a/requirements/base.txt b/requirements/base.txt index 606f4f6..5788dbc 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,7 +1,6 @@ # Requirements for app run -xblock-utils<=4.0.0 -xblock-sdk<0.9.0 +xblock-sdk django-statici18n<2.5 edx-i18n-tools<1.4 Mako==1.2.4 diff --git a/requirements/test.txt b/requirements/test.txt index c663775..a5c7ae6 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -11,4 +11,4 @@ mock==3.0.5 # Github requirements django-pyfs<3.2 -xblock-sdk<0.9.0 +xblock-sdk diff --git a/setup.py b/setup.py index f1d6d34..400e0f2 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ def package_data(pkg, roots): 'markdown_xblock', ], install_requires=[ - 'XBlock<=1.9', + 'XBlock>=2.0', 'markdown2>=2.3.9', 'Pygments>=2.0.1' ], diff --git a/tox.ini b/tox.ini index 0614211..e0700d1 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,10 @@ [tox] -envlist = py{38,310,312},flake8,report +envlist = py{310,311,312},flake8,report [gh-actions] python = - 3.8: py38,flake8 3.10: py310,flake8 + 3.11: py311,flake8 3.12: py312,flake8 [flake8] From bf1f373b61c62e3bbbe7b6bced5d32129c9a2438 Mon Sep 17 00:00:00 2001 From: Florian Haas Date: Fri, 2 Aug 2024 11:53:56 +0200 Subject: [PATCH 2/4] fixup! Add support for Open edX Redwood release Support versions before and after 2 of the XBlock API. Distinguish using the following logic: * When using a Python version prior to 3.9, assume we need the pre-2 API. * For later Python versions, assume the latest API. This way, we get the correct dependencies installed for Redwood (which uses Python 3.11) and earlier releases (which use 3.8). --- .github/workflows/tox.yml | 1 + markdown_xblock/html.py | 28 ++++++++++++++++++++++------ requirements/test.txt | 3 ++- setup.py | 5 +++-- tox.ini | 3 ++- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index c6c683f..dc730fb 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -10,6 +10,7 @@ jobs: strategy: matrix: python-version: + - '3.8' - '3.10' - '3.11' pip-version: diff --git a/markdown_xblock/html.py b/markdown_xblock/html.py index 736171a..d9cd319 100644 --- a/markdown_xblock/html.py +++ b/markdown_xblock/html.py @@ -8,10 +8,16 @@ from django.conf import settings as django_settings from xblock.core import XBlock from xblock.fields import List, Scope, String -from web_fragments.fragment import Fragment -from xblock.utils.resources import ResourceLoader -from xblock.utils.settings import XBlockWithSettingsMixin -from xblock.utils.studio_editable import StudioEditableXBlockMixin, loader +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 StudioEditableXBlockMixin, loader +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 StudioEditableXBlockMixin, loader from .utils import _ @@ -276,15 +282,25 @@ def get_editable_fields(self): return fields @classmethod - def parse_xml(cls, node, runtime, keys): + 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 + # Read markdown content from file and add to editor. url_name = node.get('url_name', node.get('slug')) - location = runtime.id_generator.create_definition(node.tag, url_name) + location = id_generator.create_definition(node.tag, url_name) filename = node.get('filename') pointer_path = "{category}/{url_path}".format( diff --git a/requirements/test.txt b/requirements/test.txt index a5c7ae6..cf23d0d 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -11,4 +11,5 @@ mock==3.0.5 # Github requirements django-pyfs<3.2 -xblock-sdk +xblock-sdk<0.9.0;python_version<"3.9" +xblock-sdk;python_version>="3.9" diff --git a/setup.py b/setup.py index 400e0f2..518c85a 100644 --- a/setup.py +++ b/setup.py @@ -41,9 +41,10 @@ def package_data(pkg, roots): 'markdown_xblock', ], install_requires=[ - 'XBlock>=2.0', + 'XBlock<2; python_version < "3.9"', + 'XBlock<5; python_version >= "3.9"', 'markdown2>=2.3.9', - 'Pygments>=2.0.1' + 'Pygments>=2.0.1', ], setup_requires=[ 'setuptools-scm', diff --git a/tox.ini b/tox.ini index e0700d1..4f2a752 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,9 @@ [tox] -envlist = py{310,311,312},flake8,report +envlist = py{38,310,311,312},flake8,report [gh-actions] python = + 3.8: py38,flake8 3.10: py310,flake8 3.11: py311,flake8 3.12: py312,flake8 From e687a698cb5d0baa8c9092040956771fa343d270 Mon Sep 17 00:00:00 2001 From: Florian Haas Date: Fri, 2 Aug 2024 12:46:15 +0200 Subject: [PATCH 3/4] build: Add pipdeptree Having pipdeptree in the test environment is very helpful in determining what versions of dependencies actually get installed, particularly in a CI pipeline. Add the pipdeptree and pipdeptree-requirements testenvs, and invoke them from the GitHub Actions workflow. --- tox.ini | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tox.ini b/tox.ini index 4f2a752..20580b9 100644 --- a/tox.ini +++ b/tox.ini @@ -1,12 +1,12 @@ [tox] -envlist = py{38,310,311,312},flake8,report +envlist = py{38,310,311,312},pipdeptree{,-requirements},flake8,report [gh-actions] python = - 3.8: py38,flake8 - 3.10: py310,flake8 - 3.11: py311,flake8 - 3.12: py312,flake8 + 3.8: py38,pipdeptree{,-requirements},flake8 + 3.10: py310,pipdeptree{,-requirements},flake8 + 3.11: py311,pipdeptree{,-requirements},flake8 + 3.12: py312,pipdeptree{,-requirements},flake8 [flake8] ignore = E124 @@ -28,6 +28,17 @@ deps = -rrequirements/base.txt -rrequirements/test.txt +[testenv:pipdeptree] +deps = + pipdeptree +commands = pipdeptree -w fail + +[testenv:pipdeptree-requirements] +deps = + -rrequirements/base.txt + pipdeptree +commands = pipdeptree -w fail + [testenv:flake8] deps = flake8 commands = flake8 From fc0a9d458d8a5c666813b9b1d54d251b328d8be0 Mon Sep 17 00:00:00 2001 From: Florian Haas Date: Fri, 2 Aug 2024 14:36:53 +0200 Subject: [PATCH 4/4] build: Remove Python 3.10 from the test matrix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We need to test this XBlock on Python 3.8 (for Open edX releases prior to Redwood), 3.11 (for Redwood), and 3.12 (which is the current latest Python release). There is no real good reason to test on 3.10, so we might as well drop it. --- .github/workflows/tox.yml | 1 - tox.ini | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index dc730fb..5e23bfb 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -11,7 +11,6 @@ jobs: matrix: python-version: - '3.8' - - '3.10' - '3.11' pip-version: - 22.0.4 diff --git a/tox.ini b/tox.ini index 20580b9..14c70fc 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,9 @@ [tox] -envlist = py{38,310,311,312},pipdeptree{,-requirements},flake8,report +envlist = py{38,311,312},pipdeptree{,-requirements},flake8,report [gh-actions] python = 3.8: py38,pipdeptree{,-requirements},flake8 - 3.10: py310,pipdeptree{,-requirements},flake8 3.11: py311,pipdeptree{,-requirements},flake8 3.12: py312,pipdeptree{,-requirements},flake8