Skip to content
Open
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
5 changes: 3 additions & 2 deletions src/sage/doctest/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,10 +718,11 @@ def file_optional_tags(self):

sage: from sage.doctest.control import DocTestDefaults
sage: from sage.doctest.sources import FileDocTestSource
sage: filename = sage.repl.user_globals.__file__
sage: import sage.tests.numpy
sage: filename = sage.tests.numpy.__file__
sage: FDS = FileDocTestSource(filename, DocTestDefaults())
sage: FDS.file_optional_tags
{'sage.modules': None}
{'numpy': None}
"""
from .parsing import parse_file_optional_tags
return parse_file_optional_tags(self)
Expand Down
7 changes: 3 additions & 4 deletions src/sage/repl/display/fancy_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ def __call__(self, obj, p, cycle):

EXAMPLES::

sage: # needs sage.modules
sage: from sage.repl.display.fancy_repr import LargeMatrixHelpRepr
sage: M = identity_matrix(40)
sage: pp = LargeMatrixHelpRepr()
Expand All @@ -196,9 +195,9 @@ def __call__(self, obj, p, cycle):

Leads to::

sage: M # needs sage.modules
sage: M
40 x 40 dense matrix over Integer Ring (use the '.str()' method...)
sage: [M, M] # needs sage.modules
sage: [M, M]
[40 x 40 dense matrix over Integer Ring,
40 x 40 dense matrix over Integer Ring]
"""
Expand Down Expand Up @@ -317,7 +316,7 @@ def __call__(self, obj, p, cycle):

sage: from sage.repl.display.fancy_repr import TallListRepr
sage: format_list = TallListRepr().format_string
sage: format_list([1, 2, identity_matrix(2)]) # needs sage.modules
sage: format_list([1, 2, identity_matrix(2)])
'[\n [1 0]\n1, 2, [0 1]\n]'

Check that :issue:`18743` is fixed::
Expand Down
24 changes: 12 additions & 12 deletions src/sage/repl/display/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
contains a new facility for displaying lists of matrices in an easier
to read format::

