From b0bb05efe989e19cb9f3c1a5cbb74e26fd195644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Tue, 21 Feb 2023 17:03:08 -0300 Subject: [PATCH] #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 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. --- src/sage/interfaces/maxima_lib.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/sage/interfaces/maxima_lib.py b/src/sage/interfaces/maxima_lib.py index 621419d76a3..83f8c9d3400 100644 --- a/src/sage/interfaces/maxima_lib.py +++ b/src/sage/interfaces/maxima_lib.py @@ -135,7 +135,19 @@ ecl_eval("(setq $nolabels t))") ecl_eval("(defvar *MAXIMA-LANG-SUBDIR* NIL)") ecl_eval("(set-locale-subdir)") -ecl_eval("(set-pathnames)") + +try: + ecl_eval("(set-pathnames)") +except RuntimeError: + # Recover from :trac:`26968` by creating `*maxima-objdir*` here. + # This cannot be done before calling `(set-pathnames)` since + # `*maxima-objdir*` is computed there. + maxima_objdir = ecl_eval("*maxima-objdir*").python()[1:-1] + import os + os.makedirs(maxima_objdir, exist_ok=True) + # Call `(set-pathnames)` again to complete its job. + ecl_eval("(set-pathnames)") + ecl_eval("(defun add-lineinfo (x) x)") ecl_eval('(defun principal nil (cond ($noprincipal (diverg)) ((not pcprntd) (merror "Divergent Integral"))))') ecl_eval("(remprop 'mfactorial 'grind)") # don't use ! for factorials (#11539)