From 3572f674ab96a01882ea78a729209e3f2ab6f8c2 Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Thu, 27 Jun 2024 08:37:16 -0400 Subject: [PATCH] fix: No module named 'importlib_resources' (#80) 1. importlib_resources is a backport of.... 2. importlib.resources, a standard library package Redwood and earlier installed (1). Starting with the [py3.11 upgrade] we dropped (1) in favor of (2). To maintain compatibility with both, we use a try-except. Fixes the error on Tutor Nightly: ModuleNotFoundError: No module named 'importlib_resources' [py3.11 upgrade] https://github.com/openedx/edx-platform/pull/34788 --- changelog.d/20240625_104737_kyle_patch_1.md | 1 + openedxscorm/__about__.py | 2 +- openedxscorm/scormxblock.py | 11 +++++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 changelog.d/20240625_104737_kyle_patch_1.md diff --git a/changelog.d/20240625_104737_kyle_patch_1.md b/changelog.d/20240625_104737_kyle_patch_1.md new file mode 100644 index 0000000..9695ab1 --- /dev/null +++ b/changelog.d/20240625_104737_kyle_patch_1.md @@ -0,0 +1 @@ +- [Bugfix] Fix a bug where the scorm block would fail to load with an error message `No module named 'importlib_resources'` (by @kdmccormick) diff --git a/openedxscorm/__about__.py b/openedxscorm/__about__.py index 28cc149..93eb58c 100644 --- a/openedxscorm/__about__.py +++ b/openedxscorm/__about__.py @@ -1 +1 @@ -__version__ = "18.0.1" +__version__ = "18.0.2" diff --git a/openedxscorm/scormxblock.py b/openedxscorm/scormxblock.py index f94a085..a306ebb 100644 --- a/openedxscorm/scormxblock.py +++ b/openedxscorm/scormxblock.py @@ -15,15 +15,22 @@ from django.utils import timezone from django.utils.module_loading import import_string from webob import Response -import importlib_resources from six import string_types - from web_fragments.fragment import Fragment from xblock.core import XBlock from xblock.completable import CompletableXBlockMixin from xblock.exceptions import JsonHandlerError from xblock.fields import Scope, String, Float, Boolean, Dict, DateTime, Integer +try: + # Older Open edX releases (Redwood and earlier) install a backported version of + # importlib.resources: https://pypi.org/project/importlib-resources/ + import importlib_resources +except ModuleNotFoundError: + # Starting with Sumac, Open edX drops importlib-resources in favor of the standard library: + # https://docs.python.org/3/library/importlib.resources.html#module-importlib.resources + from importlib import resources as importlib_resources + try: try: from common.djangoapps.student.models import CourseEnrollment