Skip to content

Commit

Permalink
fix: no module named importlib_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
hinakhadim committed Jan 25, 2025
1 parent 76e269f commit df71a40
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion openedx_cmi5_xblock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

from .openedx_cmi5_xblock import CMI5XBlock

__version__ = '0.1.0'
__version__ = '0.1.1'
17 changes: 15 additions & 2 deletions openedx_cmi5_xblock/openedx_cmi5_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import xml.etree.ElementTree as ET
import zipfile

import importlib_resources
import requests
from django.conf import settings
from django.core.files.base import ContentFile
Expand All @@ -37,6 +36,16 @@
send_xapi_to_external_lrs,
)

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


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -648,7 +657,11 @@ def workbench_scenarios():

def resource_string(path):
"""Handy helper for getting resources from our kit."""
data = importlib_resources.files(__name__).joinpath(path).read_bytes()
try:
data = importlib_resources.files(__name__).joinpath(path).read_bytes()
except TypeError:
data = importlib_resources.files(__package__).joinpath(path).read_bytes()
return data.decode("utf8")
return data.decode('utf8')


Expand Down

0 comments on commit df71a40

Please sign in to comment.