Skip to content

Commit

Permalink
fix: failing importlib import in sumac
Browse files Browse the repository at this point in the history
  • Loading branch information
Danyal-Faheem committed Feb 20, 2025
1 parent 76e269f commit 5c57419
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 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,15 @@
import xml.etree.ElementTree as ET
import zipfile

import importlib_resources
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

import requests
from django.conf import settings
from django.core.files.base import ContentFile
Expand Down Expand Up @@ -648,7 +656,10 @@ 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')


Expand Down

0 comments on commit 5c57419

Please sign in to comment.