Skip to content

Commit

Permalink
fix: added support for py12, removed 3.8 from tox and fixed loading s…
Browse files Browse the repository at this point in the history
…cenarios
  • Loading branch information
OmerBhatti committed Sep 25, 2024
1 parent 1086127 commit 9648bea
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 55 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
)
59 changes: 6 additions & 53 deletions sql_grader/mixins/scenario.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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")
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]\#egg=codejail
django42: Django>=4.2,<4.3

commands =
coverage run manage.py test
coverage report
Expand Down

0 comments on commit 9648bea

Please sign in to comment.