Skip to content

Commit

Permalink
fix: remove pkg_resources for compatibility with python 3.12
Browse files Browse the repository at this point in the history
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.
regisb committed Mar 6, 2024
1 parent 0464c0c commit 50eb9d8
Showing 2 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions changelog.d/20240212_115536_regis_pkg_resources.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- [Bugfix] Make plugin compatible with Python 3.12 by removing dependency on `pkg_resources`. (by @regisb)
26 changes: 12 additions & 14 deletions tutormfe/plugin.py
Original file line number Diff line number Diff line change
@@ -5,10 +5,10 @@
import typing as t
from glob import glob

import pkg_resources
import importlib_resources
from tutor import fmt
from tutor.__about__ import __version_suffix__
from tutor import hooks as tutor_hooks
from tutor.__about__ import __version_suffix__
from tutor.hooks import priorities
from tutor.types import Config, get_typed

@@ -168,11 +168,14 @@ def _mounted_mfe_image_management() -> None:
# init script
with open(
os.path.join(
pkg_resources.resource_filename("tutormfe", "templates"),
"mfe",
"tasks",
"lms",
"init",
str(
importlib_resources.files("tutormfe")
/ "templates"
/ "mfe"
/ "tasks"
/ "lms"
/ "init"
)
),
encoding="utf-8",
) as task_file:
@@ -248,7 +251,7 @@ def _build_3rd_party_dev_mfes_on_launch(
# Boilerplate code
# Add the "templates" folder as a template root
tutor_hooks.Filters.ENV_TEMPLATE_ROOTS.add_item(
pkg_resources.resource_filename("tutormfe", "templates")
str(importlib_resources.files("tutormfe") / "templates")
)
# Render the "build" and "apps" folders
tutor_hooks.Filters.ENV_TEMPLATE_TARGETS.add_items(
@@ -258,12 +261,7 @@ def _build_3rd_party_dev_mfes_on_launch(
],
)
# Load patches from files
for path in glob(
os.path.join(
pkg_resources.resource_filename("tutormfe", "patches"),
"*",
)
):
for path in glob(str(importlib_resources.files("tutormfe") / "patches" / "*")):
with open(path, encoding="utf-8") as patch_file:
# Here we force tutor-mfe lms patches to be loaded first, thus ensuring when operators override
# MFE_CONFIG and/or MFE_CONFIG_OVERRIDES, their patches will be loaded after this plugin's

0 comments on commit 50eb9d8

Please sign in to comment.