diff --git a/packages/python/pyio.c b/packages/python/pyio.c index e0a7813ce..e5f288fe0 100644 --- a/packages/python/pyio.c +++ b/packages/python/pyio.c @@ -171,7 +171,7 @@ static bool pygetLine(StreamDesc *rl_iostream, int sno) { PyObject_GetAttrString(s->u.private_data, "readline"); if (!readl) { readl = - PyObject_GetAttrString(s->u.private_data, "read"); + PyObject_GetAttrString(s->u.private_data, "input"); } if (readl) user_line = PyObject_CallFunctionObjArgs(readl, diff --git a/packages/python/yap_kernel/yap_ipython/yapi.py b/packages/python/yap_kernel/yap_ipython/yapi.py index 56c286a16..882e3723c 100644 --- a/packages/python/yap_kernel/yap_ipython/yapi.py +++ b/packages/python/yap_kernel/yap_ipython/yapi.py @@ -13,7 +13,6 @@ from IPython.core.inputtransformer import * from IPython.core.interactiveshell import * from ipython_genutils.py3compat import builtin_mod -import copy import json from yap_kernel.displayhook import ZMQShellDisplayHook @@ -536,14 +535,13 @@ class YAPRun(InteractiveShell): self.engine.mgoal(errors(self,text),"user",True) return self.errors - def prolog(self, ccell, result): + def prolog(self, program, squery, howmany, result): # # construct a self.query from a one-line string # self.q is opaque to Python try: # sys.settrace(tracefunc) - (program, squery, _, howmany) = ccell if self.q and self.os == (program,squery): howmany += self.iterations else: @@ -553,6 +551,7 @@ class YAPRun(InteractiveShell): self.answers = [] result.result = [] self.os = (program,squery) + self.iterations = 0 pg = jupyter_query(self,program,squery) self.q = Query(self.engine, pg) for v in self.q: @@ -671,7 +670,6 @@ class YAPRun(InteractiveShell): except: magic = cell[2:].strip() body = "" - linec = False try: [magic,line] = magic.split(maxsplit=1) except: @@ -680,7 +678,6 @@ class YAPRun(InteractiveShell): result.result = self.shell.run_cell_magic(magic, line, body) return else: - linec = True rcell = cell[1:].strip() try: [magic,cell] = rcell.split(maxsplit = 1, sep = '\n') @@ -697,9 +694,9 @@ class YAPRun(InteractiveShell): # Give the displayhook a reference to our ExecutionResult so it # can fill in the output value. self.shell.displayhook.exec_result = result - ccell = self.prolog_cell(cell) - (program,squery,_ ,howmany) = ccell - if howmany == 0 and not program: + (program,squery,_ ,howmany) = self.prolog_cell(cell) + print(program, squery, howmany) + if howmany <= 0 and not program: return result if self.syntaxErrors(program+squery+".\n") : result.result = [] @@ -723,7 +720,7 @@ class YAPRun(InteractiveShell): # run the new command using the given tracer # # tracer.runfunc(f,self,cell,state) - answers = self.prolog( ccell, result ) + answers = self.prolog( program, squery, howmany, result ) # state = tracer.runfunc(hist # er_query( self, cell ) ) except Exception as e: @@ -731,6 +728,7 @@ class YAPRun(InteractiveShell): try: (etype, value, tb) = e traceback.print_exception(etype, value, tb) + self.engine.mgoal(streams(False),"user", True) except: print(e) @@ -760,71 +758,74 @@ class YAPRun(InteractiveShell): def pcell(s): - """ - Trasform a text into program+query. A query is the - last line if the last line is non-empty and does not terminate - on a dot. You can also finish with + """ + Trasform a text into program+query. A query is the + last line if the last line is non-empty and does not terminate + on a dot. You can also finish with - - `*`: you request all solutions - - ';'[N]: you want an answer; optionally you want N answers + - `*`: you request all solutions + - ';'[N]: you want an answer; optionally you want N answers - If the line terminates on a `*/` or starts on a `%` we assume the line - is a comment. - """ - try: - sl = s.splitlines() - l = len(sl) - i = 0 - while i