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.
  • Loading branch information
regisb committed Feb 12, 2024
1 parent 0190a08 commit 62c4f79
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 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)
8 changes: 4 additions & 4 deletions tutorecommerce/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
from tutormfe.hooks import MFE_APPS, MFE_ATTRS_TYPE
Expand Down Expand Up @@ -88,7 +88,7 @@ def _add_ecommerce_mfe_apps(
for service in ("mysql", "lms", "ecommerce"):
with open(
os.path.join(
pkg_resources.resource_filename("tutorecommerce", "templates"),
str(importlib_resources.files("tutorecommerce") / "templates"),
"ecommerce",
"tasks",
service,
Expand Down Expand Up @@ -156,7 +156,7 @@ def _add_ecommerce_mfe_apps(
####### Boilerplate code
# Add the "templates" folder as a template root
tutor_hooks.Filters.ENV_TEMPLATE_ROOTS.add_item(
pkg_resources.resource_filename("tutorecommerce", "templates")
str(importlib_resources.files("tutorecommerce") / "templates")
)
# Render the "build" and "apps" folders
tutor_hooks.Filters.ENV_TEMPLATE_TARGETS.add_items(
Expand All @@ -168,7 +168,7 @@ def _add_ecommerce_mfe_apps(
# Load patches from files
for path in glob(
os.path.join(
pkg_resources.resource_filename("tutorecommerce", "patches"),
str(importlib_resources.files("tutorecommerce") / "patches"),
"*",
)
):
Expand Down

0 comments on commit 62c4f79

Please sign in to comment.