passagemath-repl 10.4.62__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- passagemath_repl-10.4.62.data/scripts/sage-cachegrind +25 -0
- passagemath_repl-10.4.62.data/scripts/sage-callgrind +16 -0
- passagemath_repl-10.4.62.data/scripts/sage-cleaner +230 -0
- passagemath_repl-10.4.62.data/scripts/sage-coverage +327 -0
- passagemath_repl-10.4.62.data/scripts/sage-eval +14 -0
- passagemath_repl-10.4.62.data/scripts/sage-fixdoctests +708 -0
- passagemath_repl-10.4.62.data/scripts/sage-inline-fortran +12 -0
- passagemath_repl-10.4.62.data/scripts/sage-ipynb2rst +50 -0
- passagemath_repl-10.4.62.data/scripts/sage-ipython +16 -0
- passagemath_repl-10.4.62.data/scripts/sage-massif +25 -0
- passagemath_repl-10.4.62.data/scripts/sage-notebook +267 -0
- passagemath_repl-10.4.62.data/scripts/sage-omega +25 -0
- passagemath_repl-10.4.62.data/scripts/sage-preparse +302 -0
- passagemath_repl-10.4.62.data/scripts/sage-run +27 -0
- passagemath_repl-10.4.62.data/scripts/sage-run-cython +10 -0
- passagemath_repl-10.4.62.data/scripts/sage-runtests +9 -0
- passagemath_repl-10.4.62.data/scripts/sage-startuptime.py +163 -0
- passagemath_repl-10.4.62.data/scripts/sage-valgrind +34 -0
- passagemath_repl-10.4.62.dist-info/METADATA +77 -0
- passagemath_repl-10.4.62.dist-info/RECORD +162 -0
- passagemath_repl-10.4.62.dist-info/WHEEL +5 -0
- passagemath_repl-10.4.62.dist-info/top_level.txt +1 -0
- sage/all__sagemath_repl.py +119 -0
- sage/doctest/__init__.py +4 -0
- sage/doctest/__main__.py +236 -0
- sage/doctest/all.py +4 -0
- sage/doctest/check_tolerance.py +261 -0
- sage/doctest/control.py +1727 -0
- sage/doctest/external.py +534 -0
- sage/doctest/fixtures.py +383 -0
- sage/doctest/forker.py +2665 -0
- sage/doctest/marked_output.py +102 -0
- sage/doctest/parsing.py +1708 -0
- sage/doctest/parsing_test.py +79 -0
- sage/doctest/reporting.py +733 -0
- sage/doctest/rif_tol.py +124 -0
- sage/doctest/sources.py +1657 -0
- sage/doctest/test.py +584 -0
- sage/doctest/tests/1second.rst +4 -0
- sage/doctest/tests/99seconds.rst +4 -0
- sage/doctest/tests/abort.rst +5 -0
- sage/doctest/tests/atexit.rst +7 -0
- sage/doctest/tests/fail_and_die.rst +6 -0
- sage/doctest/tests/initial.rst +15 -0
- sage/doctest/tests/interrupt.rst +7 -0
- sage/doctest/tests/interrupt_diehard.rst +14 -0
- sage/doctest/tests/keyboardinterrupt.rst +11 -0
- sage/doctest/tests/longtime.rst +5 -0
- sage/doctest/tests/nodoctest +5 -0
- sage/doctest/tests/random_seed.rst +4 -0
- sage/doctest/tests/show_skipped.rst +18 -0
- sage/doctest/tests/sig_on.rst +9 -0
- sage/doctest/tests/simple_failure.rst +8 -0
- sage/doctest/tests/sleep_and_raise.rst +106 -0
- sage/doctest/tests/tolerance.rst +31 -0
- sage/doctest/util.py +750 -0
- sage/interfaces/cleaner.py +48 -0
- sage/interfaces/quit.py +163 -0
- sage/misc/all__sagemath_repl.py +51 -0
- sage/misc/banner.py +235 -0
- sage/misc/benchmark.py +221 -0
- sage/misc/classgraph.py +131 -0
- sage/misc/copying.py +22 -0
- sage/misc/cython.py +694 -0
- sage/misc/dev_tools.py +745 -0
- sage/misc/edit_module.py +304 -0
- sage/misc/explain_pickle.py +3079 -0
- sage/misc/gperftools.py +361 -0
- sage/misc/inline_fortran.py +212 -0
- sage/misc/messaging.py +86 -0
- sage/misc/pager.py +21 -0
- sage/misc/profiler.py +179 -0
- sage/misc/python.py +70 -0
- sage/misc/remote_file.py +53 -0
- sage/misc/sage_eval.py +246 -0
- sage/misc/sage_input.py +3621 -0
- sage/misc/sagedoc.py +1742 -0
- sage/misc/sh.py +38 -0
- sage/misc/trace.py +90 -0
- sage/repl/__init__.py +16 -0
- sage/repl/all.py +15 -0
- sage/repl/attach.py +625 -0
- sage/repl/configuration.py +186 -0
- sage/repl/display/__init__.py +1 -0
- sage/repl/display/fancy_repr.py +354 -0
- sage/repl/display/formatter.py +318 -0
- sage/repl/display/jsmol_iframe.py +290 -0
- sage/repl/display/pretty_print.py +153 -0
- sage/repl/display/util.py +163 -0
- sage/repl/image.py +302 -0
- sage/repl/inputhook.py +91 -0
- sage/repl/interface_magic.py +298 -0
- sage/repl/interpreter.py +854 -0
- sage/repl/ipython_extension.py +593 -0
- sage/repl/ipython_kernel/__init__.py +1 -0
- sage/repl/ipython_kernel/__main__.py +4 -0
- sage/repl/ipython_kernel/all_jupyter.py +10 -0
- sage/repl/ipython_kernel/install.py +301 -0
- sage/repl/ipython_kernel/interact.py +278 -0
- sage/repl/ipython_kernel/kernel.py +217 -0
- sage/repl/ipython_kernel/widgets.py +466 -0
- sage/repl/ipython_kernel/widgets_sagenb.py +587 -0
- sage/repl/ipython_tests.py +163 -0
- sage/repl/load.py +326 -0
- sage/repl/preparse.py +2218 -0
- sage/repl/prompts.py +90 -0
- sage/repl/rich_output/__init__.py +4 -0
- sage/repl/rich_output/backend_base.py +648 -0
- sage/repl/rich_output/backend_doctest.py +316 -0
- sage/repl/rich_output/backend_emacs.py +151 -0
- sage/repl/rich_output/backend_ipython.py +596 -0
- sage/repl/rich_output/buffer.py +311 -0
- sage/repl/rich_output/display_manager.py +829 -0
- sage/repl/rich_output/example.avi +0 -0
- sage/repl/rich_output/example.canvas3d +1 -0
- sage/repl/rich_output/example.dvi +0 -0
- sage/repl/rich_output/example.flv +0 -0
- sage/repl/rich_output/example.gif +0 -0
- sage/repl/rich_output/example.jpg +0 -0
- sage/repl/rich_output/example.mkv +0 -0
- sage/repl/rich_output/example.mov +0 -0
- sage/repl/rich_output/example.mp4 +0 -0
- sage/repl/rich_output/example.ogv +0 -0
- sage/repl/rich_output/example.pdf +0 -0
- sage/repl/rich_output/example.png +0 -0
- sage/repl/rich_output/example.svg +54 -0
- sage/repl/rich_output/example.webm +0 -0
- sage/repl/rich_output/example.wmv +0 -0
- sage/repl/rich_output/example_jmol.spt.zip +0 -0
- sage/repl/rich_output/example_wavefront_scene.mtl +7 -0
- sage/repl/rich_output/example_wavefront_scene.obj +17 -0
- sage/repl/rich_output/output_basic.py +391 -0
- sage/repl/rich_output/output_browser.py +103 -0
- sage/repl/rich_output/output_catalog.py +54 -0
- sage/repl/rich_output/output_graphics.py +320 -0
- sage/repl/rich_output/output_graphics3d.py +345 -0
- sage/repl/rich_output/output_video.py +231 -0
- sage/repl/rich_output/preferences.py +432 -0
- sage/repl/rich_output/pretty_print.py +339 -0
- sage/repl/rich_output/test_backend.py +201 -0
- sage/repl/user_globals.py +214 -0
- sage/tests/__init__.py +1 -0
- sage/tests/all.py +3 -0
- sage/tests/article_heuberger_krenn_kropf_fsm-in-sage.py +630 -0
- sage/tests/arxiv_0812_2725.py +351 -0
- sage/tests/benchmark.py +1923 -0
- sage/tests/book_schilling_zabrocki_kschur_primer.py +795 -0
- sage/tests/book_stein_ent.py +651 -0
- sage/tests/book_stein_modform.py +558 -0
- sage/tests/cmdline.py +790 -0
- sage/tests/combinatorial_hopf_algebras.py +52 -0
- sage/tests/finite_poset.py +623 -0
- sage/tests/functools_partial_src.py +27 -0
- sage/tests/gosper-sum.py +218 -0
- sage/tests/lazy_imports.py +28 -0
- sage/tests/modular_group_cohomology.py +80 -0
- sage/tests/numpy.py +21 -0
- sage/tests/parigp.py +76 -0
- sage/tests/startup.py +27 -0
- sage/tests/symbolic-series.py +76 -0
- sage/tests/sympy.py +16 -0
- sage/tests/test_deprecation.py +31 -0
@@ -0,0 +1,298 @@
|
|
1
|
+
# sage_setup: distribution = sagemath-repl
|
2
|
+
"""
|
3
|
+
Magics for each of the Sage interfaces
|
4
|
+
|
5
|
+
This module defines magic functions for interpreters. As an example,
|
6
|
+
consider the GAP interpreter which can evaluate a gap command given as
|
7
|
+
a string::
|
8
|
+
|
9
|
+
sage: gap('SymmetricGroup(4)') # not tested
|
10
|
+
SymmetricGroup( [ 1 .. 4 ] )
|
11
|
+
|
12
|
+
Magics are syntactic sugar to avoid writing the Python string. They
|
13
|
+
are either called as line magics::
|
14
|
+
|
15
|
+
sage: %gap SymmetricGroup(4) # not tested
|
16
|
+
|
17
|
+
or as cell magics, that is, spanning multiple lines::
|
18
|
+
|
19
|
+
sage: %%gap # not tested
|
20
|
+
....: G := SymmetricGroup(4);
|
21
|
+
....: Display(G);
|
22
|
+
|
23
|
+
Note that the cell magic needs semicolons, this is required by the GAP
|
24
|
+
language to separate multiple commands.
|
25
|
+
"""
|
26
|
+
# Note: no magics in doctests, hence # not tested
|
27
|
+
|
28
|
+
|
29
|
+
# ****************************************************************************
|
30
|
+
# Copyright (C) 2016 Volker Braun <vbraun.name@gmail.com>
|
31
|
+
#
|
32
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
33
|
+
# as published by the Free Software Foundation; either version 2 of
|
34
|
+
# the License, or (at your option) any later version.
|
35
|
+
# https://www.gnu.org/licenses/
|
36
|
+
# ****************************************************************************
|
37
|
+
|
38
|
+
from sage.misc.lazy_import import lazy_import, LazyImport
|
39
|
+
from sage.repl.rich_output.display_manager import get_display_manager
|
40
|
+
|
41
|
+
lazy_import('sage.interfaces.interface', 'Interface')
|
42
|
+
|
43
|
+
|
44
|
+
LINE_DOCSTRING = """
|
45
|
+
Interact with {name}
|
46
|
+
|
47
|
+
The line magic %{name} sends a single line to the {name} interface.
|
48
|
+
|
49
|
+
INPUT:
|
50
|
+
|
51
|
+
Single {name} command
|
52
|
+
|
53
|
+
OUTPUT:
|
54
|
+
|
55
|
+
The result of the evaluated {name} command as an interface wrapper
|
56
|
+
object.
|
57
|
+
|
58
|
+
EXAMPLES::
|
59
|
+
|
60
|
+
sage: %{name} 1 + 2 + 3 # not tested
|
61
|
+
"""
|
62
|
+
|
63
|
+
|
64
|
+
CELL_DOCSTRING = """
|
65
|
+
Interact with {name}
|
66
|
+
|
67
|
+
The cell magic %%{name} sends multiple lines to the {name} interface.
|
68
|
+
|
69
|
+
INPUT:
|
70
|
+
|
71
|
+
Multiple lines of valid {name}-commands
|
72
|
+
|
73
|
+
OUTPUT:
|
74
|
+
|
75
|
+
The result of the evaluated {name}-commands is printed.
|
76
|
+
|
77
|
+
EXAMPLES::
|
78
|
+
|
79
|
+
sage: %%{name} # not tested
|
80
|
+
....: 1 + 2 + 3;
|
81
|
+
....: some_{name}_command();
|
82
|
+
"""
|
83
|
+
|
84
|
+
|
85
|
+
class InterfaceMagic:
|
86
|
+
|
87
|
+
@classmethod
|
88
|
+
def all_iter(cls):
|
89
|
+
"""
|
90
|
+
Iterate over the available interfaces.
|
91
|
+
|
92
|
+
EXAMPLES::
|
93
|
+
|
94
|
+
sage: from sage.repl.interface_magic import InterfaceMagic
|
95
|
+
sage: next(InterfaceMagic.all_iter())
|
96
|
+
<sage.repl.interface_magic.InterfaceMagic object at 0x...>
|
97
|
+
"""
|
98
|
+
try:
|
99
|
+
import sage.interfaces.all
|
100
|
+
except ImportError:
|
101
|
+
return
|
102
|
+
for name, obj in sage.interfaces.all.__dict__.items():
|
103
|
+
if isinstance(obj, (Interface, LazyImport)):
|
104
|
+
yield cls(name, obj)
|
105
|
+
|
106
|
+
@classmethod
|
107
|
+
def register_all(cls, shell=None):
|
108
|
+
"""
|
109
|
+
Register all available interfaces.
|
110
|
+
|
111
|
+
EXAMPLES::
|
112
|
+
|
113
|
+
sage: class MockShell():
|
114
|
+
....: magics = set()
|
115
|
+
....: def register_magic_function(self, fn, magic_name, magic_kind):
|
116
|
+
....: self.magics.add(magic_name)
|
117
|
+
....: print(magic_name, magic_kind)
|
118
|
+
sage: from sage.repl.interface_magic import InterfaceMagic
|
119
|
+
sage: InterfaceMagic.register_all(MockShell()) # random output
|
120
|
+
('gp', 'line')
|
121
|
+
('gp', 'cell')
|
122
|
+
('mwrank', 'line')
|
123
|
+
('mwrank', 'cell')
|
124
|
+
...
|
125
|
+
('maxima', 'line')
|
126
|
+
('maxima', 'cell')
|
127
|
+
sage: 'gap' in MockShell.magics # needs sage.libs.gap
|
128
|
+
True
|
129
|
+
sage: 'maxima' in MockShell.magics # needs sage.symbolic
|
130
|
+
True
|
131
|
+
"""
|
132
|
+
if shell is None:
|
133
|
+
shell = get_ipython()
|
134
|
+
for interface in cls.all_iter():
|
135
|
+
shell.register_magic_function(
|
136
|
+
interface.line_magic_factory(),
|
137
|
+
magic_name=interface._name,
|
138
|
+
magic_kind='line'
|
139
|
+
)
|
140
|
+
shell.register_magic_function(
|
141
|
+
interface.cell_magic_factory(),
|
142
|
+
magic_name=interface._name,
|
143
|
+
magic_kind='cell'
|
144
|
+
)
|
145
|
+
|
146
|
+
@classmethod
|
147
|
+
def find(cls, name):
|
148
|
+
"""
|
149
|
+
Find a particular magic by name.
|
150
|
+
|
151
|
+
This method is for doctesting purposes only.
|
152
|
+
|
153
|
+
INPUT:
|
154
|
+
|
155
|
+
- ``name`` -- string; the name of the interface magic to search for
|
156
|
+
|
157
|
+
OUTPUT: the corresponding :class:`InterfaceMagic` instance
|
158
|
+
|
159
|
+
EXAMPLES::
|
160
|
+
|
161
|
+
sage: from sage.repl.interface_magic import InterfaceMagic
|
162
|
+
sage: InterfaceMagic.find('gap') # needs sage.libs.gap
|
163
|
+
<sage.repl.interface_magic.InterfaceMagic object at 0x...>
|
164
|
+
"""
|
165
|
+
for magic in cls.all_iter():
|
166
|
+
if magic._name == name:
|
167
|
+
return magic
|
168
|
+
|
169
|
+
def __init__(self, name, interface):
|
170
|
+
"""
|
171
|
+
Interface Magic.
|
172
|
+
|
173
|
+
This class is a wrapper around interface objects to provide
|
174
|
+
them with magics.
|
175
|
+
|
176
|
+
INPUT:
|
177
|
+
|
178
|
+
- ``name`` -- string; the interface name
|
179
|
+
|
180
|
+
- ``interface`` -- :class:`sage.interfaces.expect.Expect`; the
|
181
|
+
interface to wrap
|
182
|
+
|
183
|
+
EXAMPLES::
|
184
|
+
|
185
|
+
sage: from sage.repl.interface_magic import InterfaceMagic
|
186
|
+
sage: InterfaceMagic.find('gap') # needs sage.libs.gap
|
187
|
+
<sage.repl.interface_magic.InterfaceMagic object at 0x...>
|
188
|
+
"""
|
189
|
+
self._name = name
|
190
|
+
self._interface = interface
|
191
|
+
|
192
|
+
def line_magic_factory(self):
|
193
|
+
"""
|
194
|
+
Factory for line magic.
|
195
|
+
|
196
|
+
OUTPUT: a function suitable to be used as line magic
|
197
|
+
|
198
|
+
EXAMPLES::
|
199
|
+
|
200
|
+
sage: # needs sage.libs.gap
|
201
|
+
sage: from sage.repl.interface_magic import InterfaceMagic
|
202
|
+
sage: line_magic = InterfaceMagic.find('gap').line_magic_factory()
|
203
|
+
sage: output = line_magic('1+1')
|
204
|
+
sage: output
|
205
|
+
2
|
206
|
+
sage: type(output)
|
207
|
+
<class 'sage.interfaces.gap.GapElement'>
|
208
|
+
|
209
|
+
This is how the built line magic is used in practice::
|
210
|
+
|
211
|
+
sage: from sage.repl.interpreter import get_test_shell
|
212
|
+
sage: shell = get_test_shell()
|
213
|
+
sage: shell.run_cell('%gap 1+1') # needs sage.libs.gap
|
214
|
+
2
|
215
|
+
sage: shell.run_cell('%gap?') # needs sage.libs.gap
|
216
|
+
Docstring:
|
217
|
+
Interact with gap
|
218
|
+
<BLANKLINE>
|
219
|
+
The line magic %gap sends a single line to the gap interface.
|
220
|
+
...
|
221
|
+
"""
|
222
|
+
terminal = get_display_manager().is_in_terminal()
|
223
|
+
|
224
|
+
def line_magic(line):
|
225
|
+
if line:
|
226
|
+
return self._interface(line)
|
227
|
+
else:
|
228
|
+
if terminal:
|
229
|
+
self._interface.interact()
|
230
|
+
else:
|
231
|
+
raise SyntaxError('{0} command required'.format(self._name))
|
232
|
+
line_magic.__doc__ = LINE_DOCSTRING.format(name=self._name)
|
233
|
+
return line_magic
|
234
|
+
|
235
|
+
def cell_magic_factory(self):
|
236
|
+
r"""
|
237
|
+
Factory for cell magic.
|
238
|
+
|
239
|
+
OUTPUT: a function suitable to be used as cell magic
|
240
|
+
|
241
|
+
EXAMPLES::
|
242
|
+
|
243
|
+
sage: # needs sage.libs.gap
|
244
|
+
sage: from sage.repl.interface_magic import InterfaceMagic
|
245
|
+
sage: cell_magic = InterfaceMagic.find('gap').cell_magic_factory()
|
246
|
+
sage: output = cell_magic('', '1+1;')
|
247
|
+
2
|
248
|
+
sage: output is None
|
249
|
+
True
|
250
|
+
sage: cell_magic('foo', '1+1;')
|
251
|
+
Traceback (most recent call last):
|
252
|
+
...
|
253
|
+
SyntaxError: Interface magics have no options, got "foo"
|
254
|
+
|
255
|
+
This is how the built cell magic is used in practice::
|
256
|
+
|
257
|
+
sage: from sage.repl.interpreter import get_test_shell
|
258
|
+
sage: shell = get_test_shell()
|
259
|
+
sage: shell.run_cell('%%gap\nG:=SymmetricGroup(5);\n1+1;Order(G);') # needs sage.libs.gap
|
260
|
+
Sym( [ 1 .. 5 ] )
|
261
|
+
2
|
262
|
+
120
|
263
|
+
sage: shell.run_cell('%%gap foo\n1+1;\n') # needs sage.libs.gap
|
264
|
+
...File...<string>...
|
265
|
+
SyntaxError: Interface magics have no options, got "foo"
|
266
|
+
<BLANKLINE>
|
267
|
+
sage: shell.run_cell('%%gap?') # needs sage.libs.gap
|
268
|
+
Docstring:
|
269
|
+
Interact with gap
|
270
|
+
<BLANKLINE>
|
271
|
+
The cell magic %%gap sends multiple lines to the gap interface.
|
272
|
+
...
|
273
|
+
"""
|
274
|
+
def cell_magic(line, cell):
|
275
|
+
"""
|
276
|
+
Evaluate cell magic.
|
277
|
+
|
278
|
+
Docstring is overwritten in the instance.
|
279
|
+
|
280
|
+
INPUT:
|
281
|
+
|
282
|
+
- ``line`` -- string; the option part of the cell magic
|
283
|
+
|
284
|
+
- ``cell`` -- string; the lines of the cell magic
|
285
|
+
|
286
|
+
OUTPUT: prints the interface output
|
287
|
+
|
288
|
+
RAISES:
|
289
|
+
|
290
|
+
:exc:`SyntaxError` if a line is specified; Interfaces have no
|
291
|
+
options.
|
292
|
+
"""
|
293
|
+
if line:
|
294
|
+
raise SyntaxError('Interface magics have no options, got "{0}"'.format(line))
|
295
|
+
output = self._interface.eval(cell)
|
296
|
+
print(output)
|
297
|
+
cell_magic.__doc__ = CELL_DOCSTRING.format(name=self._name)
|
298
|
+
return cell_magic
|