Skip to content
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

deprecate some imports #35841

Merged
merged 5 commits into from
Jul 20, 2023
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
4 changes: 0 additions & 4 deletions src/sage/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@
copying = license
copyright = license

_cpu_time_ = cputime()
_wall_time_ = walltime()


def quit_sage(verbose=True):
"""
Does nothing. Code that needs cleanup should register its own
Expand Down
22 changes: 11 additions & 11 deletions src/sage/misc/abstract_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ def abstract_method(f=None, optional=False):

sage: abstract_method(optional = True)
<function abstract_method.<locals>.<lambda> at ...>
sage: abstract_method(optional = True)(banner)
<optional abstract method banner at ...>
sage: abstract_method(banner, optional = True)
<optional abstract method banner at ...>
sage: abstract_method(optional = True)(version)
<optional abstract method version at ...>
sage: abstract_method(version, optional = True)
<optional abstract method version at ...>
"""
if f is None:
return lambda f: AbstractMethod(f, optional=optional)
Expand Down Expand Up @@ -173,11 +173,11 @@ def __repr__(self):
"""
EXAMPLES::

sage: abstract_method(banner)
<abstract method banner at ...>
sage: abstract_method(version)
<abstract method version at ...>

sage: abstract_method(banner, optional = True)
<optional abstract method banner at ...>
sage: abstract_method(version, optional = True)
<optional abstract method version at ...>
"""
return "<" + ("optional " if self._optional else "") + "abstract method %s at %s>" % (self.__name__, hex(id(self._f)))

Expand All @@ -188,12 +188,12 @@ def _sage_src_lines_(self):
EXAMPLES::

sage: from sage.misc.sageinspect import sage_getsourcelines
sage: g = abstract_method(banner)
sage: g = abstract_method(version)
sage: (src, lines) = sage_getsourcelines(g)
sage: src[0]
'def banner():\n'
'def version():\n'
sage: lines
89
19
"""
from sage.misc.sageinspect import sage_getsourcelines
return sage_getsourcelines(self._f)
Expand Down
61 changes: 15 additions & 46 deletions src/sage/misc/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,28 @@
lazy_import('sage.misc.misc', 'union',
deprecation=32096)

from .banner import version, banner
from .banner import version

from .dev_tools import runsnake, import_statements
from .dev_tools import import_statements

from .html import html, pretty_print_default

from .table import table

from .sage_timeit_class import timeit

from .edit_module import edit, set_edit_template
from .edit_module import edit

from .map_threaded import map_threaded

from .session import load_session, save_session, show_identifiers

from .remote_file import get_remote_file

from .profiler import Profiler

from .mrange import xmrange, mrange, xmrange_iter, mrange_iter, cartesian_product_iterator

from .fpickle import pickle_function, unpickle_function

from .dist import install_scripts

lazy_import('sage.misc.package', ('installed_packages', 'is_package_installed',
'standard_packages', 'optional_packages',
'experimental_packages', 'package_versions'))

lazy_import('sage.misc.pager', 'pager')

lazy_import('sage.misc.sagedoc', ['browse_sage_doc',
Expand Down Expand Up @@ -128,8 +120,6 @@

from .latex import LatexExpr, latex, view

from .trace import trace

from .randstate import seed, set_random_seed, initial_seed, current_randstate

from .prandom import *
Expand All @@ -140,36 +130,15 @@

lazy_import('sage.misc.inline_fortran', 'fortran')


##########################################################################
def benchmark(n=-1):
"""
Run a well-chosen range of Sage commands and record the time it
takes for each to run.

INPUT:

- ``n`` -- int (default: -1); the benchmark number. The default
of -1 runs all the benchmarks.

OUTPUT:

