Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

160: Migrate to ResourceLoader #165

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-20.04]
python-version: ['3.8']
python-version: ['3.11']
abdullahQureshee marked this conversation as resolved.
Show resolved Hide resolved
toxenv: [django32, django42, quality, csslint, eslint]

steps:
Expand Down
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.11

- name: Install pip
run: pip install -r requirements/pip.txt
Expand Down
58 changes: 6 additions & 52 deletions qualtricssurvey/mixins/scenario.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,14 @@
"""
Mixin workbench behavior into XBlocks
"""
from glob import glob
import pkg_resources


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
try:
from xblock.utils.resources import ResourceLoader
except ModuleNotFoundError:
from xblockutils.resources import ResourceLoader


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 = f"{directory}/*.xml"
files = glob(pattern)
return files
loader = ResourceLoader(__name__)


class XBlockWorkbenchMixin:
Expand All @@ -62,9 +21,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")
abdullahQureshee marked this conversation as resolved.
Show resolved Hide resolved
28 changes: 13 additions & 15 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,50 +1,48 @@
#
# This file is autogenerated by pip-compile with Python 3.8
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# make upgrade
#
appdirs==1.4.4
# via fs
asgiref==3.7.2
asgiref==3.8.1
# via django
django==3.2.24
django==3.2.25
# via
# -c requirements/common_constraints.txt
# -r requirements/base.in
fs==2.4.16
# via xblock
lxml==5.1.0
lxml==5.3.0
# via xblock
mako==1.3.2
mako==1.3.5
# via xblock
markupsafe==2.1.5
# via
# mako
# xblock
python-dateutil==2.8.2
python-dateutil==2.9.0.post0
# via xblock
pytz==2024.1
pytz==2024.2
# via
# django
# xblock
pyyaml==6.0.1
pyyaml==6.0.2
# via xblock
simplejson==3.19.2
simplejson==3.19.3
# via xblock
six==1.16.0
# via
# fs
# python-dateutil
sqlparse==0.4.4
sqlparse==0.5.1
# via django
typing-extensions==4.10.0
# via asgiref
web-fragments==2.1.0
web-fragments==2.2.0
# via xblock
webob==1.8.7
webob==1.8.8
# via xblock
xblock==1.10.0
xblock==5.1.0
# via -r requirements/base.in

# The following packages are considered to be unsafe in a requirements file:
Expand Down
35 changes: 15 additions & 20 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#
# This file is autogenerated by pip-compile with Python 3.8
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# make upgrade
#
cachetools==5.3.2
cachetools==5.5.0
# via
# -r requirements/tox.txt
# tox
certifi==2024.2.2
certifi==2024.8.30
# via requests
chardet==5.2.0
# via
Expand All @@ -20,53 +20,48 @@ colorama==0.4.6
# via
# -r requirements/tox.txt
# tox
coverage==6.5.0
coverage[toml]==7.6.1
# via coveralls
coveralls==3.3.1
coveralls==4.0.1
# via -r requirements/ci.in
distlib==0.3.8
# via
# -r requirements/tox.txt
# virtualenv
docopt==0.6.2
# via coveralls
filelock==3.13.1
filelock==3.16.0
# via
# -r requirements/tox.txt
# tox
# virtualenv
idna==3.6
idna==3.10
# via requests
packaging==23.2
packaging==24.1
# via
# -r requirements/tox.txt
# pyproject-api
# tox
platformdirs==4.2.0
platformdirs==4.3.3
# via
# -r requirements/tox.txt
# tox
# virtualenv
pluggy==1.4.0
pluggy==1.5.0
# via
# -r requirements/tox.txt
# tox
pyproject-api==1.6.1
pyproject-api==1.7.1
# via
# -r requirements/tox.txt
# tox
requests==2.31.0
requests==2.32.3
# via coveralls
tomli==2.0.1
# via
# -r requirements/tox.txt
# pyproject-api
# tox
tox==4.13.0
tox==4.18.1
# via -r requirements/tox.txt
urllib3==2.2.1
urllib3==2.2.3
# via requests
virtualenv==20.25.1
virtualenv==20.26.4
# via
# -r requirements/tox.txt
# tox
8 changes: 4 additions & 4 deletions requirements/pip.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#
# This file is autogenerated by pip-compile with Python 3.8
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# make upgrade
#
wheel==0.42.0
wheel==0.44.0
# via -r requirements/pip.in

# The following packages are considered to be unsafe in a requirements file:
pip==24.0
pip==24.2
# via -r requirements/pip.in
setuptools==69.1.1
setuptools==75.0.0
# via -r requirements/pip.in
21 changes: 6 additions & 15 deletions requirements/pip_tools.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
#
# This file is autogenerated by pip-compile with Python 3.8
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# make upgrade
#
build==1.0.3
build==1.2.2
# via pip-tools
click==8.1.7
# via pip-tools
importlib-metadata==7.0.1
packaging==24.1
# via build
packaging==23.2
# via build
pip-tools==7.4.0
pip-tools==7.4.1
# via -r requirements/pip_tools.in
pyproject-hooks==1.0.0
# via
# build
# pip-tools
tomli==2.0.1
pyproject-hooks==1.1.0
# via
# build
# pip-tools
# pyproject-hooks
wheel==0.42.0
wheel==0.44.0
# via pip-tools
zipp==3.17.0
# via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
# pip
Expand Down
Loading