From a39483efc0967d2b4bf6fb883a2639db3fcdb9d1 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Wed, 15 Feb 2017 20:16:54 -0600 Subject: [PATCH 1/9] maxima.shutdown(): Fix OS X interop by turning off echo before sending quit command (closes #3). --- pymbolic/interop/maxima.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pymbolic/interop/maxima.py b/pymbolic/interop/maxima.py index 77f1aab..6021486 100644 --- a/pymbolic/interop/maxima.py +++ b/pymbolic/interop/maxima.py @@ -326,6 +326,8 @@ 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();") self.child.wait() -- GitLab From 234ff27fed2686a30486c19cddce7ef85092bc9d Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 16 Feb 2017 11:41:47 -0600 Subject: [PATCH 2/9] 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 From 0afaefa53ab549390e670bc1fb386d6181060f1b Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 16 Feb 2017 11:45:22 -0600 Subject: [PATCH 3/9] Fix fixture deprecation warning. --- test/test_maxima.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_maxima.py b/test/test_maxima.py index a2ec028..7dcfa2e 100644 --- a/test/test_maxima.py +++ b/test/test_maxima.py @@ -36,7 +36,8 @@ def test_kernel(): knl.shutdown() -def pytest_funcarg__knl(request): +@pytest.fixture +def knl(request): pytest.importorskip("pexpect") knl = MaximaKernel() -- GitLab From 29e9d442e763c3df721c294ecfc3c107a576a3a5 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 16 Feb 2017 11:48:47 -0600 Subject: [PATCH 4/9] flake8 fix --- pymbolic/interop/maxima.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pymbolic/interop/maxima.py b/pymbolic/interop/maxima.py index ef1f61f..bfd8fe3 100644 --- a/pymbolic/interop/maxima.py +++ b/pymbolic/interop/maxima.py @@ -270,9 +270,9 @@ class MaximaKernel: def _initialize(self): - PEXPECT_SHELL = "bash" + PEXPECT_SHELL = "bash" # noqa - PRE_MAXIMA_COMMANDS = ( + PRE_MAXIMA_COMMANDS = ( # noqa # Makes long line inputs possible. ("stty -icanon",) ) -- GitLab From c4f493e9b97032580a2cfd190e6ffb54d78e4981 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 16 Feb 2017 12:24:15 -0600 Subject: [PATCH 5/9] Fail faster if maxima is not found. --- pymbolic/interop/maxima.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pymbolic/interop/maxima.py b/pymbolic/interop/maxima.py index ef1f61f..e2daa46 100644 --- a/pymbolic/interop/maxima.py +++ b/pymbolic/interop/maxima.py @@ -282,6 +282,19 @@ class MaximaKernel: for command in PRE_MAXIMA_COMMANDS: self.child.sendline(command) + # {{{ check for maxima command + + self.child.sendline( + "hash \"{command}\"; echo $?".format(command=self.executable)) + + hash_output = self.child.expect(["0\r\n", "1\r\n"]) + if hash_output != 0: + raise RuntimeError( + "maxima executable \"{command}\" not found" + .format(command=self.executable)) + + # }}} + self.child.sendline(" ".join( [self.executable, "--disable-readline", "-q"])) -- GitLab From ff86d0e2e705ef2d2344f4f6a9a9f737bac9aa98 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 16 Feb 2017 12:31:14 -0600 Subject: [PATCH 6/9] Add a maxima tag to the Conda builds (for now). --- .gitlab-ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index af88cbb..0c49e57 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,6 +15,8 @@ Python 2.7 Conda: - CONDA_ENVIRONMENT=.test-py2.yml - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project-within-miniconda.sh - ". ./build-and-test-py-project-within-miniconda.sh" + tags: + - maxima except: - tags @@ -35,6 +37,8 @@ Python 3.5 Conda: - CONDA_ENVIRONMENT=.test-py3.yml - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project-within-miniconda.sh - ". ./build-and-test-py-project-within-miniconda.sh" + tags: + - maxima except: - tags -- GitLab From f8aa165db0e0c9c60c436d6e9271a9258e18e515 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 16 Feb 2017 12:35:38 -0600 Subject: [PATCH 7/9] Surround executable in quotes. --- pymbolic/interop/maxima.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymbolic/interop/maxima.py b/pymbolic/interop/maxima.py index 6ca16f3..1486ff7 100644 --- a/pymbolic/interop/maxima.py +++ b/pymbolic/interop/maxima.py @@ -296,7 +296,7 @@ class MaximaKernel: # }}} self.child.sendline(" ".join( - [self.executable, "--disable-readline", "-q"])) + ['"' + self.executable + '"', "--disable-readline", "-q"])) self.current_prompt = 0 self._expect_prompt(IN_PROMPT_RE) -- GitLab From 4a4a5d760698ccd6fa7ba331a115f89812789b42 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 16 Feb 2017 12:54:48 -0600 Subject: [PATCH 8/9] Test knl.restart(). --- pymbolic/interop/maxima.py | 3 +-- test/test_maxima.py | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pymbolic/interop/maxima.py b/pymbolic/interop/maxima.py index 1486ff7..2dabf2b 100644 --- a/pymbolic/interop/maxima.py +++ b/pymbolic/interop/maxima.py @@ -345,8 +345,7 @@ class MaximaKernel: # {{{ execution control def restart(self): - from signal import SIGKILL - self.child.kill(SIGKILL) + self.child.close(force=True) self._initialize() def shutdown(self): diff --git a/test/test_maxima.py b/test/test_maxima.py index 7dcfa2e..7ddbb68 100644 --- a/test/test_maxima.py +++ b/test/test_maxima.py @@ -128,6 +128,15 @@ def test_long_command(knl): knl.eval_str("+".join(["1"]*16384)) +def test_restart(knl): + pytest.importorskip("pexpect") + + knl = MaximaKernel() + knl.restart() + knl.eval_str("1") + knl.shutdown() + + if __name__ == "__main__": import sys if len(sys.argv) > 1: -- GitLab From 47f54efb29db6b8b7d128fd163420f8a86a1a5d7 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 16 Feb 2017 19:20:20 -0600 Subject: [PATCH 9/9] Add an Apple test, make conda tests run on Linux. --- .gitlab-ci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0c49e57..ec9e960 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,6 +17,7 @@ Python 2.7 Conda: - ". ./build-and-test-py-project-within-miniconda.sh" tags: - maxima + - linux except: - tags @@ -39,6 +40,18 @@ Python 3.5 Conda: - ". ./build-and-test-py-project-within-miniconda.sh" tags: - maxima + - linux + except: + - tags + +Python 3.5 Apple: + script: + - CONDA_ENVIRONMENT=.test-py3.yml + - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-and-test-py-project-within-miniconda.sh + - ". ./build-and-test-py-project-within-miniconda.sh" + tags: + - maxima + - apple except: - tags -- GitLab