From 41c5a142b530a90717bc090b6361abaa6b32ad98 Mon Sep 17 00:00:00 2001 From: Muhammad Farhan Khan Date: Mon, 24 Jun 2024 17:35:46 +0500 Subject: [PATCH] fix: Address PR notified exceptions --- xblock/utils/resources.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/xblock/utils/resources.py b/xblock/utils/resources.py index 5f1185d00..b870e2bd2 100644 --- a/xblock/utils/resources.py +++ b/xblock/utils/resources.py @@ -22,7 +22,7 @@ def load_unicode(self, resource_path): Gets the content of a resource """ package_name = importlib.import_module(self.module_name).__package__ - return importlib.resources.files(package_name).joinpath(resource_path).read_text() + return importlib.resources.files(package_name).joinpath(resource_path.lstrip('/')).read_text() def render_django_template(self, template_path, context=None, i18n_service=None): """ @@ -56,8 +56,7 @@ def render_mako_template(self, template_path, context=None): ) context = context or {} template_str = self.load_unicode(template_path) - directory = str(importlib.resources.as_file( - importlib.resources.files(sys.modules[self.module_name].__package__))) + directory = os.path.dirname(os.path.realpath(sys.modules[self.module_name].__file__)) lookup = MakoTemplateLookup(directories=[directory]) template = MakoTemplate(template_str, lookup=lookup) return template.render(**context)