diff --git a/converting.md b/converting.md index 873217d..c074de9 100644 --- a/converting.md +++ b/converting.md @@ -44,9 +44,6 @@ those submissions when they're regraded. Read every file in the question, including `info.json`, `question.html`, `server.py` and everything in `tests/`. Stop and report back instead of converting if the question needs one of these: -- **Course libraries.** `externalGradingOptions.serverFilesCourse` or imports of course-wide - modules. The legacy grader put `/grade/serverFilesCourse` on the import path, and this grader - doesn't. - **A custom grader image** or an `entrypoint` in `externalGradingOptions`. - **Values the sandbox can't send back.** Tests can only receive values that can be serialized: numbers, strings, `None`, lists, dicts, numpy arrays and scalars, pandas DataFrames and matplotlib @@ -368,6 +365,9 @@ These differences from the legacy grader are easy to miss: - **Default import blacklist.** `os`, `sys`, `subprocess`, `pathlib` and `shutil` are blocked unless you set `import_blacklist`. - **Syntax errors** make the submission ungradable instead of scoring 0. +- **Course libraries** from `externalGradingOptions.serverFilesCourse` are still on the import path. + If you set `import_whitelist`, list them in it. See + [Course Modules](quick_start.md#course-modules). ## 7. Test the conversion diff --git a/quick_start.md b/quick_start.md index f0270ea..8964242 100644 --- a/quick_start.md +++ b/quick_start.md @@ -1008,6 +1008,29 @@ import helper_function as hf > setting also doesn't make the rest of the tests folder private. `importlib` isn't blacklisted by > default, so student code can load files in that folder by path. +#### Course Modules + +To share a module between questions, put it in the course's `serverFilesCourse` folder and list it +in the question's `info.json`: + +```json +"externalGradingOptions": { + "image": "prairielearn/grader-python-pytest:latest", + "serverFilesCourse": ["course_lib.py"] +} +``` + +PrairieLearn copies it to `/grade/serverFilesCourse`, which the grader images put on the import +path, as the legacy grader did. Tests, setup code and student code can then `import course_lib`. + +- **Import restrictions:** if you set `import_whitelist`, list the module in it so that setup code + and student code can import it. Tests aren't restricted. +- **Ordinary modules:** unlike [helper modules](#helper-modules), these load like any installed + library, without the sandbox's restricted builtins. +- **Testing locally:** add the folder to `PYTHONPATH` when you run pytest. + +> **Warning:** Student code can import these modules too, so they must not contain answers. + #### Data Files In a workspace, code such as `np.loadtxt("pagerank_large.txt")` reads a file next to the notebook. To