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 Jul 25, 2024
1 parent fc2fc88 commit 0e65692
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 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(encoding="utf-8")


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

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.
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(encoding="utf-8")

def get_prompt(self, index=-1):
"""
Expand Down

0 comments on commit 0e65692

Please sign in to comment.