Skip to content

Commit 04f9e45

Browse files
author
Release Manager
committed
gh-35841: deprecate some imports - Head toward deprecation of automatic imports of some dev tools - Remove unnecessary assignments in tests/benchmark.py Deprecate the imports of some dev tools <!-- Please provide a concise, informative and self-explanatory title. --> <!-- Don't put issue numbers in the title. Put it in the Description below. --> <!-- For example, instead of "Fixes #12345", use "Add a new method to multiply two integers" --> ### 📚 Description This is a branch to address #34259, replacing the old trac branch. It doesn't make all of the original changes: the original branch. In particular, the original branch added a bunch of lines like `from sage.misc.misc import cputime` even though the import of `cputime` was not changes, just in case someone wanted to change it later. I skipped all of those additions. The original branch made a few other changes that were not connected to the purposes of this pull request (e.g. the changes to src/sage/combinat/composition.py), and I skipped those, too. <!-- Describe your changes here in detail. --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x ]`. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #35841 Reported by: John H. Palmieri Reviewer(s): Matthias Köppe
2 parents f00b6cb + 0d6c729 commit 04f9e45

File tree

13 files changed

+183
-153
lines changed

13 files changed

+183
-153
lines changed

src/sage/all.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,6 @@
194194
copying = license
195195
copyright = license
196196

197-
_cpu_time_ = cputime()
198-
_wall_time_ = walltime()
199-
200-
201197
def quit_sage(verbose=True):
202198
"""
203199
Does nothing. Code that needs cleanup should register its own

src/sage/misc/abstract_method.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ def abstract_method(f=None, optional=False):
127127

128128
sage: abstract_method(optional = True)
129129
<function abstract_method.<locals>.<lambda> at ...>
130-
sage: abstract_method(optional = True)(banner)
131-
<optional abstract method banner at ...>
132-
sage: abstract_method(banner, optional = True)
133-
<optional abstract method banner at ...>
130+
sage: abstract_method(optional = True)(version)
131+
<optional abstract method version at ...>
132+
sage: abstract_method(version, optional = True)
133+
<optional abstract method version at ...>
134134
"""
135135
if f is None:
136136
return lambda f: AbstractMethod(f, optional=optional)
@@ -173,11 +173,11 @@ def __repr__(self):
173173
"""
174174
EXAMPLES::
175175

176-
sage: abstract_method(banner)
177-
<abstract method banner at ...>
176+
sage: abstract_method(version)
177+
<abstract method version at ...>
178178

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

@@ -188,12 +188,12 @@ def _sage_src_lines_(self):
188188
EXAMPLES::
189189

190190
sage: from sage.misc.sageinspect import sage_getsourcelines
191-
sage: g = abstract_method(banner)
191+
sage: g = abstract_method(version)
192192
sage: (src, lines) = sage_getsourcelines(g)
193193
sage: src[0]
194-
'def banner():\n'
194+
'def version():\n'
195195
sage: lines
196-
89
196+
19
197197
"""
198198
from sage.misc.sageinspect import sage_getsourcelines
199199
return sage_getsourcelines(self._f)

src/sage/misc/all.py

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,28 @@
1515
lazy_import('sage.misc.misc', 'union',
1616
deprecation=32096)
1717

18-
from .banner import version, banner
18+
from .banner import version
1919

20-
from .dev_tools import runsnake, import_statements
20+
from .dev_tools import import_statements
2121

2222
from .html import html, pretty_print_default
2323

2424
from .table import table
2525

2626
from .sage_timeit_class import timeit
2727

28-
from .edit_module import edit, set_edit_template
28+
from .edit_module import edit
2929

3030
from .map_threaded import map_threaded
3131

3232
from .session import load_session, save_session, show_identifiers
3333

3434
from .remote_file import get_remote_file
3535

36-
from .profiler import Profiler
37-
3836
from .mrange import xmrange, mrange, xmrange_iter, mrange_iter, cartesian_product_iterator
3937

4038
from .fpickle import pickle_function, unpickle_function
4139

42-
from .dist import install_scripts
43-
44-
lazy_import('sage.misc.package', ('installed_packages', 'is_package_installed',
45-
'standard_packages', 'optional_packages',
46-
'experimental_packages', 'package_versions'))
47-
4840
lazy_import('sage.misc.pager', 'pager')
4941

5042
lazy_import('sage.misc.sagedoc', ['browse_sage_doc',
@@ -128,8 +120,6 @@
128120

129121
from .latex import LatexExpr, latex, view
130122

131-
from .trace import trace
132-
133123
from .randstate import seed, set_random_seed, initial_seed, current_randstate
134124

135125
from .prandom import *
@@ -140,36 +130,15 @@
140130

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

143-
144-
##########################################################################
145-
def benchmark(n=-1):
146-
"""
147-
Run a well-chosen range of Sage commands and record the time it
148-
takes for each to run.
149-
150-
INPUT:
151-
152-
- ``n`` -- int (default: -1); the benchmark number. The default
153-
of -1 runs all the benchmarks.
154-
155-
OUTPUT:
156-
157-
- ``list`` -- summary of timings for each benchmark
158-
"""
159-
import sage.misc.benchmark
160-
return sage.misc.benchmark.benchmark(n)
161-
162-
163-
class logstr(str):
164-
def __repr__(self):
165-
return self
166-
167-
def _latex_(self):
168-
# return "\\begin{verbatim}%s\\end{verbatim}"%self
169-
if '#' not in self:
170-
delim = '#'
171-
elif '@' not in self:
172-
delim = '@'
173-
elif '~' not in self:
174-
delim = '~'
175-
return r"""\verb%s%s%s""" % (delim, self.replace('\n\n', '\n').replace('\n', '; '), delim)
133+
lazy_import('sage.misc.banner', 'banner', deprecation=34259)
134+
lazy_import('sage.misc.dev_tools', 'runsnake', deprecation=34259)
135+
lazy_import('sage.misc.edit_module', 'set_edit_template', deprecation=34259)
136+
lazy_import('sage.misc.profiler', 'Profiler', deprecation=34259)
137+
lazy_import('sage.misc.dist', 'install_scripts', deprecation=34259)
138+
lazy_import('sage.misc.trace', 'trace', deprecation=34259)
139+
lazy_import('sage.misc.package', ('installed_packages', 'is_package_installed',
140+
'standard_packages', 'optional_packages',
141+
'experimental_packages', 'package_versions'),
142+
deprecation=34259)
143+
lazy_import('sage.misc.benchmark', 'benchmark', deprecation=34259)
144+
lazy_import('sage.repl.interpreter', 'logstr', deprecation=34259)

src/sage/misc/banner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def banner():
100100
EXAMPLES::
101101

102102
sage: import sage.misc.banner; sage.misc.banner.SAGE_BANNER = ''
103-
sage: banner()
103+
sage: sage.misc.banner.banner()
104104
┌────────────────────────────────────────────────────────────────────┐
105105
│ SageMath version ..., Release Date: ... │
106106
│ Using Python .... Type "help()" for help. │

src/sage/misc/dev_tools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def runsnake(command):
3131

3232
EXAMPLES::
3333

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

3637
``command`` is first preparsed (see :func:`preparse`)::

src/sage/misc/dist.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def install_scripts(directory=None, ignore_existing=False):
7070
EXAMPLES::
7171

7272
sage: import tempfile
73+
sage: from sage.misc.dist import install_scripts
7374
sage: with tempfile.TemporaryDirectory() as d:
7475
....: install_scripts(d, ignore_existing=True)
7576
doctest:warning...

src/sage/misc/lazy_attribute.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ cdef class _lazy_attribute():
8282
EXAMPLES::
8383

8484
sage: from sage.misc.sageinspect import sage_getsourcelines
85-
sage: g = lazy_attribute(banner)
85+
sage: g = lazy_attribute(sage.misc.banner.banner)
8686
sage: (src, lines) = sage_getsourcelines(g)
8787
sage: src[0]
8888
'def banner():\n'

src/sage/misc/package.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ def installed_packages(exclude_pip=True):
424424
records of Python packages. Our ``SAGE_VENV`` is not necessarily the
425425
main Sage venv; it could be a user-created venv or a venv created by tox.)::
426426

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

463464
EXAMPLES::
464465

466+
sage: from sage.misc.package import is_package_installed
465467
sage: is_package_installed('conway_polynomials') # optional - sage_spkg
466468
True
467469

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

533535
EXAMPLES::
534536

537+
sage: from sage.misc.package import package_versions
535538
sage: std = package_versions('standard', local=True) # optional - sage_spkg
536539
sage: 'gap' in std # optional - sage_spkg
537540
True

src/sage/misc/profiler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Profiler:
2828

2929
EXAMPLES::
3030

31+
from sage.misc.profiler import Profiler
3132
sage: def f(): # not tested
3233
....: p = Profiler()
3334

src/sage/misc/trace.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def trace(code, preparse=True):
2626

2727
::
2828

29+
sage: from sage.misc.trace import trace
2930
sage: trace("factor(100)") # not tested
3031

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

5657
sage: import pexpect
5758
sage: s = pexpect.spawn('sage')
58-
sage: _ = s.sendline("trace('print(factor(10))'); print(3+97)")
59+
sage: _ = s.sendline("from sage.misc.trace import trace; trace('print(factor(10))'); print(3+97)")
5960
sage: _ = s.expect('ipdb>', timeout=90)
6061
sage: _ = s.sendline("s"); _ = s.sendline("c")
6162
sage: _ = s.expect('100', timeout=90)

0 commit comments

Comments
 (0)