- ``list`` -- summary of timings for each benchmark
"""
import sage.misc.benchmark
return sage.misc.benchmark.benchmark(n)


class logstr(str):
def __repr__(self):
return self

def _latex_(self):
# return "\\begin{verbatim}%s\\end{verbatim}"%self
if '#' not in self:
delim = '#'
elif '@' not in self:
delim = '@'
elif '~' not in self:
delim = '~'
return r"""\verb%s%s%s""" % (delim, self.replace('\n\n', '\n').replace('\n', '; '), delim)
lazy_import('sage.misc.banner', 'banner', deprecation=34259)
lazy_import('sage.misc.dev_tools', 'runsnake', deprecation=34259)
lazy_import('sage.misc.edit_module', 'set_edit_template', deprecation=34259)
lazy_import('sage.misc.profiler', 'Profiler', deprecation=34259)
lazy_import('sage.misc.dist', 'install_scripts', deprecation=34259)
lazy_import('sage.misc.trace', 'trace', deprecation=34259)
lazy_import('sage.misc.package', ('installed_packages', 'is_package_installed',
'standard_packages', 'optional_packages',
'experimental_packages', 'package_versions'),
deprecation=34259)
lazy_import('sage.misc.benchmark', 'benchmark', deprecation=34259)
lazy_import('sage.repl.interpreter', 'logstr', deprecation=34259)
2 changes: 1 addition & 1 deletion src/sage/misc/banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def banner():
EXAMPLES::

sage: import sage.misc.banner; sage.misc.banner.SAGE_BANNER = ''
sage: banner()
sage: sage.misc.banner.banner()
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ SageMath version ..., Release Date: ... β”‚
β”‚ Using Python .... Type "help()" for help. β”‚
Expand Down
1 change: 1 addition & 0 deletions src/sage/misc/dev_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def runsnake(command):

EXAMPLES::

sage: from sage.misc.dev_tools import runsnake
sage: runsnake("list(SymmetricGroup(3))") # optional - runsnake

``command`` is first preparsed (see :func:`preparse`)::
Expand Down
1 change: 1 addition & 0 deletions src/sage/misc/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def install_scripts(directory=None, ignore_existing=False):
EXAMPLES::

sage: import tempfile
sage: from sage.misc.dist import install_scripts
sage: with tempfile.TemporaryDirectory() as d:
....: install_scripts(d, ignore_existing=True)
doctest:warning...
Expand Down
2 changes: 1 addition & 1 deletion src/sage/misc/lazy_attribute.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ cdef class _lazy_attribute():
EXAMPLES::

sage: from sage.misc.sageinspect import sage_getsourcelines
sage: g = lazy_attribute(banner)
sage: g = lazy_attribute(sage.misc.banner.banner)
sage: (src, lines) = sage_getsourcelines(g)
sage: src[0]
'def banner():\n'
Expand Down
3 changes: 3 additions & 0 deletions src/sage/misc/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ def installed_packages(exclude_pip=True):
records of Python packages. Our ``SAGE_VENV`` is not necessarily the
main Sage venv; it could be a user-created venv or a venv created by tox.)::

sage: from sage.misc.package import installed_packages
sage: sorted(installed_packages().keys()) # optional - sage_spkg
[...'conway_polynomials', ...]
sage: installed_packages()['conway_polynomials'] # optional - sage_spkg, random
Expand Down Expand Up @@ -462,6 +463,7 @@ def is_package_installed(package, exclude_pip=True):

EXAMPLES::

sage: from sage.misc.package import is_package_installed
sage: is_package_installed('conway_polynomials') # optional - sage_spkg
True

Expand Down Expand Up @@ -532,6 +534,7 @@ def package_versions(package_type, local=False):

EXAMPLES::

sage: from sage.misc.package import package_versions
sage: std = package_versions('standard', local=True) # optional - sage_spkg
sage: 'gap' in std # optional - sage_spkg
True
Expand Down
1 change: 1 addition & 0 deletions src/sage/misc/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Profiler:

EXAMPLES::

from sage.misc.profiler import Profiler
sage: def f(): # not tested
....: p = Profiler()

Expand Down
3 changes: 2 additions & 1 deletion src/sage/misc/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def trace(code, preparse=True):

::

sage: from sage.misc.trace import trace
sage: trace("factor(100)") # not tested

then at the (Pdb) prompt type ``s`` (or ``step``), then press :kbd:`Return`
Expand Down Expand Up @@ -55,7 +56,7 @@ def trace(code, preparse=True):

sage: import pexpect
sage: s = pexpect.spawn('sage')
sage: _ = s.sendline("trace('print(factor(10))'); print(3+97)")
sage: _ = s.sendline("from sage.misc.trace import trace; trace('print(factor(10))'); print(3+97)")
sage: _ = s.expect('ipdb>', timeout=90)
sage: _ = s.sendline("s"); _ = s.sendline("c")
sage: _ = s.expect('100', timeout=90)
Expand Down
1 change: 0 additions & 1 deletion src/sage/modular/hecke/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,6 @@ def system_of_eigenvalues(self, n, name='alpha'):
Next we define a function that does the above::

sage: def b(N,k=2):
....: t=cputime()
....: S = ModularSymbols(N,k,sign=-1).cuspidal_submodule().new_submodule()
....: for A in S.decomposition():
....: print("{} {}".format(N, A.system_of_eigenvalues(5)))
Expand Down
48 changes: 42 additions & 6 deletions src/sage/repl/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,42 @@ def SagePreparseTransformer(lines):
# Interface shell #
###################

class logstr(str):
"""
For use by :meth`~InterfaceShellTransformer.transform`.
This provides a ``_latex_`` method which is just the string
wrapped in a ``\\verb`` environment.
"""
def __repr__(self):
"""
EXAMPLES::
sage: from sage.repl.interpreter import logstr
sage: logstr("ABC")
ABC
"""
return self

def _latex_(self):
r"""
EXAMPLES::
sage: from sage.repl.interpreter import logstr
sage: logstr("A")
A
sage: latex(logstr("A"))
\verb#A#
sage: latex(logstr("A#B"))
\verb@A#B@
"""
# return "\\begin{verbatim}%s\\end{verbatim}"%self
if '#' not in self:
delim = '#'
elif '@' not in self:
delim = '@'
elif '~' not in self:
delim = '~'
return r"""\verb%s%s%s""" % (delim, self.replace('\n\n', '\n').replace('\n', '; '), delim)


class InterfaceShellTransformer(PrefilterTransformer):
priority = 50

Expand Down Expand Up @@ -555,16 +591,16 @@ def transform(self, line, continue_prompt):
sage: shell = interface_shell_embed(maxima)
sage: ift = InterfaceShellTransformer(shell=shell, config=shell.config, prefilter_manager=shell.prefilter_manager)
sage: ift.transform('2+2', False) # note: output contains triple quotation marks
'sage.misc.all.logstr(r"""4""")'
'sage.repl.interpreter.logstr(r"""4""")'
sage: ift.shell.ex('a = 4')
sage: ift.transform(r'sage(a)+4', False)
'sage.misc.all.logstr(r"""8""")'
'sage.repl.interpreter.logstr(r"""8""")'
sage: ift.temporary_objects
set()
sage: shell = interface_shell_embed(gap)
sage: ift = InterfaceShellTransformer(shell=shell, config=shell.config, prefilter_manager=shell.prefilter_manager)
sage: ift.transform('2+2', False)
'sage.misc.all.logstr(r"""4""")'
'sage.repl.interpreter.logstr(r"""4""")'

TESTS:

Expand All @@ -574,12 +610,12 @@ def transform(self, line, continue_prompt):
sage: shell = interface_shell_embed(gap)
sage: ift = InterfaceShellTransformer(shell=shell, config=shell.config, prefilter_manager=shell.prefilter_manager)
sage: ift.transform(r'Print(" -\n\\\\- ");', False)
'sage.misc.all.logstr(r""" -\n\\\\-""")'
'sage.repl.interpreter.logstr(r""" -\n\\\\-""")'

sage: shell = interface_shell_embed(macaulay2) # optional - macaulay2
sage: ift = InterfaceShellTransformer(shell=shell, config=shell.config, prefilter_manager=shell.prefilter_manager) # optional - macaulay2
sage: ift.transform('net(ZZ^2)', False) # optional - macaulay2
'sage.misc.all.logstr(r""" 2\nZZ""")'
'sage.repl.interpreter.logstr(r""" 2\nZZ""")'
'''
line = self.preparse_imports_from_sage(line)

Expand All @@ -591,7 +627,7 @@ def transform(self, line, continue_prompt):
self.temporary_objects = set()
# We do not strip whitespace from t here as the individual interface is
# responsible for that
return 'sage.misc.all.logstr(r"""%s""")' % t
return 'sage.repl.interpreter.logstr(r"""%s""")' % t


def interface_shell_embed(interface):
Expand Down
Loading