Skip to content

Commit 036ae24

Browse files
committed
fix: Address PR request changes
1 parent 49742c8 commit 036ae24

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

xblock/core.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import inspect
77
import json
88
import logging
9-
import os
109
import warnings
1110
from collections import OrderedDict, defaultdict
1211

@@ -161,8 +160,12 @@ def open_local_resource(cls, uri):
161160

162161
@classmethod
163162
def _open_resource(cls, uri):
164-
return importlib.resources.files(inspect.getmodule(cls).__package__).joinpath(
165-
os.path.join(cls.resources_dir, uri)
163+
return importlib.resources.files(
164+
inspect.getmodule(cls).__package__
165+
).joinpath(
166+
cls.resources_dir
167+
).joinpath(
168+
uri
166169
).open('rb')
167170

168171
@classmethod

xblock/plugin.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,7 @@ def select(identifier, all_entry_points):
100100
if select is None:
101101
select = default_select
102102

103-
all_entry_points = [
104-
entry_point
105-
for entry_point in importlib.metadata.entry_points(group=cls.entry_point)
106-
if entry_point.name == identifier
107-
]
103+
all_entry_points = importlib.metadata.entry_points(group=cls.entry_point, name=identifier)
108104
for extra_identifier, extra_entry_point in iter(cls.extra_entry_points):
109105
if identifier == extra_identifier:
110106
all_entry_points.append(extra_entry_point)

xblock/utils/resources.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def load_unicode(self, resource_path):
2222
Gets the content of a resource
2323
"""
2424
package_name = importlib.import_module(self.module_name).__package__
25-
return importlib.resources.files(package_name).joinpath(resource_path.lstrip('/')).read_text()
25+
# Strip leading slash to avoid importlib exception with absolute paths
26+
return importlib.resources.files(package_name).joinpath(resource_path.lstrip('/')).read_text(encoding="utf-8")
2627

2728
def render_django_template(self, template_path, context=None, i18n_service=None):
2829
"""
@@ -56,7 +57,9 @@ def render_mako_template(self, template_path, context=None):
5657
)
5758
context = context or {}
5859
template_str = self.load_unicode(template_path)
59-
directory = os.path.dirname(os.path.realpath(sys.modules[self.module_name].__file__))
60+
61+
package_name = importlib.import_module(self.module_name).__package__
62+
directory = str(importlib.resources.files(package_name))
6063
lookup = MakoTemplateLookup(directories=[directory])
6164
template = MakoTemplate(template_str, lookup=lookup)
6265
return template.render(**context)

0 commit comments

Comments
 (0)