From 234ff27fed2686a30486c19cddce7ef85092bc9d Mon Sep 17 00:00:00 2001 From: Matt Wala <wala1@illinois.edu> Date: Thu, 16 Feb 2017 11:41:47 -0600 Subject: [PATCH] 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. --- pymbolic/interop/maxima.py | 31 ++++++++++++++++++------------- test/test_maxima.py | 3 --- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/pymbolic/interop/maxima.py b/pymbolic/interop/maxima.py index 6021486..ef1f61f 100644 --- a/pymbolic/interop/maxima.py +++ b/pymbolic/interop/maxima.py @@ -270,10 +270,21 @@ class MaximaKernel: def _initialize(self): + PEXPECT_SHELL = "bash" + + PRE_MAXIMA_COMMANDS = ( + # Makes long line inputs possible. + ("stty -icanon",) + ) + import pexpect - self.child = pexpect.spawn(self.executable, - ["--disable-readline", "-q"], - timeout=self.timeout) + self.child = pexpect.spawn(PEXPECT_SHELL, timeout=self.timeout, echo=False) + for command in PRE_MAXIMA_COMMANDS: + self.child.sendline(command) + + self.child.sendline(" ".join( + [self.executable, "--disable-readline", "-q"])) + self.current_prompt = 0 self._expect_prompt(IN_PROMPT_RE) @@ -326,9 +337,11 @@ class MaximaKernel: self._initialize() def shutdown(self): - # tty echo appears to cause waitpid() to block on OS X; turn it off. - self.child.setecho(False) self._sendline("quit();") + # Exit shell + self._sendline("exit") + from pexpect import EOF + self.child.expect(EOF) self.child.wait() # }}} @@ -342,11 +355,6 @@ class MaximaKernel: def _sendline(self, l): self._check_debug() - - if len(l) > 2048: - raise RuntimeError("input lines longer than 2048 characters " - "don't work, refusing") - self.child.sendline(l) def exec_str(self, s, enforce_prompt_numbering=True): @@ -367,9 +375,6 @@ class MaximaKernel: print("[MAXIMA INPUT]", cmd) self._sendline(cmd) - s_echo = self.child.readline().decode() - - assert s_echo.strip() == cmd.strip() self._expect_prompt(OUT_PROMPT_RE, enforce_prompt_numbering=enforce_prompt_numbering) diff --git a/test/test_maxima.py b/test/test_maxima.py index 94991c0..a2ec028 100644 --- a/test/test_maxima.py +++ b/test/test_maxima.py @@ -23,8 +23,6 @@ THE SOFTWARE. """ import pytest -from pytools.test import mark_test - from pymbolic.interop.maxima import MaximaKernel @@ -123,7 +121,6 @@ def test_diff(): diff(parse("sqrt(x**2+y**2)"), parse("x")) -@mark_test.xfail def test_long_command(knl): from pymbolic.interop.maxima import set_debug set_debug(4) -- GitLab