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

some minor details in interfaces #35530

Merged
merged 1 commit into from
Apr 23, 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
3 changes: 1 addition & 2 deletions src/sage/interfaces/axiom.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,14 +684,13 @@ def comma(self, *args):
[2,3,4]
sage: _.type() #optional - axiom
Tuple PositiveInteger

"""
P = self._check_valid()
args = list(args)
for i, arg in enumerate(args):
if not isinstance(arg, AxiomElement) or arg.parent() is not P:
args[i] = P(arg)
cmd = "(" + ",".join([x.name() for x in [self]+args]) + ")"
cmd = "(" + ",".join(x.name() for x in [self] + args) + ")"
return P(cmd)

def _latex_(self):
Expand Down
40 changes: 16 additions & 24 deletions src/sage/interfaces/expect.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
- François Bissey, Bill Page, Jeroen Demeyer (2015-12-09): Upgrade to
pexpect 4.0.1 + patches, see :trac:`10295`.
"""

# ****************************************************************************
# Copyright (C) 2005 William Stein <wstein@gmail.com>
#
Expand All @@ -38,7 +37,6 @@
# (at your option) any later version.
# https://www.gnu.org/licenses/
# ****************************************************************************

import io
import os
import re
Expand Down Expand Up @@ -219,7 +217,7 @@ def set_server_and_command(self, server=None, command=None, server_tmpdir=None,

def server(self):
"""
Returns the server used in this interface.
Return the server used in this interface.

EXAMPLES::

Expand All @@ -232,7 +230,7 @@ def server(self):

def command(self):
"""
Returns the command used in this interface.
Return the command used in this interface.

EXAMPLES::

Expand Down Expand Up @@ -1082,11 +1080,11 @@ def interrupt(self, tries=5, timeout=2.0, quit_on_fail=True):
# BEGIN Synchronization code.
###########################################################################

def _before(self, encoding=None, errors=None):
def _before(self, encoding=None, errors=None) -> str:
r"""
Return the previous string that was sent through the interface.

Returns ``str`` objects on both Python 2 and Python 3.
This returns a ``str`` object.

The ``encoding`` and ``errors`` arguments are passed to
:func:`sage.misc.cpython.bytes_to_str`.
Expand Down Expand Up @@ -1126,7 +1124,7 @@ def _after(self, encoding=None, errors=None):

return after

def _readline(self, size=-1, encoding=None, errors=None):
def _readline(self, size=-1, encoding=None, errors=None) -> str:
r"""
Wraps ``spawn.readline`` to pass the return values through
``bytes_to_str``, like `Expect._before` and `Expect._after`.
Expand All @@ -1139,7 +1137,6 @@ def _readline(self, size=-1, encoding=None, errors=None):
sage: singular._readline()
'2\r\n'
"""

return bytes_to_str(self._expect.readline(size=size), encoding, errors)

def _interrupt(self):
Expand All @@ -1166,12 +1163,10 @@ def _expect_expr(self, expr=None, timeout=None):

INPUT:


- ``expr`` - None or a string or list of strings
- ``expr`` -- None or a string or list of strings
(default: None)

- ``timeout`` - None or a number (default: None)

- ``timeout`` -- None or a number (default: None)

EXAMPLES:

Expand Down Expand Up @@ -1345,7 +1340,6 @@ def eval(self, code, strip=True, synchronize=False, locals=None, allow_use_file=
"""
INPUT:


- ``code`` -- text to evaluate

- ``strip`` -- bool; whether to strip output prompts,
Expand Down Expand Up @@ -1393,8 +1387,8 @@ def eval(self, code, strip=True, synchronize=False, locals=None, allow_use_file=
self._eval_using_file_cutoff and len(code) > self._eval_using_file_cutoff):
return self._eval_line_using_file(code)
elif split_lines:
return '\n'.join([self._eval_line(L, allow_use_file=allow_use_file, **kwds)
for L in code.split('\n') if L != ''])
return '\n'.join(self._eval_line(L, allow_use_file=allow_use_file, **kwds)
for L in code.split('\n') if L)
else:
return self._eval_line(code, allow_use_file=allow_use_file, **kwds)
# DO NOT CATCH KeyboardInterrupt, as it is being caught
Expand Down Expand Up @@ -1512,7 +1506,9 @@ def __init__(self, parent, value, is_name=False, name=None):

def __hash__(self):
"""
Returns the hash of self. This is a default implementation of hash
Return the hash of self.

This is a default implementation of hash
which just takes the hash of the string of self.
"""
return hash('%s%s' % (self, self._session_number))
Expand Down Expand Up @@ -1544,7 +1540,7 @@ def __del__(self):
if P is not None:
P.clear(self._name)

except (RuntimeError, ExceptionPexpect): # needed to avoid infinite loops in some rare cases
except (RuntimeError, ExceptionPexpect): # needed to avoid infinite loops in some rare cases
pass

# def _sage_repr(self):
Expand All @@ -1563,11 +1559,11 @@ def __init__(self, interface, silent=False, stdout=None):

INPUT:

- ``interface`` - the interface whose communication shall be dumped.
- ``interface`` -- the interface whose communication shall be dumped.

- ``silent`` - if ``True`` this context does nothing
- ``silent`` -- if ``True`` this context does nothing

- ``stdout`` - optional parameter for alternative stdout device (default: ``None``)
- ``stdout`` -- optional parameter for alternative stdout device (default: ``None``)

EXAMPLES::

Expand Down Expand Up @@ -1621,7 +1617,3 @@ def __exit__(self, typ, value, tb):
self.interface._expect.logfile.flush()
self.stdout.write("\n")
self.interface._expect.logfile = self._logfile_backup


def console(cmd):
os.system(cmd)
2 changes: 1 addition & 1 deletion src/sage/interfaces/fricas.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ def get_string(self, var):
We test that strings are returned properly::

sage: r = fricas.get_string('concat([concat(string(i)," ") for i in 0..299])') # optional - fricas
sage: r == " ".join([str(i) for i in range(300)]) + ' ' # optional - fricas
sage: r == " ".join(str(i) for i in range(300)) + ' ' # optional - fricas
True

sage: fricas.get_string('concat([string(1) for i in 1..5])') == "1"*5 # optional - fricas
Expand Down
10 changes: 4 additions & 6 deletions src/sage/interfaces/magma.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,15 @@
#
# The full text of the GPL is available at:
#
# http://www.gnu.org/licenses/
# https://www.gnu.org/licenses/
# ****************************************************************************
from __future__ import annotations
import re
import sys
import os

from sage.structure.parent import Parent
from .expect import console, Expect, ExpectElement, ExpectFunction, FunctionElement
from .expect import Expect, ExpectElement, ExpectFunction, FunctionElement
PROMPT = ">>>"

SAGE_REF = "_sage_ref"
Expand Down Expand Up @@ -252,7 +253,6 @@ def extcode_dir(iface=None):
shutil.copytree('%s/magma/' % SAGE_EXTCODE, tmp + '/data')
EXTCODE_DIR = "%s/data/" % tmp
else:
import os
tmp = iface._remote_tmpdir()
command = 'scp -q -r "%s/magma/" "%s:%s/data" 1>&2 2>/dev/null' % (SAGE_EXTCODE, iface._server, tmp)
try:
Expand Down Expand Up @@ -330,7 +330,6 @@ def __init__(self, script_subdirectory=None,
Magma
"""
if command is None:
import os
command = os.getenv('SAGE_MAGMA_COMMAND') or 'magma'

if not user_config:
Expand All @@ -339,7 +338,6 @@ def __init__(self, script_subdirectory=None,
# Obtain the parameters from the environment, to allow the magma = Magma() phrase
# to work with non-default parameters.
if seed is None:
import os
seed = os.getenv('SAGE_MAGMA_SEED')

Expect.__init__(self,
Expand Down Expand Up @@ -2787,7 +2785,7 @@ def magma_console():
from sage.repl.rich_output.display_manager import get_display_manager
if not get_display_manager().is_in_terminal():
raise RuntimeError('Can use the console only in the terminal. Try %%magma magics instead.')
console('magma')
os.system('magma')


class MagmaGBLogPrettyPrinter:
Expand Down