Skip to content
Snippets Groups Projects
Commit 234ff27f authored by Matt Wala's avatar Matt Wala
Browse files

Fix maxima interop to work on OS X and with long lines:

1. Disables echo, which seems to cause waitpid() to block on OS X.
2. Fixes long line handling via stty -icanon.
parent a39483ef
No related branches found
No related tags found
No related merge requests found
...@@ -270,10 +270,21 @@ class MaximaKernel: ...@@ -270,10 +270,21 @@ class MaximaKernel:
def _initialize(self): def _initialize(self):
PEXPECT_SHELL = "bash"
PRE_MAXIMA_COMMANDS = (
# Makes long line inputs possible.
("stty -icanon",)
)
import pexpect import pexpect
self.child = pexpect.spawn(self.executable, self.child = pexpect.spawn(PEXPECT_SHELL, timeout=self.timeout, echo=False)
["--disable-readline", "-q"], for command in PRE_MAXIMA_COMMANDS:
timeout=self.timeout) self.child.sendline(command)
self.child.sendline(" ".join(
[self.executable, "--disable-readline", "-q"]))
self.current_prompt = 0 self.current_prompt = 0
self._expect_prompt(IN_PROMPT_RE) self._expect_prompt(IN_PROMPT_RE)
...@@ -326,9 +337,11 @@ class MaximaKernel: ...@@ -326,9 +337,11 @@ class MaximaKernel:
self._initialize() self._initialize()
def shutdown(self): def shutdown(self):
# tty echo appears to cause waitpid() to block on OS X; turn it off.
self.child.setecho(False)
self._sendline("quit();") self._sendline("quit();")
# Exit shell
self._sendline("exit")
from pexpect import EOF
self.child.expect(EOF)
self.child.wait() self.child.wait()
# }}} # }}}
...@@ -342,11 +355,6 @@ class MaximaKernel: ...@@ -342,11 +355,6 @@ class MaximaKernel:
def _sendline(self, l): def _sendline(self, l):
self._check_debug() self._check_debug()
if len(l) > 2048:
raise RuntimeError("input lines longer than 2048 characters "
"don't work, refusing")
self.child.sendline(l) self.child.sendline(l)
def exec_str(self, s, enforce_prompt_numbering=True): def exec_str(self, s, enforce_prompt_numbering=True):
...@@ -367,9 +375,6 @@ class MaximaKernel: ...@@ -367,9 +375,6 @@ class MaximaKernel:
print("[MAXIMA INPUT]", cmd) print("[MAXIMA INPUT]", cmd)
self._sendline(cmd) self._sendline(cmd)
s_echo = self.child.readline().decode()
assert s_echo.strip() == cmd.strip()
self._expect_prompt(OUT_PROMPT_RE, self._expect_prompt(OUT_PROMPT_RE,
enforce_prompt_numbering=enforce_prompt_numbering) enforce_prompt_numbering=enforce_prompt_numbering)
......
...@@ -23,8 +23,6 @@ THE SOFTWARE. ...@@ -23,8 +23,6 @@ THE SOFTWARE.
""" """
import pytest import pytest
from pytools.test import mark_test
from pymbolic.interop.maxima import MaximaKernel from pymbolic.interop.maxima import MaximaKernel
...@@ -123,7 +121,6 @@ def test_diff(): ...@@ -123,7 +121,6 @@ def test_diff():
diff(parse("sqrt(x**2+y**2)"), parse("x")) diff(parse("sqrt(x**2+y**2)"), parse("x"))
@mark_test.xfail
def test_long_command(knl): def test_long_command(knl):
from pymbolic.interop.maxima import set_debug from pymbolic.interop.maxima import set_debug
set_debug(4) set_debug(4)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment