Skip to content

Commit 322c945

Browse files
committed
Replace all uses of SAGE_SHARE in sagelib
1 parent 0752a38 commit 322c945

File tree

13 files changed

+79
-61
lines changed

13 files changed

+79
-61
lines changed

src/sage/combinat/cluster_algebra_quiver/mutation_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,12 +1268,12 @@ def load_data(n: int, user=True) -> dict:
12681268
('BKO', (((1, 0), (3, -1)), ((2, 1), (1, -3)))),
12691269
('BP_', (((0, 1), (2, -2)), ((1, 2), (1, -3)), ((2, 0), (3, -1))))])]
12701270
"""
1271-
from sage.env import DOT_SAGE, SAGE_SHARE
1271+
from sage.env import DOT_SAGE, sage_data_paths
12721272

12731273
# we check
12741274
# - if the data is stored by the user, and if this is not the case
12751275
# - if the data is stored by the optional package install
1276-
paths = [Path(SAGE_SHARE)]
1276+
paths = list(sage_data_paths())
12771277
if user:
12781278
paths.append(Path(DOT_SAGE))
12791279
data = {}

src/sage/databases/cremona.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
This causes the latest version of the database to be downloaded from
2121
the internet.
2222
23-
Both the mini and full versions of John Cremona's tables are stored in
24-
SAGE_SHARE/cremona as SQLite databases. The mini version has the layout::
23+
Both the mini and full versions of John Cremona's tables are stored
24+
as SQLite databases. The mini version has the layout::
2525
2626
CREATE TABLE t_class(conductor INTEGER, class TEXT PRIMARY KEY, rank INTEGER);
2727
CREATE TABLE t_curve(class TEXT, curve TEXT PRIMARY KEY, eqn TEXT UNIQUE, tors INTEGER);
@@ -115,8 +115,8 @@ def build(name, data_tgz, largest_conductor=0, mini=False, decompress=True):
115115
116116
sage: d = sage.databases.cremona.build('cremona','ecdata.tgz') # not tested
117117
"""
118-
from sage.env import SAGE_SHARE
119-
db_path = os.path.join(SAGE_SHARE,'cremona',name.replace(' ','_')+'.db')
118+
from sage.env import DOT_SAGE
119+
db_path = os.path.join(DOT_SAGE, 'db', 'cremona', name.replace(' ','_')+'.db')
120120
if os.path.exists(db_path):
121121
raise RuntimeError('Please (re)move %s before building ' % db_path
122122
+ 'database')

src/sage/databases/cunningham_tables.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from sage.misc.cachefunc import cached_function
2020
from sage.rings.integer import Integer
2121
from sage.misc.persist import load
22-
from sage.env import SAGE_SHARE
22+
from sage.env import sage_data_paths
2323

2424

2525
@cached_function
@@ -43,11 +43,11 @@ def cunningham_prime_factors():
4343
17,
4444
...
4545
"""
46-
file = os.path.join(SAGE_SHARE,'cunningham_tables','cunningham_prime_factors.sobj')
47-
if os.path.exists(file):
48-
return [Integer(_) for _ in load(file)]
49-
else:
50-
from warnings import warn
51-
warn("You might consider installing the optional package for factoring Cunningham numbers"
52-
" with the following command: ``sage -i cunningham_tables``")
53-
return []
46+
for path in sage_data_paths('cunningham_tables'):
47+
file = os.path.join(path, 'cunningham_prime_factors.sobj')
48+
if os.path.exists(file):
49+
return [Integer(_) for _ in load(file)]
50+
51+
from warnings import warn
52+
warn("The optional cunningham_tables package for factoring Cunningham numbers is not installed")
53+
return []

src/sage/databases/db_modular_polynomials.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ def _dbz_to_string(name) -> str:
5252
sage: _dbz_to_string('PolHeeg/Cls/0000001-0005000/pol.0000003.dbz')
5353
'0\n1\n'
5454
"""
55-
from sage.env import SAGE_SHARE
56-
filename = Path(SAGE_SHARE) / 'kohel' / name
57-
try:
58-
with open(filename, 'rb') as f:
59-
data = bz2.decompress(f.read())
60-
except OSError:
61-
raise FileNotFoundError('file not found in the Kohel database')
62-
return data.decode()
55+
from sage.env import sage_data_paths
56+
for path in sage_data_paths('kohel'):
57+
filename = Path(path) / name
58+
if os.path.exists(filename):
59+
with open(filename, 'rb') as f:
60+
data = bz2.decompress(f.read())
61+
return data.decode()
62+
raise FileNotFoundError('file not found in the Kohel database')
6363

6464

6565
def _dbz_to_integer_list(name) -> list[list]:

src/sage/databases/jones.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
from sage.rings.rational_field import RationalField
7474
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
7575
from sage.combinat.subset import powerset
76-
from sage.env import SAGE_SHARE
7776

7877
from sage.misc.persist import load, save
7978

src/sage/databases/odlyzko.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import os
3030

3131
from sage.misc.persist import load
32-
from sage.env import SAGE_SHARE
32+
from sage.env import sage_data_paths
3333

3434

