From b4201dd0f3cc000c3570c3be645a5aa6ede9853c Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Sat, 21 Jul 2018 23:29:01 +0100 Subject: [PATCH] jupyter --- packages/python/py2pl.c | 4 ++-- packages/python/pyio.c | 15 ++++++++------- packages/python/swig/prolog/yapi.yap | 2 +- .../yap_kernel/yap_ipython/prolog/jupyter.yap | 3 ++- packages/python/yap_kernel/yap_ipython/yapi.py | 4 ++++ 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/python/py2pl.c b/packages/python/py2pl.c index 919a5f35a..3cf2795c6 100644 --- a/packages/python/py2pl.c +++ b/packages/python/py2pl.c @@ -158,9 +158,9 @@ else if (PyDict_Check(pVal)) { Term t0[2], to; t0[0] = python_to_term__(key); t0[1] = python_to_term__(value); - to = Yap_MkApplTerm(FunctorEq, 2, t0); + to = Yap_MkApplTerm(FunctorModule, 2, t0); if (left--) { - t = Yap_MkNewApplTerm(FunctorOr, 2); + t = Yap_MkNewApplTerm(FunctorComma, 2); *opt = t; CELL *pt = RepAppl(t) + 1; pt[0] = to; diff --git a/packages/python/pyio.c b/packages/python/pyio.c index 7b600ffad..28aa622e3 100644 --- a/packages/python/pyio.c +++ b/packages/python/pyio.c @@ -130,14 +130,15 @@ static bool py_close(int sno) { static bool getLine(StreamDesc *rl_iostream, int sno) { char *myrl_line = NULL; // term_t ctk = python_acquire_GIL(); - PyObject_Print(rl_iostream->u.private_data, stderr, 0); - /* window of vulnerability opened */ - PyObject *readl = - PyObject_GetAttrString(rl_iostream->u.private_data, "readline"); - PyObject_Print(readl, stderr, 0); + PyObject *readl = + PythonLookup("input", Py_None); + PyObject_Print(readl, stderr, 0);fprintf(stderr," input\n"); - myrl_line = PyUnicode_AsUTF8( - PyObject_CallFunctionObjArgs(readl, rl_iostream->u.private_data, NULL)); + + PyObject *user_inp = PyObject_CallFunction(readl,NULL); + PyObject_Print(user_inp, stderr, 0);fprintf(stderr," input\n"); + myrl_line = PyUnicode_AsUTF8(user_inp); + //PyObject_Print(myrl_line, stderr, 0);fprintf(stderr," myrl_line\n"); // python_release_GIL(ctk); PyObject *err; if ((err = PyErr_Occurred())) { diff --git a/packages/python/swig/prolog/yapi.yap b/packages/python/swig/prolog/yapi.yap index e5e0322ef..76dea4574 100644 --- a/packages/python/swig/prolog/yapi.yap +++ b/packages/python/swig/prolog/yapi.yap @@ -72,7 +72,7 @@ python_query( Caller, String ) :- atomic_to_term( String, Goal, VarNames ), query_to_answer( Goal, VarNames, Status, Bindings), atom_to_string( Status, SStatus ), - Caller.port := SStatus, + % Caller.port := SStatus, write_query_answer( Bindings ), nl(user_error), Caller.answer := {}, diff --git a/packages/python/yap_kernel/yap_ipython/prolog/jupyter.yap b/packages/python/yap_kernel/yap_ipython/prolog/jupyter.yap index 4bcca17f4..d9696d51f 100644 --- a/packages/python/yap_kernel/yap_ipython/prolog/jupyter.yap +++ b/packages/python/yap_kernel/yap_ipython/prolog/jupyter.yap @@ -37,7 +37,8 @@ jupyter_cell( _Caller, _, `` ) :- !. jupyter_cell( _Caller, _, Line ) :- blank( Line ), !. -jupyter_cell(Self, _, Line ) :- +jupyter_cell(Caller, _, Line ) :- + Self := Caller.query, catch( python_query(Self,Line), E=error(A,B), diff --git a/packages/python/yap_kernel/yap_ipython/yapi.py b/packages/python/yap_kernel/yap_ipython/yapi.py index 562f2bd34..3dfe95be0 100644 --- a/packages/python/yap_kernel/yap_ipython/yapi.py +++ b/packages/python/yap_kernel/yap_ipython/yapi.py @@ -519,6 +519,10 @@ class YAPRun: self.shell.yapeng = self.yapeng self._get_exc_info = shell._get_exc_info + + def showtraceback(self, tuple): + return None + def syntaxErrors(self, text): """Return whether a legal query """