From 0e65692fc3ef3925cfdd80a646db8d3be142d714 Mon Sep 17 00:00:00 2001 From: Muhammad Farhan Khan Date: Mon, 20 May 2024 18:41:22 +0500 Subject: [PATCH] chore: Transition from pkg_resources API to importlib-resources API --- feedback/extensions/filters.py | 5 ++--- feedback/feedback.py | 11 ++++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/feedback/extensions/filters.py b/feedback/extensions/filters.py index 8fac1a3..2813907 100644 --- a/feedback/extensions/filters.py +++ b/feedback/extensions/filters.py @@ -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 @@ -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): diff --git a/feedback/feedback.py b/feedback/feedback.py index 86175a8..f4dd5d2 100644 --- a/feedback/feedback.py +++ b/feedback/feedback.py @@ -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. @@ -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): """