Skip to content

Commit

Permalink
Merge pull request #350 from openedx/farhan/replace_pkg_resources
Browse files Browse the repository at this point in the history
Drop py3.8 support | Replace pkg_resources lib with importlib.resources
  • Loading branch information
farhan authored Aug 7, 2024
2 parents e83ba2d + 805ea25 commit 088065b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Change history for XBlock SDK

These are notable changes in XBlock.

1.0.0 - 2024-05-30
------------------
* dropped python 3.8 support
* transitioned from deprecated pkg_resources lib to importlib.resources

0.9.0
-----
* Xblock bumped to 3.0.0. Removed the deprecated id_generator method parameter in xblock.runtime
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ COPY . /usr/local/src/xblock-sdk
WORKDIR /usr/local/src/xblock-sdk

ENV VIRTUAL_ENV=/venvs/xblock-sdk
RUN python3.8 -m venv $VIRTUAL_ENV
RUN python3.11 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

RUN pip install --upgrade pip && pip install -r /usr/local/src/xblock-sdk/requirements/dev.txt
Expand Down
15 changes: 6 additions & 9 deletions sample_xblocks/filethumbs/filethumbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
"""



import json
import logging

import pkg_resources
import importlib.resources
import png
from web_fragments.fragment import Fragment
from xblock.core import XBlock
Expand Down Expand Up @@ -72,8 +70,9 @@ def student_view(self, context=None): # pylint: disable=W0613
"""

# Load the HTML fragment from within the package and fill in the template
html_str = pkg_resources.resource_string(__name__,
"static/html/thumbs.html").decode('utf-8')
html_str = importlib.resources.files(__package__).joinpath(
"static/html/thumbs.html"
).read_text(encoding="utf-8")
frag = Fragment(str(html_str))

if not self.fs.exists("thumbsvotes.json"):
Expand All @@ -86,12 +85,10 @@ def student_view(self, context=None): # pylint: disable=W0613
self.downvotes = votes['down']

# Load the CSS and JavaScript fragments from within the package
css_str = pkg_resources.resource_string(__name__,
"static/css/thumbs.css").decode('utf-8')
css_str = importlib.resources.files(__package__).joinpath("static/css/thumbs.css").read_text(encoding="utf-8")
frag.add_css(str(css_str))

js_str = pkg_resources.resource_string(__name__,
"static/js/src/thumbs.js").decode('utf-8')
js_str = importlib.resources.files(__package__).joinpath("static/js/src/thumbs.js").read_text(encoding="utf-8")
frag.add_javascript(str(js_str))

with self.fs.open('uparrow.png', 'wb') as file_output:
Expand Down
15 changes: 6 additions & 9 deletions sample_xblocks/thumbs/thumbs.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"""An XBlock providing thumbs-up/thumbs-down voting."""



import logging

import pkg_resources
import importlib.resources
from web_fragments.fragment import Fragment
from xblock.core import XBlock, XBlockAside
from xblock.fields import Boolean, Integer, Scope
Expand Down Expand Up @@ -36,17 +34,16 @@ def student_view(self, context=None): # pylint: disable=W0613
"""

# Load the HTML fragment from within the package and fill in the template
html_str = pkg_resources.resource_string(__name__,
"static/html/thumbs.html").decode('utf-8')
html_str = importlib.resources.files(
__package__
).joinpath("static/html/thumbs.html").read_text(encoding="utf-8")
frag = Fragment(str(html_str).format(block=self))

# Load the CSS and JavaScript fragments from within the package
css_str = pkg_resources.resource_string(__name__,
"static/css/thumbs.css").decode('utf-8')
css_str = importlib.resources.files(__package__).joinpath("static/css/thumbs.css").read_text(encoding="utf-8")
frag.add_css(str(css_str))

js_str = pkg_resources.resource_string(__name__,
"static/js/src/thumbs.js").decode('utf-8')
js_str = importlib.resources.files(__package__).joinpath("static/js/src/thumbs.js").read_text(encoding="utf-8")
frag.add_javascript(str(js_str))

frag.initialize_js('ThumbsBlock')
Expand Down
2 changes: 1 addition & 1 deletion workbench/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Provide a djangoapp for XBlock development
"""

__version__ = '0.11.0'
__version__ = '0.12.0'

0 comments on commit 088065b

Please sign in to comment.