Skip to content

Commit

Permalink
Merge pull request #190 from edly-io/omer/replace_pkg_resources
Browse files Browse the repository at this point in the history
xblock-image-modal | Drop py3.8 support | replace pkg_resource with importlib.resources
  • Loading branch information
Feanil Patel authored Oct 1, 2024
2 parents dd655f2 + daba989 commit e1c5cac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: setup python
uses: actions/setup-python@v3
with:
python-version: 3.8
python-version: 3.12

- name: Install pip
run: pip install -r requirements/pip.txt
Expand Down
61 changes: 6 additions & 55 deletions imagemodal/mixins/scenario.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,13 @@
"""
Mixin workbench behavior into XBlocks
"""
from glob import glob
import pkg_resources
try:
from xblock.utils.resources import ResourceLoader
except ModuleNotFoundError:
from xblockutils.resources import ResourceLoader


def _read_file(file_path):
"""
Read in a file's contents
"""
with open(file_path, encoding='utf-8') as file_input:
file_contents = file_input.read()
return file_contents


def _parse_title(file_path):
"""
Parse a title from a file name
"""
title = file_path
title = title.split('/')[-1]
title = '.'.join(title.split('.')[:-1])
title = ' '.join(title.split('-'))
title = ' '.join([
word.capitalize()
for word in title.split(' ')
])
return title


def _read_files(files):
"""
Read the contents of a list of files
"""
file_contents = [
(
_parse_title(file_path),
_read_file(file_path),
)
for file_path in files
]
return file_contents


def _find_files(directory):
"""
Find XML files in the directory
"""
pattern = "{directory}/*.xml".format(
directory=directory,
)
files = glob(pattern)
return files
loader = ResourceLoader(__name__)


class XBlockWorkbenchMixin:
Expand All @@ -64,9 +20,4 @@ def workbench_scenarios(cls):
"""
Gather scenarios to be displayed in the workbench
"""
module = cls.__module__
module = module.split('.', maxsplit=1)[0]
directory = pkg_resources.resource_filename(module, 'scenarios')
files = _find_files(directory)
scenarios = _read_files(files)
return scenarios
return loader.load_scenarios_from_path("../scenarios")

0 comments on commit e1c5cac

Please sign in to comment.