From 392de8d40e1055dccd22428f6ccac593d9c98178 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Wed, 22 May 2013 13:27:24 -0400 Subject: [PATCH] Check functions need access to course-local code also, so we need to save the python path from the problem setup, and use it for the check function. --- common/lib/capa/capa/capa_problem.py | 5 ++--- common/lib/capa/capa/responsetypes.py | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index 7ead599d67..8543e9e3e1 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -475,12 +475,11 @@ class LoncapaProblem(object): msg = "Error while executing script code: %s" % str(err).replace('<', '<') raise responsetypes.LoncapaProblemError(msg) - # store code source in context + # Store code source in context, along with the Python path needed to run it correctly. context['script_code'] = all_code + context['python_path'] = python_path return context - - def _extract_html(self, problemtree): # private ''' Main (private) function which converts Problem XML tree to HTML. diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index c7a99f1271..a166438f17 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -286,7 +286,7 @@ class LoncapaResponse(object): } try: - safe_exec.safe_exec(code, globals_dict) + safe_exec.safe_exec(code, globals_dict, python_path=self.context['python_path']) except Exception as err: msg = 'Error %s in evaluating hint function %s' % (err, hintfn) msg += "\nSee XML source line %s" % getattr( @@ -972,7 +972,7 @@ class CustomResponse(LoncapaResponse): 'ans': ans, } globals_dict.update(kwargs) - safe_exec.safe_exec(code, globals_dict, cache=self.system.cache) + safe_exec.safe_exec(code, globals_dict, python_path=self.context['python_path']) return globals_dict['cfn_return'] return check_function