Skip to content

Remove SAGE_DB from public interface #39012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/sage/graphs/isgci.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,13 +852,8 @@ def update_db(self):

This method downloads the ISGCI database from the website
`GraphClasses.org <http://www.graphclasses.org/>`_. It then extracts the
zip file and parses its XML content.

Depending on the credentials of the user running Sage when this command
is run, one attempt is made at saving the result in Sage's directory so
that all users can benefit from it. If the credentials are not
sufficient, the XML file are saved instead in the user's directory (in
the SAGE_DB folder).
zip file and parses its XML content. The XML file is saved in the directory
controlled by the :class:`DatabaseGraphs` class (usually, ``$HOME/.sage/db``).

EXAMPLES::

Expand Down
3 changes: 1 addition & 2 deletions src/sage/misc/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
exists, forall, is_iterator,
random_sublist,
pad_zeros,
SAGE_DB,
newton_method_sizes, compose,
newton_method_sizes, compose,
nest)

from sage.misc.banner import version
Expand Down
33 changes: 22 additions & 11 deletions src/sage/misc/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@
from sage.env import DOT_SAGE, HOSTNAME
from sage.misc.lazy_import import lazy_import

lazy_import("sage.combinat.subset", ["powerset", "subsets", "uniq"],
deprecation=35564)
lazy_import("sage.combinat.subset", ["powerset", "subsets", "uniq"], deprecation=35564)

lazy_import("sage.misc.timing", ["cputime", "GlobalCputime", "walltime"],
deprecation=35816)
lazy_import(
"sage.misc.timing", ["cputime", "GlobalCputime", "walltime"], deprecation=35816
)

LOCAL_IDENTIFIER = '%s.%s' % (HOSTNAME, os.getpid())

Expand Down Expand Up @@ -169,9 +169,6 @@ def try_read(obj, splitlines=False):
return data


SAGE_DB = os.path.join(DOT_SAGE, 'db')
os.makedirs(SAGE_DB, exist_ok=True)

try:
# Create the matplotlib config directory.
os.makedirs(os.environ["MPLCONFIGDIR"], exist_ok=True)
Expand Down Expand Up @@ -351,6 +348,7 @@ def nest(f, n, x):
x
"""
from sage.rings.integer import Integer

n = Integer(n)

if n < 0:
Expand All @@ -365,6 +363,7 @@ def nest(f, n, x):
# The A \ b operator
#################################################################


class BackslashOperator:
r"""
Implement Matlab-style backslash operator for solving systems::
Expand All @@ -389,6 +388,7 @@ class BackslashOperator:
sage: preparse("A^3 \\ b")
'A**Integer(3) * BackslashOperator() * b'
"""

def __rmul__(self, left):
"""
EXAMPLES::
Expand All @@ -412,6 +412,7 @@ def __rmul__(self, left):
True
"""
from sage.misc.superseded import deprecation

deprecation(36394, 'the backslash operator has been deprecated')
self.left = left
return self
Expand Down Expand Up @@ -443,6 +444,7 @@ def __mul__(self, right):
(0.0, 0.5, 1.0, 1.5, 2.0)
"""
from sage.misc.superseded import deprecation

deprecation(36394, 'the backslash operator has been deprecated')
return self.left._backslash_(right)

Expand Down Expand Up @@ -531,6 +533,7 @@ def random_sublist(X, s):
True
"""
import sage.misc.prandom as random

return [a for a in X if random.random() <= s]


Expand Down Expand Up @@ -603,6 +606,7 @@ def some_tuples(elements, repeat, bound, max_samples=None):
"""
if max_samples is None:
from itertools import islice, product

P = elements if repeat is None else product(elements, repeat=repeat)
return islice(P, int(bound))
else:
Expand All @@ -612,6 +616,7 @@ def some_tuples(elements, repeat, bound, max_samples=None):
N = n if repeat is None else n**repeat
if N <= max_samples:
from itertools import product

return elements if repeat is None else product(elements, repeat=repeat)
return _some_tuples_sampling(elements, repeat, max_samples, n)

Expand All @@ -638,6 +643,7 @@ def _some_tuples_sampling(elements, repeat, max_samples, n):
"""
from sage.rings.integer import Integer
import sage.misc.prandom as random

N = n if repeat is None else n**repeat
# We sample on range(N) and create tuples manually since we don't want to create the list of all possible tuples in memory
for a in random.sample(range(N), max_samples):
Expand All @@ -651,6 +657,7 @@ def _some_tuples_sampling(elements, repeat, max_samples, n):
# Misc.
#################################################################


def exists(S, P):
"""
If S contains an element x such that P(x) is ``True``, this function
Expand Down Expand Up @@ -836,8 +843,8 @@ def in_quote():
# which is the case if the previous character isn't
# a backslash, or it is but both previous characters
# are backslashes.
if line[i - 1: i] != '\\' or line[i - 2: i] == '\\\\':
if line[i: i + 3] in ['"""', "'''"]:
if line[i - 1 : i] != '\\' or line[i - 2 : i] == '\\\\':
if line[i : i + 3] in ['"""', "'''"]:
if not in_quote():
in_triple_quote = True
elif in_triple_quote:
Expand Down Expand Up @@ -899,6 +906,7 @@ def get_main_globals():
module.
"""
import sys

depth = 0
while True:
G = sys._getframe(depth).f_globals
Expand Down Expand Up @@ -957,8 +965,9 @@ def inject_variable(name, value, warn=True):
# also from functions in various modules.
G = get_main_globals()
if name in G and warn:
warnings.warn("redefining global value `%s`" % name,
RuntimeWarning, stacklevel=2)
warnings.warn(
"redefining global value `%s`" % name, RuntimeWarning, stacklevel=2
)
G[name] = value


Expand Down Expand Up @@ -1013,12 +1022,14 @@ def run_once(func):
sage: foo(False)
sage: foo(True)
"""

@functools.wraps(func)
def wrapper(*args, **kwargs):
if not wrapper.has_run:
result = func(*args, **kwargs)
wrapper.has_run = True
return result

wrapper.has_run = False
return wrapper

Expand Down
6 changes: 5 additions & 1 deletion src/sage/misc/persist.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ comp = zlib
comp_other = bz2

from sage.misc.sage_unittest import TestSuite

from sage.misc.superseded import deprecation

# We define two global dictionaries `already_pickled` and
# `already_unpickled`, which are intended to help you to implement
Expand Down Expand Up @@ -1230,6 +1230,8 @@ def db(name):

The database directory is ``$HOME/.sage/db``.
"""
deprecation(39012, "Directly use pickle/unpickle instead of db/db_save.")

from sage.misc.misc import SAGE_DB
return load('%s/%s' % (SAGE_DB, name))

Expand All @@ -1240,6 +1242,8 @@ def db_save(x, name=None):

The database directory is ``$HOME/.sage/db``.
"""
deprecation(39012, "Directly use pickle/unpickle instead of db/db_save.")

try:
x.db(name)
except AttributeError:
Expand Down
Loading