Skip to content

Commit

Permalink
chore: Transition from pkg_resources API to importlib-resources API
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan committed May 20, 2024
1 parent 2c32c47 commit 2ad2a80
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
5 changes: 2 additions & 3 deletions feedback/extensions/filters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Open edX Filters needed for instructor dashboard integration.
"""
import pkg_resources
import importlib.resources
from crum import get_current_request
from django.conf import settings
from django.template import Context, Template
Expand Down Expand Up @@ -75,8 +75,7 @@ def run_filter(

def resource_string(self, path):
"""Handy helper for getting resources from our kit."""
data = pkg_resources.resource_string("feedback", path)
return data.decode("utf8")
return importlib.resources.files("feedback").joinpath(path).read_text()


def load_blocks(request, course):
Expand Down
13 changes: 7 additions & 6 deletions feedback/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@

import html
import random
import pkg_resources
import six

import importlib.resources
import six
from web_fragments.fragment import Fragment
from xblock.core import XBlock
from xblock.fields import Scope, Integer, String, List, Float, Boolean
from web_fragments.fragment import Fragment

from feedback.utils import _

try:
from xblock.utils.resources import ResourceLoader
except ModuleNotFoundError: # For backward compatibility with releases older than Quince.
from xblockutils.resources import ResourceLoader

resource_loader = ResourceLoader(__name__)
resource_loader = ResourceLoader(__package__)

# We provide default text which is designed to elicit student thought. We'd
# like instructors to customize this to something highly structured (not
Expand Down Expand Up @@ -133,8 +135,7 @@ class FeedbackXBlock(XBlock):
@classmethod
def resource_string(cls, path):
"""Handy helper for getting resources from our kit."""
data = pkg_resources.resource_string(__name__, path)
return data.decode("utf8")
return importlib.resources.files(__package__).joinpath(path).read_text()

def get_prompt(self, index=-1):
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def package_data(pkg, roots):

setup(
name='feedback-xblock',
version='1.6.0',
version='1.6.1',
description='XBlock for providing feedback on course content',
long_description=README,
long_description_content_type='text/x-rst',
Expand Down

0 comments on commit 2ad2a80

Please sign in to comment.