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

edx-ora2 | Replace pkg_resources to importlib_resources | Drop support for python 3.8 #2238

Merged
merged 10 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
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 @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ['3.8', '3.11']
python-version: ['3.11', '3.12']
node-version: [16]
toxenv: [quality, js, django42]

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 @@ -16,7 +16,7 @@ jobs:
- name: setup python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.12

- name: Install pip
run: pip install -r requirements/pip.txt
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sphinx:
build:
os: "ubuntu-22.04"
tools:
python: "3.8"
python: "3.12"

# Optionally install extra requirements required to build your docs
python:
Expand Down
2 changes: 1 addition & 1 deletion openassessment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Initialization Information for Open Assessment Module
"""

__version__ = '6.12.0'
__version__ = '7.0.0'
ttqureshi marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 7 additions & 2 deletions openassessment/xblock/load_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import logging
from urllib.parse import urlparse

from pkg_resources import resource_string
from django.conf import settings
try:
from xblock.utils.resources import ResourceLoader
except ModuleNotFoundError:
from xblockutils.resources import ResourceLoader

logger = logging.getLogger(__name__) # pylint: disable=invalid-name

Expand All @@ -31,6 +34,8 @@ class LoadStatic:
_base_url = ''
_is_loaded = False

resource_loader = ResourceLoader(__name__)

@staticmethod
def reload_manifest():
"""
Expand All @@ -45,7 +50,7 @@ def reload_manifest():
logger.error('LMS_ROOT_URL is undefined')

try:
json_data = resource_string(__name__, 'static/dist/manifest.json').decode("utf8")
json_data = LoadStatic.resource_loader.load_unicode('static/dist/manifest.json')
LoadStatic._manifest = json.loads(json_data)
base_url_override = LoadStatic._manifest.get('base_url', None)
LoadStatic._is_loaded = True
Expand Down
9 changes: 6 additions & 3 deletions openassessment/xblock/openassessmentblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import logging
import re

import pkg_resources
import pytz
try:
from xblock.utils.resources import ResourceLoader
except ModuleNotFoundError:
from xblockutils.resources import ResourceLoader

from django.conf import settings
from django.contrib.auth import get_user_model
Expand Down Expand Up @@ -72,12 +75,12 @@
from openassessment.xblock.apis.ora_data_accessor import ORADataAccessor

logger = logging.getLogger(__name__) # pylint: disable=invalid-name
resource_loader = ResourceLoader(__name__)


def load(path):
"""Handy helper for getting resources from our kit."""
data = pkg_resources.resource_string(__name__, path)
return data.decode("utf8")
return resource_loader.load_unicode(path)


@XBlock.needs("i18n")
Expand Down
24 changes: 12 additions & 12 deletions openassessment/xblock/test/test_load_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,24 @@ def test_get_url_absolute_base_url(self):
self.assertEqual(LoadStatic.get_url(key_url), urljoin(
absolute_base_url, loaded_key_url))

@patch('pkg_resources.resource_string')
def test_get_url_file_not_found(self, resource_string):
@patch('xblock.utils.resources.ResourceLoader.load_unicode')
def test_get_url_file_not_found(self, load_unicode):
key_url = 'some_url.js'
resource_string.side_effect = IOError()
load_unicode.side_effect = IOError()
self.assertEqual(LoadStatic.get_url(key_url), urljoin(
self.default_base_url, 'some_url.js'))

@override_settings(LMS_ROOT_URL='localhost/')
@patch('pkg_resources.resource_string')
def test_get_url_file_not_found_with_root_url(self, resource_string):
@patch('xblock.utils.resources.ResourceLoader.load_unicode')
def test_get_url_file_not_found_with_root_url(self, load_unicode):
key_url = 'some_url.js'
resource_string.side_effect = IOError()
load_unicode.side_effect = IOError()
self.assertEqual(LoadStatic.get_url(key_url), urljoin(
'localhost/', self.default_base_url, 'some_url.js'))

@patch('pkg_resources.resource_string')
def test_get_url_with_manifest(self, resource_string):
resource_string.return_value = None
@patch('xblock.utils.resources.ResourceLoader.load_unicode')
def test_get_url_with_manifest(self, load_unicode):
load_unicode.return_value = None
key_url = 'some_url.js'
with patch('json.loads') as jsondata:
jsondata.return_value = {
Expand All @@ -92,9 +92,9 @@ def test_get_url_with_manifest(self, resource_string):
self.default_base_url, 'some_url.hashchunk.js'))

