Skip to content

Commit

Permalink
fix: remove pkg_resources for python3.12 support
Browse files Browse the repository at this point in the history
  • Loading branch information
MaferMazu committed Apr 30, 2024
1 parent 8eccae4 commit cc9582e
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions tutorcodejail/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from glob import glob

import pkg_resources
import importlib_resources
from tutor import hooks

from .__about__ import __version__
Expand Down Expand Up @@ -48,8 +48,9 @@
# and add it to the CLI_DO_INIT_TASKS filter, which tells Tutor to
# run it as part of the `init` job.
for service, template_path, priority in MY_INIT_TASKS:
full_path: str = pkg_resources.resource_filename(
"tutorcodejail", os.path.join("templates", *template_path)
full_path: str = str(
importlib_resources.files("tutorcodejail")
/ os.path.join("templates", *template_path)
)
with open(full_path, encoding="utf-8") as init_task_file:
init_task: str = init_task_file.read()
Expand Down Expand Up @@ -99,7 +100,7 @@
# Boilerplate code
# Add the "templates" folder as a template root
hooks.Filters.ENV_TEMPLATE_ROOTS.add_item(
pkg_resources.resource_filename("tutorcodejail", "templates")
str(importlib_resources.files("tutorcodejail") / "templates")
)
# Render the "build" and "apps" folders
hooks.Filters.ENV_TEMPLATE_TARGETS.add_items(
Expand All @@ -110,12 +111,7 @@
],
)
# Load patches from files
for path in glob(
os.path.join(
pkg_resources.resource_filename("tutorcodejail", "patches"),
"*",
)
):
for path in glob(str(importlib_resources.files("tutorcodejail") / "patches" / "*")):
with open(path, encoding="utf-8") as patch_file:
hooks.Filters.ENV_PATCHES.add_item((os.path.basename(path), patch_file.read()))
# Add configuration entries
Expand Down

0 comments on commit cc9582e

Please sign in to comment.