Skip to content

Commit

Permalink
fix: Switch from imp to importlib.
Browse files Browse the repository at this point in the history
The import in `grader.py` was just not being used so I dropped it.  In
jailedgrader.py I replaced the implementation with the sourcefile loader
from importlib which is still around.  The `imp` module is deprecated
and was removed in Python 3.12

With these changes the code is compatible with Python 3.8 and 3.12.
  • Loading branch information
feanil committed Mar 29, 2024
1 parent 243bc9c commit dc93288
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
matrix:
os:
- ubuntu-20.04
python-version: ['3.8', '3.11']
python-version: ['3.8', '3.11', '3.12']
steps:
- uses: actions/checkout@v2
- name: setup python
Expand Down
1 change: 0 additions & 1 deletion xqueue_watcher/grader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Implementation of a grader compatible with XServer
"""
import html
import imp
import sys
import time
import json
Expand Down
5 changes: 3 additions & 2 deletions xqueue_watcher/jailedgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import codecs
import os
import sys
import imp
import importlib
import json
import random
import gettext
Expand Down Expand Up @@ -122,7 +122,8 @@ 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))
sf_loader = importlib.machinery.SourceFileLoader("grader_module", str(grader_path))
grader_module = sf_loader.load_module()
grader = grader_module.grader

# Preprocess for grader-specified errors
Expand Down

0 comments on commit dc93288

Please sign in to comment.