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.
This commit is contained in:
Régis Behmo 2024-02-06 11:41:23 +01:00
parent 22e67e757c
commit 97600a5350
2 changed files with 4 additions and 5 deletions

View File

@ -0,0 +1 @@
- [Bugfix] Make plugin compatible with Python 3.12 by removing dependency on `pkg_resources`. (by @regisb)

View File

@ -6,7 +6,7 @@ import typing as t
from glob import glob
import click
import pkg_resources
import importlib_resources
from tutor import hooks
from tutor.__about__ import __version_suffix__
@ -188,7 +188,7 @@ hooks.Filters.CLI_DO_COMMANDS.add_item(create_user_command)
####### Boilerplate code
# Add the "templates" folder as a template root
hooks.Filters.ENV_TEMPLATE_ROOTS.add_item(
pkg_resources.resource_filename("tutorcairn", "templates")
str(importlib_resources.files("tutorcairn") / "templates")
)
# Render the "build" and "apps" folders
hooks.Filters.ENV_TEMPLATE_TARGETS.add_items(
@ -198,8 +198,6 @@ hooks.Filters.ENV_TEMPLATE_TARGETS.add_items(
],
)
# Load patches from files
for path in glob(
os.path.join(pkg_resources.resource_filename("tutorcairn", "patches"), "*")
):
for path in glob(str(importlib_resources.files("tutorcairn") / "patches" / "*")):
with open(path, encoding="utf-8") as patch_file:
hooks.Filters.ENV_PATCHES.add_item((os.path.basename(path), patch_file.read()))