Sorry about the dead links. The
ucquestiontypes repo is mostly for in-house use, and for convenience I had packaged all the support files for our
python3_stage1 question type into
Files.zip rather than manage them all separately. I hadn't realised there were links to the individual files. I've now unzipped and you'll see the
__pytask.py file there now. I doubt it's quite what you want, though, as it's specific to our own very complex in-house question type.
I thought my blog was so old that no-one would want it any more, so I had hidden it. I just unhid it. It might be a bit more useful to you than
__pytask, though it doesn't include the specific lines of code you're trying to insert.
The short answer to your question is that you just need to insert those lines into the Python program that you're about to run, i.e. before the student answer. For example, if you're using the standard python3 question type, and you click the Customise checkbox, you'll see the template:
{{ STUDENT_ANSWER }}
__student_answer__ = """{{ STUDENT_ANSWER | e('py') }}"""
SEPARATOR = "##"
{% for TEST in TESTCASES %}
{{ TEST.testcode }}
{% if not loop.last %}
print(SEPARATOR)
{% endif %}
{% endfor %}
@17943918#@>
So you can insert the extra code to set the matplotlib environment at the very beginning of that template.
A downside of this, which our much more complex question types avoid one way or another, is that the error messages the students see will all be wrong (in the students' eyes) because of the extra hidden code at the start.
A much better fix would be to modify the runguard environment in Jobe to add the appropriate environment variable when running Python if the string matplotlib is present anywhere in the source code. That way you wouldn't have to do anything to the Python source code at all. I just haven't got around to doing that yet.