Spaces:
Sleeping
Sleeping
Commit ·
7bd6a0c
1
Parent(s): ebf8aa8
WTF is pyc
Browse files
app.py
CHANGED
|
@@ -175,17 +175,23 @@ def evaluate_submission(file_obj, debug=False):
|
|
| 175 |
|
| 176 |
# Import with a unique module name each time
|
| 177 |
module_name = f"student_module_{int(time.time() * 1000000)}"
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
|
|
|
| 181 |
|
| 182 |
try:
|
|
|
|
|
|
|
|
|
|
| 183 |
spec.loader.exec_module(student_module)
|
| 184 |
except Exception as e:
|
| 185 |
print(f"ERROR during module exec: {type(e).__name__}: {str(e)}")
|
| 186 |
import traceback
|
| 187 |
traceback.print_exc()
|
| 188 |
raise
|
|
|
|
|
|
|
| 189 |
|
| 190 |
report = [f"## Results:\n"]
|
| 191 |
|
|
|
|
| 175 |
|
| 176 |
# Import with a unique module name each time
|
| 177 |
module_name = f"student_module_{int(time.time() * 1000000)}"
|
| 178 |
+
|
| 179 |
+
# Disable bytecode writing to prevent permission issues on temp directories
|
| 180 |
+
old_dont_write_bytecode = sys.dont_write_bytecode
|
| 181 |
+
sys.dont_write_bytecode = True
|
| 182 |
|
| 183 |
try:
|
| 184 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 185 |
+
student_module = importlib.util.module_from_spec(spec)
|
| 186 |
+
sys.modules[module_name] = student_module
|
| 187 |
spec.loader.exec_module(student_module)
|
| 188 |
except Exception as e:
|
| 189 |
print(f"ERROR during module exec: {type(e).__name__}: {str(e)}")
|
| 190 |
import traceback
|
| 191 |
traceback.print_exc()
|
| 192 |
raise
|
| 193 |
+
finally:
|
| 194 |
+
sys.dont_write_bytecode = old_dont_write_bytecode
|
| 195 |
|
| 196 |
report = [f"## Results:\n"]
|
| 197 |
|