Skip to content

Commit 6547ad5

Browse files
committed
sage.features.databases: implement data search path
Search path at sage.env.SAGE_DATA_PATH with a good default. Function `sage_data_path(data_name)` creates search path for a database named `data_name`.
1 parent 681a8e4 commit 6547ad5

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/sage/env.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ def var(key: str, *fallbacks: Optional[str], force: bool = False) -> Optional[st
195195
SAGE_ARCHFLAGS = var("SAGE_ARCHFLAGS", "unset")
196196
SAGE_PKG_CONFIG_PATH = var("SAGE_PKG_CONFIG_PATH")
197197

198+
# colon-separated search path for databases.
199+
SAGE_DATA_PATH = var("SAGE_DATA_PATH",
200+
os.pathsep.join(filter(None, [
201+
join(DOT_SAGE, "db"),
202+
join(SAGE_SHARE, "sagemath"),
203+
SAGE_SHARE,
204+
])))
205+
198206
# installation directories for various packages
199207
GRAPHS_DATA_DIR = var("GRAPHS_DATA_DIR", join(SAGE_SHARE, "graphs"))
200208
ELLCURVE_DATA_DIR = var("ELLCURVE_DATA_DIR", join(SAGE_SHARE, "ellcurves"))

src/sage/features/databases.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,27 @@
1616
# https://www.gnu.org/licenses/
1717
# *****************************************************************************
1818

19+
import os
1920

2021
from . import StaticFile, PythonModule
22+
from sage.env import SAGE_DATA_PATH
23+
24+
25+
def sage_data_path(data_name):
26+
r"""
27+
Search path for database `data_name`.
28+
29+
EXAMPLES::
30+
31+
sage: from sage.features.databases import sage_data_path
32+
sage: sage_data_path("cremona")
33+
['.../cremona']
34+
"""
35+
if not SAGE_DATA_PATH:
36+
return []
37+
38+
return [os.path.join(p, data_name)
39+
for p in SAGE_DATA_PATH.split(os.pathsep)]
2140

2241

2342
class DatabaseCremona(StaticFile):

0 commit comments

Comments
 (0)