3535
def zeta_zeros():
@@ -54,6 +54,9 @@ def zeta_zeros():
5454
2001052
5555
"""
5656
from sage.misc.verbose import verbose
57-
sobj = os.path.join(SAGE_SHARE, 'odlyzko', 'zeros.sobj')
58-
verbose("Loading Odlyzko database from " + sobj)
59-
return load(sobj)
57+
for path in sage_data_paths('odlyzko'):
58+
sobj = os.path.join(path, 'zeros.sobj')
59+
if os.path.exists(sobj):
60+
verbose("Loading Odlyzko database from " + sobj)
61+
return load(sobj)
62+
raise FileNotFoundError('Could not find the odlyzko database')

src/sage/databases/sloane.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
import ssl
8888

8989
from sage.misc.verbose import verbose
90-
from sage.env import SAGE_SHARE
90+
from sage.env import DOT_SAGE, sage_data_paths
9191
from sage.rings.integer_ring import ZZ
9292

9393

@@ -101,7 +101,12 @@ def __init__(self):
101101
"""
102102
Initialize the database but do not load any of the data.
103103
"""
104-
self.__path__ = os.path.join(SAGE_SHARE, 'sloane')
104+
self.__path__ = os.path.join(DOT_SAGE, 'db', 'sloane')
105+
for path in sage_data_paths('sloane'):
106+
file_oeis = os.path.join(path, 'sloane-oeis.bz2')
107+
file_names = os.path.join(path, 'sloane-names.bz2')
108+
if os.path.exists(file_oeis) and os.path.exists(file_names):
109+
self.__path__ = path
105110
self.__file__ = os.path.join(self.__path__, 'sloane-oeis.bz2')
106111
self.__file_names__ = os.path.join(self.__path__, 'sloane-names.bz2')
107112
self.__loaded__ = False

src/sage/databases/stein_watkins.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
import bz2
138138
import os
139139

140-
from sage.env import SAGE_SHARE
140+
from sage.env import sage_data_paths
141141

142142

143143
class SteinWatkinsIsogenyClass:
@@ -183,7 +183,13 @@ def __init__(self, num):
183183
raise RuntimeError("num (=%s) must be a nonnegative integer" % num)
184184
name = str(num)
185185
name = '0' * (3 - len(name)) + name
186-
self._file = os.path.join(SAGE_SHARE, 'stein_watkins', 'a.%s.bz2' % name)
186+
self._file = None
187+
for path in sage_data_paths('stein_watkins'):
188+
file = os.path.join(path, 'a.%s.bz2' % name)
189+
if os.path.exists(file):
190+
self._file = file
191+
if not self._file:
192+
raise FileNotFoundError('Could not find the Stein-Watkins database')
187193
self._iter = iter(self)
188194

189195
def __repr__(self):
@@ -317,7 +323,13 @@ def __init__(self, num):
317323
raise RuntimeError("num (=%s) must be a nonnegative integer" % num)
318324
name = str(num)
319325
name = '0' * (2 - len(name)) + name
320-
self._file = os.path.join(SAGE_SHARE, 'stein_watkins', 'p.%s.bz2' % name)
326+
self._file = None
327+
for path in sage_data_paths('stein_watkins'):
328+
file = os.path.join(path, 'p.%s.bz2' % name)
329+
if os.path.exists(file):
330+
self._file = file
331+
if not self._file:
332+
raise FileNotFoundError('Could not find the Stein-Watkins database')
321333
self._iter = iter(self)
322334

323335
def __repr__(self):

src/sage/databases/symbolic_data.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,16 @@ def __init__(self):
9191
sage: sd = SymbolicData(); sd # optional - database_symbolic_data
9292
SymbolicData with 372 ideals
9393
"""
94-
from sage.env import SAGE_SHARE
95-
path = os.path.join(SAGE_SHARE, 'symbolic_data')
96-
self.__intpath = path + "/Data/XMLResources/INTPS/"
97-
self.__genpath = path + "/Data/XMLResources/GenPS/"
94+
from sage.env import sage_data_paths
95+
self.__intpath = self.__genpath = None
96+
for path in sage_data_paths('symbolic_data'):
97+
intpath = path + "/Data/XMLResources/INTPS/"
98+
genpath = path + "/Data/XMLResources/GenPS/"
99+
if os.path.exists(intpath) and os.path.exists(genpath):
100+
self.__intpath = intpath
101+
self.__genpath = genpath
102+
if not self.__intpath or not self.__genpath:
103+
raise FileNotFoundError('Could not find the SymbolicData database')
98104

99105
def get_ideal(self, name, base_ring=QQ, term_order='degrevlex'):
100106
"""
@@ -218,4 +224,4 @@ def __dir__(self):
218224
self.__ideals = [s.replace('.', '__') for s in __ideals]
219225
return self.__ideals
220226
except OSError:
221-
raise AttributeError("Could not find symbolic data, you should perhaps install the optional package")
227+
raise AttributeError("Could not find symbolic data")

src/sage/features/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
from pathlib import Path
7373
from tempfile import NamedTemporaryFile
7474

75-
from sage.env import SAGE_LOCAL, SAGE_SHARE, SAGE_VENV
75+
from sage.env import SAGE_LOCAL, SAGE_VENV, sage_data_paths
7676

7777

7878
class TrivialClasscallMetaClass(type):
@@ -798,7 +798,7 @@ def __init__(self, name, filename, *, search_path=None, type='optional', **kwds)
798798
Feature.__init__(self, name, type=type, **kwds)
799799
self.filename = filename
800800
if search_path is None:
801-
self.search_path = [SAGE_SHARE]
801+
self.search_path = list(sage_data_paths())
802802
elif isinstance(search_path, str):
803803
self.search_path = [search_path]
804804
else:

0 commit comments

Comments
 (0)