sage.env: _add_variable_or_fallback depends on the order of a dict
jhpalmieri opened this issue · 23 comments
In sage/env.py, the function _add_variable_or_fallback does some variable substitution: if a string contains $VAR, it substitutes the value of VAR in the dictionary SAGE_ENV. It does this by iterating through the items of SAGE_ENV, which means that if both VAR and VAR_OTHER are in SAGE_ENV, it's sort of a coin toss as to what happens when it comes across $VAR_OTHER.
(This arose when I was working on #21469: the string $SAGE_SRC_ROOT was being replaced by the value of SAGE_SRC, followed by the string _ROOT.)
CC: @mkoeppe
Component: build
Author: John Palmieri
Branch: 343d685
Reviewer: Matthias Koeppe
Issue created by migration from https://trac.sagemath.org/ticket/23758
New commits:
60927e5 | trac 23758: in env.py, _add_variable_or_fallback should depend less |
Commit: 60927e5
Branch pushed to git repo; I updated commit sha1. New commits:
c23cc1c | trac 23758: restore "import os" |
I don't know, maybe we can just get rid of this whole variable substitution business, by using the Python variable SAGE_ROOT instead of "$SAGE_ROOT"?
(Could be a follow-up ticket.)
Perhaps add a doctest?
Branch pushed to git repo; I updated commit sha1. New commits:
343d685 | trac 23758: add a doctest |
Here is a doctest. The same test fails for me in the develop branch, but I suppose that failure may not be repeatable on all platforms, since dictionaries are not ordered.
Replying to @mkoeppe:
I don't know, maybe we can just get rid of this whole variable substitution business, by using the Python variable
SAGE_ROOTinstead of"$SAGE_ROOT"?
I agree, a followup ticket if we want to address this. I'm not sure what the point of the substitution is, compared to using shell variables or some shortcut for accessing SAGE_ENV['foo'].
Author: John H. Palmieri
Reviewer: Matthias Koeppe
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
Sorry, I accidentally pushed a branch here instead of to the appropriate ticket. The positively reviewed branch has been restored.
Changed branch from u/jhpalmieri/variable_replacement to 343d685
Changed author from John H. Palmieri to John Palmieri