Skip to content

Commit

Permalink
update xqueue_watcher.jailedgrader to comply with Python 3.12's remov…
Browse files Browse the repository at this point in the history
…al of `imp` standard library module
  • Loading branch information
TheVinhLuong102 committed Nov 8, 2023
1 parent 180d120 commit 6c850f5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions xqueue_watcher/jailedgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import codecs
import os
import sys
import imp
import importlib.util
import importlib.machinery
import json
import random
import gettext
Expand All @@ -21,6 +22,19 @@

TIMEOUT = 1


# Python 3.12: `imp` module removed: docs.python.org/3/whatsnew/3.12.html#imp
def load_source(modname, filename):
loader = importlib.machinery.SourceFileLoader(modname, filename)
spec = importlib.util.spec_from_file_location(modname, filename, loader=loader)
module = importlib.util.module_from_spec(spec)
# The module is always executed and not cached in sys.modules.
# Uncomment the following line to cache the module.
# sys.modules[module.__name__] = module
loader.exec_module(module)
return module


def path_to_six():
"""
Return the full path to six.py
Expand Down Expand Up @@ -122,7 +136,7 @@ def grade(self, grader_path, grader_config, submission):
# Import the grader, straight from the original file. (It probably isn't in
# sys.path, and we may be in a long running gunicorn process, so we don't
# want to add stuff to sys.path either.)
grader_module = imp.load_source("grader_module", str(grader_path))
grader_module = load_source("grader_module", str(grader_path))
grader = grader_module.grader

# Preprocess for grader-specified errors
Expand Down

0 comments on commit 6c850f5

Please sign in to comment.