Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 4d20b92

Browse files
author
Matthias Koeppe
committed
sage.env: Check environment variable after sage_conf value, not before
1 parent 2818890 commit 4d20b92

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/sage/env.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,15 @@ def var(key: str, *fallbacks: Optional[str], force: bool = False) -> Optional[st
6565
"""
6666
Set ``SAGE_ENV[key]`` and return the value.
6767
68-
If ``key`` is an environment variable, this is the value.
69-
Otherwise, if it is defined in ``sage_conf``, take it from there.
68+
First try to get the value from ``sage_conf``.
69+
70+
Next, unless ``force=True``, if an environment variable is defined,
71+
get the value from there.
72+
7073
Otherwise, the ``fallbacks`` are tried until one is found which
71-
is not ``None``. If the environment variable is not set and all
74+
is not ``None``.
75+
76+
If the environment variable is not set and all
7277
fallbacks are ``None``, then the final value is ``None``.
7378
7479
INPUT:
@@ -136,16 +141,13 @@ def var(key: str, *fallbacks: Optional[str], force: bool = False) -> Optional[st
136141
sage: sage.env.SAGE_FOO
137142
'foo'
138143
"""
139-
if force:
144+
try:
145+
import sage_conf
146+
value = getattr(sage_conf, key, None)
147+
except ImportError:
140148
value = None
141-
else:
149+
if value is None and not force:
142150
value = os.environ.get(key)
143-
if value is None:
144-
try:
145-
import sage_conf
146-
value = getattr(sage_conf, key, None)
147-
except ImportError:
148-
pass
149151
# Try all fallbacks in order as long as we don't have a value
150152
for f in fallbacks:
151153
if value is not None:

0 commit comments

Comments
 (0)