Skip to content

Commit 0b13dfc

Browse files
committed
#26968: workaround for an ecl race in maxima init
When maxima is initialized a bug in ecl implementation of `ensure-directories-exist` might result in a runtime error. As a workaround, in case we get a runtime error we use python to create the directory and then continue with maxima initialization. Note that for normal usage the directory will already exist within the user's `DOT_SAGE` so this code will almost never run. However, when running doctests on CI this occasionally triggers.
1 parent d2cc160 commit 0b13dfc

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/sage/interfaces/maxima_lib.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,23 @@
136136
ecl_eval("(setq $nolabels t))")
137137
ecl_eval("(defvar *MAXIMA-LANG-SUBDIR* NIL)")
138138
ecl_eval("(set-locale-subdir)")
139-
ecl_eval("(set-pathnames)")
139+
140+
try:
141+
ecl_eval("(set-pathnames)")
142+
except RuntimeError:
143+
# Recover from :trac:`26968` by creating `*maxima-objdir*` here.
144+
# This cannot be done before calling `(set-pathnames)` since
145+
# `*maxima-objdir*` is computed there.
146+
# We use python `os.makedirs()` which is immune to the race.
147+
# Using `(ensure-directories-exist ...)` in lisp would be
148+
# subject to the same race condition and since `*maxima-objdir*`
149+
# has multiple components this is quite plausible to happen.
150+
maxima_objdir = ecl_eval("*maxima-objdir*").python()[1:-1]
151+
import os
152+
os.makedirs(maxima_objdir, exist_ok=True)
153+
# Call `(set-pathnames)` again to complete its job.
154+
ecl_eval("(set-pathnames)")
155+
140156
ecl_eval("(defun add-lineinfo (x) x)")
141157
ecl_eval('(defun principal nil (cond ($noprincipal (diverg)) ((not pcprntd) (merror "Divergent Integral"))))')
142158
ecl_eval("(remprop 'mfactorial 'grind)") # don't use ! for factorials (#11539)

0 commit comments

Comments
 (0)