@override_settings(LMS_ROOT_URL='localhost/')
@patch('pkg_resources.resource_string')
def test_get_url_with_manifest_and_root_url(self, resource_string):
resource_string.return_value = None
@patch('xblock.utils.resources.ResourceLoader.load_unicode')
def test_get_url_with_manifest_and_root_url(self, load_unicode):
load_unicode.return_value = None
key_url = 'some_url.js'
with patch('json.loads') as jsondata:
jsondata.return_value = {
Expand Down
92 changes: 48 additions & 44 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# 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
Expand All @@ -8,24 +8,19 @@ appdirs==1.4.4
# via fs
asgiref==3.8.1
# via django
attrs==23.2.0
attrs==24.2.0
# via openedx-events
backports-zoneinfo==0.2.1 ; python_version < "3.9"
# via
# -c requirements/constraints.txt
# django
# djangorestframework
bleach==6.1.0
# via -r requirements/base.in
boto3==1.34.91
boto3==1.35.29
# via -r requirements/base.in
botocore==1.34.91
botocore==1.35.29
# via
# boto3
# s3transfer
certifi==2024.2.2
certifi==2024.8.30
# via requests
cffi==1.16.0
cffi==1.17.1
# via pynacl
charset-normalizer==3.3.2
# via requests
Expand All @@ -37,14 +32,15 @@ code-annotations==1.8.0
# via edx-toggles
defusedxml==0.7.1
# via -r requirements/base.in
django==4.2.11
django==4.2.16
# via
# -c requirements/constraints.txt
# -r requirements/base.in
# django-crum
# django-model-utils
# django-waffle
# djangorestframework
# edx-django-release-util
# edx-django-utils
# edx-i18n-tools
# edx-submissions
Expand All @@ -56,7 +52,7 @@ django-crum==0.7.9
# via
# edx-django-utils
# edx-toggles
django-model-utils==4.5.0
django-model-utils==5.0.0
# via
# -r requirements/base.in
# edx-submissions
Expand All @@ -68,26 +64,33 @@ django-waffle==4.1.0
# via
# edx-django-utils
# edx-toggles
djangorestframework==3.15.1
djangorestframework==3.15.2
# via
# -r requirements/base.in
# edx-submissions
edx-django-utils==5.12.0
dnspython==2.6.1
# via pymongo
edx-ccx-keys==1.3.0
# via openedx-events
edx-django-release-util==1.4.0
# via edx-submissions
edx-django-utils==5.15.0
# via
# -r requirements/base.in
# edx-toggles
# openedx-events
edx-i18n-tools==1.6.0
edx-i18n-tools==1.6.3
# via -r requirements/base.in
edx-opaque-keys[django]==2.8.0
edx-opaque-keys[django]==2.11.0
# via
# -r requirements/base.in
# edx-ccx-keys
# openedx-events
edx-submissions==3.7.0
edx-submissions==3.8.0
# via -r requirements/base.in
edx-toggles==5.2.0
# via -r requirements/base.in
fastavro==1.9.4
fastavro==1.9.7
# via openedx-events
fs==2.0.18
# via
Expand All @@ -99,7 +102,7 @@ idna==2.8
# via
# -c requirements/constraints.txt
# requests
jinja2==3.1.3
jinja2==3.1.4
# via code-annotations
jmespath==1.0.1
# via
Expand All @@ -115,26 +118,26 @@ loremipsum==1.0.5
# via
# -c requirements/constraints.txt
# -r requirements/base.in
lxml[html-clean]==5.2.1
lxml[html-clean]==5.3.0
# via
# -r requirements/base.in
# edx-i18n-tools
# lxml-html-clean
# xblock
lxml-html-clean==0.1.1
lxml-html-clean==0.2.2
# via lxml
mako==1.3.3
mako==1.3.5
# via xblock
markupsafe==2.1.5
# via
# jinja2
# mako
# xblock
newrelic==9.9.0
newrelic==10.0.0
# via edx-django-utils
openedx-events==9.9.2
openedx-events==9.14.1
# via -r requirements/base.in
openedx-filters==1.8.1
openedx-filters==1.10.0
# via -r requirements/base.in
path==13.1.0
# via
Expand All @@ -143,15 +146,15 @@ path==13.1.0
# path-py
path-py==12.5.0
# via -r requirements/base.in
pbr==6.0.0
pbr==6.1.0
# via stevedore
polib==1.2.0
# via edx-i18n-tools
psutil==5.9.8
psutil==6.0.0
# via edx-django-utils
pycparser==2.22
# via cffi
pymongo==3.13.0
pymongo==4.9.1
# via edx-opaque-keys
pynacl==1.5.0
# via edx-django-utils
Expand All @@ -166,48 +169,49 @@ python-swiftclient==3.13.1
# via
# -c requirements/constraints.txt
# -r requirements/base.in
pytz==2024.1
pytz==2024.2
# via
# -r requirements/base.in
# edx-submissions
# fs
# xblock
pyyaml==6.0.1
pyyaml==6.0.2
# via
# code-annotations
# edx-django-release-util
# edx-i18n-tools
# xblock
requests==2.31.0
requests==2.32.3
# via python-swiftclient
s3transfer==0.10.1
s3transfer==0.10.2
# via boto3
simplejson==3.19.2
simplejson==3.19.3
# via xblock
six==1.16.0
# via
# bleach
# edx-ccx-keys
# edx-django-release-util
# fs
# html5lib
# python-dateutil
# python-swiftclient
sqlparse==0.5.0
sqlparse==0.5.1
# via django
stevedore==5.2.0
stevedore==5.3.0
# via
# code-annotations
# edx-django-utils
# edx-opaque-keys
text-unidecode==1.3
# via python-slugify
typing-extensions==4.11.0
# via
# asgiref
# edx-opaque-keys
urllib3==1.26.18
typing-extensions==4.12.2
# via edx-opaque-keys
urllib3==2.2.3
# via
# botocore
# requests
voluptuous==0.14.2
voluptuous==0.15.2
# via
# -c requirements/constraints.txt
# -r requirements/base.in
Expand All @@ -217,9 +221,9 @@ webencodings==0.5.1
# via
# bleach
# html5lib
webob==1.8.7
webob==1.8.8
# via xblock
xblock==4.0.1
xblock==5.1.0
# via -r requirements/base.in

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