sage: [identity_matrix(i) for i in range(2, 5)] # needs sage.modules
sage: [identity_matrix(i) for i in range(2, 5)]
[
[1 0 0 0]
[1 0 0] [0 1 0 0]
Expand All @@ -23,17 +23,17 @@
sage: from sage.repl.interpreter import get_test_shell
sage: shell = get_test_shell()
sage: shell.run_cell('%display ascii_art')
sage: shell.run_cell('integral(x^2/pi^x, x)') # needs sage.symbolic
sage: shell.run_cell('integral(x^2/pi^x, x)')
-x / 2 2 \
-pi *\x *log (pi) + 2*x*log(pi) + 2/
--------------------------------------
3
log (pi)
sage: shell.run_cell("i = var('i')") # needs sage.symbolic
sage: shell.run_cell('sum(i*x^i, i, 0, 10)') # needs sage.symbolic
sage: shell.run_cell("i = var('i')")
sage: shell.run_cell('sum(i*x^i, i, 0, 10)')
10 9 8 7 6 5 4 3 2
10*x + 9*x + 8*x + 7*x + 6*x + 5*x + 4*x + 3*x + 2*x + x
sage: shell.run_cell('StandardTableaux(4).list()') # needs sage.combinat
sage: shell.run_cell('StandardTableaux(4).list()')
[
[ 1 4 1 3
[ 1 3 4 1 2 4 1 2 3 1 3 1 2 2 2
Expand Down Expand Up @@ -115,7 +115,7 @@ def format(self, obj, include=None, exclude=None):

EXAMPLES::

sage: [identity_matrix(i) for i in range(3,7)] # needs sage.modules
sage: [identity_matrix(i) for i in range(3,7)]
[
[1 0 0 0 0 0]
[1 0 0 0 0] [0 1 0 0 0 0]
Expand All @@ -127,8 +127,8 @@ def format(self, obj, include=None, exclude=None):
sage: from sage.repl.interpreter import get_test_shell
sage: shell = get_test_shell()
sage: shell.run_cell('%display ascii_art') # indirect doctest
sage: shell.run_cell("i = var('i')") # needs sage.symbolic
sage: shell.run_cell('sum(i*x^i, i, 0, 10)') # needs sage.symbolic
sage: shell.run_cell("i = var('i')")
sage: shell.run_cell('sum(i*x^i, i, 0, 10)')
10 9 8 7 6 5 4 3 2
10*x + 9*x + 8*x + 7*x + 6*x + 5*x + 4*x + 3*x + 2*x + x
sage: shell.run_cell('%display default')
Expand Down Expand Up @@ -223,11 +223,11 @@ def _ipython_float_precision_changed(change):
sage: shell = get_test_shell()
sage: shell.run_cell('%precision 4')
'%.4f'
sage: shell.run_cell('matrix.options.precision') # indirect doctest # needs sage.modules
sage: shell.run_cell('matrix.options.precision') # indirect doctest
4
sage: shell.run_cell('%precision')
'%r'
sage: shell.run_cell('matrix.options.precision') # indirect doctest # needs sage.modules
sage: shell.run_cell('matrix.options.precision') # indirect doctest
None
"""
try:
Expand Down Expand Up @@ -299,8 +299,8 @@ def __call__(self, obj):
sage: fmt(2)
---- calling ipython formatter ----
'2'
sage: a = identity_matrix(ZZ, 2) # needs sage.modules
sage: fmt([a, a]) # needs sage.modules
sage: a = identity_matrix(ZZ, 2)
sage: fmt([a, a])
---- calling ipython formatter ----
'[\n[1 0] [1 0]\n[0 1], [0 1]\n]'
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/repl/display/jsmol_iframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__(self, jmol, path_to_jsmol=None, width='100%', height='100%'):
EXAMPLES::

sage: from sage.repl.display.jsmol_iframe import JSMolHtml
sage: JSMolHtml(sphere(), width=500, height=300) # needs sage.plot
sage: JSMolHtml(sphere(), width=500, height=300)
JSmol Window 500x300
"""
from sage.repl.rich_output.output_graphics3d import OutputSceneJmol
Expand Down
2 changes: 1 addition & 1 deletion src/sage/repl/display/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def try_format(self, the_list):
TESTS::

sage: from sage.repl.display.util import format_list
sage: print(format_list.try_format( # needs sage.modules
sage: print(format_list.try_format(
....: [matrix([[1, 2, 3, 4], [5, 6, 7, 8]]) for i in range(7)]))
[
[1 2 3 4] [1 2 3 4] [1 2 3 4] [1 2 3 4] [1 2 3 4] [1 2 3 4]
Expand Down
20 changes: 9 additions & 11 deletions src/sage/repl/interface_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def register_all(cls, shell=None):
...
('maxima', 'line')
('maxima', 'cell')
sage: 'gap' in MockShell.magics # needs sage.libs.gap
sage: 'gap' in MockShell.magics
True
sage: 'maxima' in MockShell.magics # needs sage.symbolic
sage: 'maxima' in MockShell.magics
True
"""
if shell is None:
Expand Down Expand Up @@ -156,7 +156,7 @@ def find(cls, name):
EXAMPLES::

sage: from sage.repl.interface_magic import InterfaceMagic
sage: InterfaceMagic.find('gap') # needs sage.libs.gap
sage: InterfaceMagic.find('gap')
<sage.repl.interface_magic.InterfaceMagic object at 0x...>
"""
for magic in cls.all_iter():
Expand All @@ -180,7 +180,7 @@ def __init__(self, name, interface):
EXAMPLES::

sage: from sage.repl.interface_magic import InterfaceMagic
sage: InterfaceMagic.find('gap') # needs sage.libs.gap
sage: InterfaceMagic.find('gap')
<sage.repl.interface_magic.InterfaceMagic object at 0x...>
"""
self._name = name
Expand All @@ -194,7 +194,6 @@ def line_magic_factory(self):

EXAMPLES::

sage: # needs sage.libs.gap
sage: from sage.repl.interface_magic import InterfaceMagic
sage: line_magic = InterfaceMagic.find('gap').line_magic_factory()
sage: output = line_magic('1+1')
Expand All @@ -207,9 +206,9 @@ def line_magic_factory(self):

sage: from sage.repl.interpreter import get_test_shell
sage: shell = get_test_shell()
sage: shell.run_cell('%gap 1+1') # needs sage.libs.gap
sage: shell.run_cell('%gap 1+1')
2
sage: shell.run_cell('%gap?') # needs sage.libs.gap
sage: shell.run_cell('%gap?')
Docstring:
Interact with gap
<BLANKLINE>
Expand All @@ -236,7 +235,6 @@ def cell_magic_factory(self):

EXAMPLES::

sage: # needs sage.libs.gap
sage: from sage.repl.interface_magic import InterfaceMagic
sage: cell_magic = InterfaceMagic.find('gap').cell_magic_factory()
sage: output = cell_magic('', '1+1;')
Expand All @@ -252,15 +250,15 @@ def cell_magic_factory(self):

sage: from sage.repl.interpreter import get_test_shell
sage: shell = get_test_shell()
sage: shell.run_cell('%%gap\nG:=SymmetricGroup(5);\n1+1;Order(G);') # needs sage.libs.gap
sage: shell.run_cell('%%gap\nG:=SymmetricGroup(5);\n1+1;Order(G);')
Sym( [ 1 .. 5 ] )
2
120
sage: shell.run_cell('%%gap foo\n1+1;\n') # needs sage.libs.gap
sage: shell.run_cell('%%gap foo\n1+1;\n')
...File...<string>...
SyntaxError: Interface magics have no options, got "foo"
<BLANKLINE>
sage: shell.run_cell('%%gap?') # needs sage.libs.gap
sage: shell.run_cell('%%gap?')
Docstring:
Interact with gap
<BLANKLINE>
Expand Down
18 changes: 7 additions & 11 deletions src/sage/repl/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,6 @@ def __init__(self, *args, **kwds):

TESTS::

sage: # needs sage.symbolic
sage: from sage.repl.interpreter import interface_shell_embed
sage: shell = interface_shell_embed(maxima)
sage: ift = shell.prefilter_manager.transformers[0]
Expand All @@ -556,7 +555,6 @@ def preparse_imports_from_sage(self, line):

EXAMPLES::

sage: # needs sage.symbolic
sage: from sage.repl.interpreter import interface_shell_embed, InterfaceShellTransformer
sage: from sage.interfaces.maxima_lib import maxima
sage: shell = interface_shell_embed(maxima)
Expand All @@ -575,7 +573,6 @@ def preparse_imports_from_sage(self, line):
Since :issue:`28439`, this also works with more complicated expressions
containing nested parentheses::

sage: # needs sage.libs.gap sage.symbolic
sage: shell = interface_shell_embed(gap)
sage: shell.user_ns = locals()
sage: ift = InterfaceShellTransformer(shell=shell, config=shell.config,
Expand Down Expand Up @@ -612,7 +609,6 @@ def transform(self, line, continue_prompt):

EXAMPLES::

sage: # needs sage.symbolic
sage: from sage.repl.interpreter import interface_shell_embed, InterfaceShellTransformer
sage: shell = interface_shell_embed(maxima)
sage: ift = InterfaceShellTransformer(shell=shell, config=shell.config,
Expand All @@ -624,8 +620,8 @@ def transform(self, line, continue_prompt):
'sage.repl.interpreter.logstr(r"""8""")'
sage: ift.temporary_objects
set()
sage: shell = interface_shell_embed(gap) # needs sage.libs.gap
sage: ift = InterfaceShellTransformer(shell=shell, config=shell.config, # needs sage.libs.gap
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.repl.interpreter.logstr(r"""4""")'
Expand All @@ -635,10 +631,10 @@ def transform(self, line, continue_prompt):
Check that whitespace is not stripped and that special characters are
escaped (:issue:`28439`)::

sage: shell = interface_shell_embed(gap) # needs sage.libs.gap sage.symbolic
sage: ift = InterfaceShellTransformer(shell=shell, config=shell.config, # needs sage.libs.gap sage.symbolic
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) # needs sage.symbolic
sage: ift.transform(r'Print(" -\n\\\\- ");', False)
'sage.repl.interpreter.logstr(r""" -\n\\\\-""")'

sage: # optional - macaulay2
Expand Down Expand Up @@ -675,8 +671,8 @@ def interface_shell_embed(interface):
EXAMPLES::

sage: from sage.repl.interpreter import interface_shell_embed
sage: shell = interface_shell_embed(gap) # needs sage.libs.gap
sage: shell.run_cell('List( [1..10], IsPrime )') # needs sage.libs.gap
sage: shell = interface_shell_embed(gap)
sage: shell.run_cell('List( [1..10], IsPrime )')
[ false, true, true, false, true, false, true, false, false, false ]
<ExecutionResult object at ..., execution_count=... error_before_exec=None error_in_exec=None ...result=[ false, true, true, false, true, false, true, false, false, false ]>
"""
Expand Down
18 changes: 6 additions & 12 deletions src/sage/repl/ipython_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,23 +240,23 @@ def display(self, args):
That means you do not have to use :func:`ascii_art` to get an ASCII art
output::

sage: shell.run_cell("i = var('i')") # needs sage.symbolic
sage: shell.run_cell('sum(i^2*x^i, i, 0, 10)') # needs sage.symbolic
sage: shell.run_cell("i = var('i')")
sage: shell.run_cell('sum(i^2*x^i, i, 0, 10)')
10 9 8 7 6 5 4 3 2
100*x + 81*x + 64*x + 49*x + 36*x + 25*x + 16*x + 9*x + 4*x + x

Then when you want to return to 'textual mode'::

sage: shell.run_cell('%display text plain')
sage: shell.run_cell('%display plain') # shortcut for "text plain"
sage: shell.run_cell('sum(i^2*x^i, i, 0, 10)') # needs sage.symbolic
sage: shell.run_cell('sum(i^2*x^i, i, 0, 10)')
100*x^10 + 81*x^9 + 64*x^8 + 49*x^7 + 36*x^6 + 25*x^5 + 16*x^4 + 9*x^3 + 4*x^2 + x

Sometime you could have to use a special output width and you
could specify it::

sage: shell.run_cell('%display ascii_art')
sage: shell.run_cell('StandardTableaux(4).list()') # needs sage.combinat
sage: shell.run_cell('StandardTableaux(4).list()')
[
[ 1 4 1 3
[ 1 3 4 1 2 4 1 2 3 1 3 1 2 2 2
Expand All @@ -267,7 +267,7 @@ def display(self, args):
3 3 ]
4 , 4 ]
sage: shell.run_cell('%display ascii_art 50')
sage: shell.run_cell('StandardTableaux(4).list()') # needs sage.combinat
sage: shell.run_cell('StandardTableaux(4).list()')
[
[
[ 1 3 4 1 2 4 1 2 3
Expand Down Expand Up @@ -392,7 +392,6 @@ def cython(self, line, cell):

EXAMPLES::

sage: # needs sage.misc.cython
sage: from sage.repl.interpreter import get_test_shell
sage: shell = get_test_shell()
sage: shell.run_cell(
Expand All @@ -410,7 +409,6 @@ def cython(self, line, cell):

Test unrecognized arguments::

sage: # needs sage.misc.cython
sage: shell.run_cell('''
....: %%cython --some-unrecognized-argument
....: print(1)
Expand All @@ -419,7 +417,6 @@ def cython(self, line, cell):

Test ``--help`` is disabled::

sage: # needs sage.misc.cython
sage: shell.run_cell('''
....: %%cython --help
....: print(1)
Expand All @@ -428,7 +425,6 @@ def cython(self, line, cell):

Test ``--view-annotate`` invalid arguments::

sage: # needs sage.misc.cython
sage: shell.run_cell('''
....: %%cython --view-annotate=xx
....: print(1)
Expand All @@ -438,7 +434,6 @@ def cython(self, line, cell):
Test ``--view-annotate=displayhtml`` (note that in a notebook environment
an inline HTML frame will be displayed)::

sage: # needs sage.misc.cython
sage: shell.run_cell('''
....: %%cython --view-annotate=displayhtml
....: print(1)
Expand All @@ -448,7 +443,7 @@ def cython(self, line, cell):

Test ``--view-annotate=webbrowser``::

sage: # needs sage.misc.cython webbrowser
sage: # needs webbrowser
sage: shell.run_cell('''
....: %%cython --view-annotate
....: print(1)
Expand All @@ -467,7 +462,6 @@ def cython(self, line, cell):

Test invalid quotes::

sage: # needs sage.misc.cython
sage: shell.run_cell('''
....: %%cython --a='
....: print(1)
Expand Down
Loading
Loading