Skip to content

Commit 1303965

Browse files
authored
feat: Also set MPLCONFIGDIR to make matplotlib complain less (#36456)
Example output from running `import matplotlib; 1/0`, before and after the change: ```diff --- tmp/before 2025-03-28 03:34:06.633689552 +0000 +++ tmp/after 2025-03-28 03:34:37.268688891 +0000 @@ -1,6 +1,5 @@ -Matplotlib created a temporary cache directory at /tmp/codejail-hveq16ah/tmp/matplotlib-tv0c_vzt because the default path (/home/sandbox/.config/matplotlib) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing. Traceback (most recent call last): File "jailed_code", line 19, in <module> exec(code, g_dict) File "<string>", line 1, in <module> ZeroDivisionError: division by zero ```
1 parent f32b08b commit 1303965

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

xmodule/capa/safe_exec/safe_exec.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@
3131
# the ./tmp directory that codejail creates in each sandbox, rather than trying
3232
# to use a global temp dir (which should be blocked by AppArmor anyhow).
3333
# This is needed for matplotlib among other things.
34+
#
35+
# matplotlib will complain on stderr about the non-standard temp dir if we
36+
# don't explicitly tell it "no really, use this". This pollutes the output
37+
# when codejail returns an error message (which includes stderr). So we also
38+
# set MPLCONFIGDIR as a special case.
3439
os.environ["TMPDIR"] = os.getcwd() + "/tmp"
40+
os.environ["MPLCONFIGDIR"] = os.environ["TMPDIR"]
3541
3642
import random2 as random_module
3743
import sys

0 commit comments

Comments
 (0)