diff --git a/setup.py b/setup.py index 493bc77..873b485 100644 --- a/setup.py +++ b/setup.py @@ -155,5 +155,6 @@ def is_requirement(line): 'Natural Language :: English', "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", ] ) diff --git a/sql_grader/mixins/scenario.py b/sql_grader/mixins/scenario.py index d6966d5..cfb13ff 100644 --- a/sql_grader/mixins/scenario.py +++ b/sql_grader/mixins/scenario.py @@ -1,54 +1,13 @@ """ Mixin workbench behavior into XBlocks """ -from glob import glob -import importlib.resources -import importlib +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) 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('-')) - 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: @@ -61,10 +20,4 @@ def workbench_scenarios(cls): """ Gather scenarios to be displayed in the workbench """ - module = cls.__module__ - module = module.split('.', maxsplit=1)[0] - module_ref = importlib.import_module(module) - files = importlib.resources.files(module_ref).joinpath('scenarios') - files = _find_files(files) - scenarios = _read_files(files) - return scenarios + return loader.load_scenarios_from_path("../scenarios") diff --git a/tox.ini b/tox.ini index 58ebf1b..7d0926b 100644 --- a/tox.ini +++ b/tox.ini @@ -2,14 +2,14 @@ envlist = csslint eslint - py{38, 311}-django{42}quality + py{311}-django{42}quality [testenv] deps = -rrequirements/test.txt -e git+https://github.com/openedx/codejail.git@3.0.0\#egg=codejail django42: Django>=4.2,<4.3 - + commands = coverage run manage.py test coverage report