Skip to content

Commit

Permalink
Drop support for Python 3.8 and replace pkg_resources with importlib.…
Browse files Browse the repository at this point in the history
…resources (#28)

* refactor: replace deprecated pkg_resources API

* chore: drop support for Python 3.8

* chore: upgrade requirements

* chore: update version and changelog

* chore: remove backports.zoneinfo constraint

---------

Co-authored-by: Maga Giorgianni <maria.jaimes@edunext.co>
  • Loading branch information
luisfelipec95 and magajh authored Feb 11, 2025
1 parent f54a336 commit f6f1570
Show file tree
Hide file tree
Showing 16 changed files with 166 additions and 278 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ jobs:
strategy:
matrix:
os: [ubuntu-20.04]
python-version: ['3.8', '3.11']
toxenv: [quality, docs, django32, django42]
exclude:
- python-version: '3.11'
toxenv: django32
python-version: ['3.11']
toxenv: [quality, docs, django42]

steps:
- uses: actions/checkout@v4
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ Unreleased

*

1.0.0 - 2025-02-05
**********************************************

Changed
=======

* Removed support for Python 3.8 and Django 3.2
* Replaced deprecated `pkg_resources` with `importlib.resources` for better compatibility with newer Django and Python versions.
* Starting with this version, this package is no longer compatible with releases older than Redwood.

0.6.0 - 2025-01-17
**********************************************

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Compatibility Notes
+------------------+--------------+
| Open edX Release | Version |
+==================+==============+
| Palm | >= 0.5.0 |
| Palm | >= 0.5.0 <1.0|
+------------------+--------------+
| Quince | >= 0.5.0 |
| Quince | >= 0.5.0 <1.0|
+------------------+--------------+
| Redwood | >= 0.5.0 |
+------------------+--------------+
Expand Down
2 changes: 1 addition & 1 deletion imagesgallery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Init for the ImagesGalleryXBlock package.
"""

__version__ = "0.6.0"
__version__ = "1.0.0"
10 changes: 3 additions & 7 deletions imagesgallery/imagesgallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from http import HTTPStatus
from urllib.parse import urljoin

import pkg_resources
from importlib.resources import files as importlib_files
from django.conf import settings
from django.utils import translation
from opaque_keys.edx.keys import AssetKey
Expand All @@ -15,7 +15,6 @@
from xblock.core import XBlock
from xblock.fields import List, Scope
from xblock.reference.user_service import XBlockUser
from xblock.utils.resources import ResourceLoader

from imagesgallery.edxapp_wrapper.contentstore import get_static_content, contentstore, update_course_run_asset
from imagesgallery.edxapp_wrapper.site_configuration import configuration_helpers
Expand Down Expand Up @@ -84,8 +83,7 @@ def block_id_parsed(self):

def resource_string(self, path):
"""Handy helper for getting resources from our kit."""
data = pkg_resources.resource_string(__name__, path)
return data.decode("utf8")
return importlib_files(__package__).joinpath(path).read_text(encoding="utf-8")

def read_file(self, path: str):
"""Helper for reading a file using a relative path"""
Expand Down Expand Up @@ -383,9 +381,7 @@ def _get_statici18n_js_url():
text_js = 'public/js/translations/{locale_code}/text.js'
lang_code = locale_code.split('-')[0]
for code in (locale_code, lang_code, 'en'):
loader = ResourceLoader(__name__)
if pkg_resources.resource_exists(
loader.module_name, text_js.format(locale_code=code)):
if importlib_files(__package__).joinpath(text_js.format(locale_code=code)).exists():
return text_js.format(locale_code=code)
return None

Expand Down
30 changes: 13 additions & 17 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,11 +8,9 @@ appdirs==1.4.4
# via fs
asgiref==3.8.1
# via django
backports-zoneinfo==0.2.1 ; python_version < "3.9"
# via django
boto3==1.36.0
boto3==1.36.13
# via fs-s3fs
botocore==1.36.0
botocore==1.36.13
# via
# boto3
# s3transfer
Expand All @@ -27,7 +25,7 @@ django-appconf==1.0.6
# via django-statici18n
django-statici18n==2.6.0
# via -r requirements/base.in
dnspython==2.6.1
dnspython==2.7.0
# via pymongo
edx-i18n-tools==1.6.3
# via -r requirements/base.in
Expand All @@ -53,36 +51,36 @@ lxml[html-clean,html_clean]==5.3.0
# xblock
lxml-html-clean==0.4.1
# via lxml
mako==1.3.8
mako==1.3.9
# via
# -r requirements/base.in
# xblock
# xblock-utils
markupsafe==2.1.5
markupsafe==3.0.2
# via
# mako
# xblock
openedx-django-pyfs==3.7.0
# via xblock
path==16.16.0
# via edx-i18n-tools
pbr==6.1.0
pbr==6.1.1
# via stevedore
polib==1.2.0
# via edx-i18n-tools
pymongo==4.10.1
pymongo==4.11
# via edx-opaque-keys
python-dateutil==2.9.0.post0
# via
# botocore
# xblock
pytz==2024.2
pytz==2025.1
# via xblock
pyyaml==6.0.2
# via
# edx-i18n-tools
# xblock
s3transfer==0.11.0
s3transfer==0.11.2
# via boto3
simplejson==3.19.3
# via
Expand All @@ -95,12 +93,10 @@ six==1.17.0
# python-dateutil
sqlparse==0.5.3
# via django
stevedore==5.3.0
stevedore==5.4.0
# via edx-opaque-keys
typing-extensions==4.12.2
# via
# asgiref
# edx-opaque-keys
# via edx-opaque-keys
urllib3==1.26.20
# via
# -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt
Expand All @@ -112,7 +108,7 @@ web-fragments==2.2.0
# xblock-utils
webob==1.8.9
# via xblock
xblock[django]==5.1.0
xblock[django]==5.1.1
# via
# -r requirements/base.in
# xblock-utils
Expand Down
43 changes: 15 additions & 28 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#
# 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
#
backports-tarfile==1.2.0
# via jaraco-context
certifi==2024.12.14
certifi==2025.1.31
# via requests
cffi==1.17.1
# via cryptography
Expand All @@ -16,19 +16,17 @@ cryptography==44.0.0
# via secretstorage
distlib==0.3.9
# via virtualenv
docutils==0.20.1
docutils==0.21.2
# via readme-renderer
filelock==3.16.1
filelock==3.17.0
# via
# tox
# virtualenv
id==1.5.0
# via twine
idna==3.10
# via requests
importlib-metadata==8.5.0
# via
# keyring
# twine
importlib-resources==6.4.5
importlib-metadata==8.6.1
# via keyring
jaraco-classes==3.4.0
# via keyring
Expand All @@ -40,13 +38,13 @@ jeepney==0.8.0
# via
# keyring
# secretstorage
keyring==25.5.0
keyring==25.6.0
# via twine
markdown-it-py==3.0.0
# via rich
mdurl==0.1.2
# via markdown-it-py
more-itertools==10.5.0
more-itertools==10.6.0
# via
# jaraco-classes
# jaraco-functools
Expand All @@ -57,8 +55,6 @@ packaging==24.2
# pyproject-api
# tox
# twine
pkginfo==1.12.0
# via twine
platformdirs==4.3.6
# via
# tox
Expand All @@ -73,10 +69,11 @@ pygments==2.19.1
# via
# readme-renderer
# rich
readme-renderer==43.0
readme-renderer==44.0
# via twine
requests==2.32.3
# via
# id
# requests-toolbelt
# twine
requests-toolbelt==1.0.0
Expand All @@ -89,31 +86,21 @@ secretstorage==3.3.3
# via keyring
six==1.17.0
# via tox
tomli==2.2.1
# via
# pyproject-api
# tox
tox==3.28.0
# via
# -r requirements/ci.in
# tox-battery
tox-battery==0.6.2
# via -r requirements/ci.in
twine==6.0.1
twine==6.1.0
# via -r requirements/ci.in
typing-extensions==4.12.2
# via
# rich
# tox
urllib3==1.26.20
# via
# -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt
# -c requirements/constraints.txt
# requests
# twine
virtualenv==20.29.0
virtualenv==20.29.1
# via tox
zipp==3.20.2
# via
# importlib-metadata
# importlib-resources
zipp==3.21.0
# via importlib-metadata
6 changes: 0 additions & 6 deletions requirements/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,3 @@
# which require urllib3<2 for now.
# Issue for unpinning: https://github.com/openedx/edx-platform/issues/32222
urllib3<2.0.0

# backports.zoneinfo is only needed for Python < 3.9
backports.zoneinfo; python_version<'3.9'

# edx-lint 5.3.7 is the last version compatible with python 3.8
edx_lint<5.4.0
Loading

0 comments on commit f6f1570

Please sign in to comment.