diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5fd6947..2639099 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,17 @@ Unreleased * +[2.0.1] - 2025-02-05 +********************************************** + +Changed +======= + +* **Replaced `pkg_resources` with `importlib.resources`** + - `pkg_resources` (from `setuptools`) is deprecated and may be removed in future Python versions. + - Now using `importlib.resources`, the recommended alternative for managing package resources. + - This improves performance and ensures better compatibility with modern Python versions. + [2.0.0] - 2025-01-23 ********************************************** diff --git a/flow_control/__init__.py b/flow_control/__init__.py index 84119fa..965b31a 100644 --- a/flow_control/__init__.py +++ b/flow_control/__init__.py @@ -2,4 +2,4 @@ Init for main Flow-Control XBlock """ from .flow import FlowCheckPointXblock -__version__ = '2.0.0' +__version__ = '2.0.1' diff --git a/flow_control/flow.py b/flow_control/flow.py index 4162f46..4cb71b6 100644 --- a/flow_control/flow.py +++ b/flow_control/flow.py @@ -2,7 +2,7 @@ either display the unit's content or take an alternative action """ import logging -import pkg_resources +from importlib.resources import files as importlib_files import re from functools import reduce @@ -24,8 +24,7 @@ def load(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 _actions_generator(block): # pylint: disable=unused-argument diff --git a/flow_control/tests/test_flowcontrol.py b/flow_control/tests/test_flowcontrol.py index 74cc773..effbd03 100644 --- a/flow_control/tests/test_flowcontrol.py +++ b/flow_control/tests/test_flowcontrol.py @@ -5,7 +5,7 @@ import ddt import unittest -from mock import MagicMock, patch +from mock import MagicMock, patch, mock_open # from xblock.core import XBlock from xblock.field_data import DictFieldData from flow_control.flow import FlowCheckPointXblock @@ -85,13 +85,13 @@ def test_operators_generator(self): self.assertEqual(operators, operators_allowed) def test_load(self): - """ - It should return the corresponding resource - """ - path_mock = MagicMock() - with patch('pkg_resources.resource_string') as my_patch: - load(path_mock) - my_patch.assert_called_once_with('flow_control.flow', path_mock) + """It should return the corresponding resource""" + path_mock = "test_resource.txt" + mock_content = "mocked content" + + with patch("pathlib.Path.open", mock_open(read_data=mock_content)): + result = load(path_mock) + self.assertEqual(result, mock_content) @ddt.data( 'course-v1:Course+course+course', diff --git a/setup.cfg b/setup.cfg index 592dcb8..4473f95 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.0.0 +current_version = 2.0.1 commit = True tag = True