From e800dcad7fc034346967aed93d353c534ec25af8 Mon Sep 17 00:00:00 2001 From: "Takeshi Ikuma (LSUHSC)" Date: Tue, 20 Aug 2024 20:52:26 -0500 Subject: [PATCH 1/2] Changed REPLWrapper to accept args argument --- metakernel/replwrap.py | 6 ++++-- metakernel/tests/test_replwrap.py | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/metakernel/replwrap.py b/metakernel/replwrap.py index 4de060e..f95398f 100644 --- a/metakernel/replwrap.py +++ b/metakernel/replwrap.py @@ -47,6 +47,7 @@ class REPLWrapper(object): we need to interrupt a continuation prompt. :param bool echo: Whether the child should echo, or in the case of Windows, whether the child does echo. + :param list args: Additional arguments to the spawning command """ def __init__(self, cmd_or_spawn, prompt_regex, prompt_change_cmd, @@ -56,9 +57,10 @@ def __init__(self, cmd_or_spawn, prompt_regex, prompt_change_cmd, extra_init_cmd=None, prompt_emit_cmd=None, force_prompt_on_continuation=False, - echo=False): + echo=False, + args=[]): if isinstance(cmd_or_spawn, basestring): - self.child = pexpect.spawnu(cmd_or_spawn, echo=echo, + self.child = pexpect.spawnu(cmd_or_spawn, args, echo=echo, codec_errors="ignore", encoding="utf-8") else: diff --git a/metakernel/tests/test_replwrap.py b/metakernel/tests/test_replwrap.py index bb76e4f..09647bc 100644 --- a/metakernel/tests/test_replwrap.py +++ b/metakernel/tests/test_replwrap.py @@ -95,6 +95,13 @@ def test_bracketed_paste(self): res = bash.run_command("echo '1 2\n3 4'") self.assertEqual(res.strip().splitlines(), ['1 2', '3 4']) + def test_spawn_args(self): + p = replwrap.REPLWrapper(sys.executable, ">>> ", + "import sys; sys.ps1={0!r}; sys.ps2={1!r}", + args=['-i', '-c', 'x=4+7']) + res = p.run_command('x-11') + assert res.strip() == '0' + if __name__ == '__main__': unittest.main() From 303f2fd665d8e8138199f34a9eec66ded63f643c Mon Sep 17 00:00:00 2001 From: "Takeshi Ikuma (LSUHSC)" Date: Tue, 20 Aug 2024 20:57:09 -0500 Subject: [PATCH 2/2] non-pty spawn to treat the command and args in the same manner as pt_ spawn does --- metakernel/pexpect.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/metakernel/pexpect.py b/metakernel/pexpect.py index f901b3b..05c4ac3 100644 --- a/metakernel/pexpect.py +++ b/metakernel/pexpect.py @@ -24,8 +24,10 @@ def spawn(command, args=[], timeout=30, maxread=2000, ''' codec_errors = kwargs.get('codec_errors', kwargs.get('errors', 'strict')) if pty is None: - command = shlex.split(command, posix=os.name == 'posix') - command += args + if args == []: + command = shlex.split(command, posix=os.name == 'posix') + else: + command += args child = PopenSpawn(command, timeout=timeout, maxread=maxread, searchwindowsize=searchwindowsize, logfile=logfile, cwd=cwd, env=env,