From b8f6ad8c9c0110931fb90f38529008e354fd1b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Tue, 6 Feb 2024 11:41:23 +0100 Subject: [PATCH] fix: remove pkg_resources for compatibility with python 3.12 pkg_resources is a package that is unavailable in python 3.12, unless setuptools is explicitely installed. Turns out, there are replacement functions coming from importlib_resources, which can be obtained from the importlib-resources pypi package. This package will be installed with tutor starting from 17.0.2. --- changelog.d/20240212_115536_regis_pkg_resources.md | 1 + tutordiscovery/plugin.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 changelog.d/20240212_115536_regis_pkg_resources.md diff --git a/changelog.d/20240212_115536_regis_pkg_resources.md b/changelog.d/20240212_115536_regis_pkg_resources.md new file mode 100644 index 0000000..35b6d20 --- /dev/null +++ b/changelog.d/20240212_115536_regis_pkg_resources.md @@ -0,0 +1 @@ +- [Bugfix] Make plugin compatible with Python 3.12 by removing dependency on `pkg_resources`. (by @regisb) diff --git a/tutordiscovery/plugin.py b/tutordiscovery/plugin.py index a889c12..5fcdc22 100644 --- a/tutordiscovery/plugin.py +++ b/tutordiscovery/plugin.py @@ -4,7 +4,7 @@ import typing as t from glob import glob -import pkg_resources +import importlib_resources from tutor import hooks as tutor_hooks from tutor.__about__ import __version_suffix__ @@ -50,7 +50,7 @@ for service in init_tasks: with open( os.path.join( - pkg_resources.resource_filename("tutordiscovery", "templates"), + str(importlib_resources.files("tutordiscovery") / "templates"), "discovery", "tasks", service, @@ -112,7 +112,7 @@ def _mount_course_discovery_on_build( # Add the "templates" folder as a template root tutor_hooks.Filters.ENV_TEMPLATE_ROOTS.add_item( - pkg_resources.resource_filename("tutordiscovery", "templates") + str(importlib_resources.files("tutordiscovery") / "templates") ) # Render the "build" and "apps" folders tutor_hooks.Filters.ENV_TEMPLATE_TARGETS.add_items( @@ -124,7 +124,7 @@ def _mount_course_discovery_on_build( # Load patches from files for path in glob( os.path.join( - pkg_resources.resource_filename("tutordiscovery", "patches"), + str(importlib_resources.files("tutordiscovery") / "patches"), "*", ) ):