This commit is contained in:
Vitor Santos Costa
2018-06-01 13:22:13 +01:00
parent 725a0a692a
commit 94a826efcc
9 changed files with 477 additions and 268 deletions

View File

@@ -34,26 +34,18 @@ jupyter_cell( _Caller, _, Line ) :-
jupyter_cell( _Caller, _, [] ) :- !.
jupyter_cell( Caller, _, Line ) :-
Self := Caller.query,
gated_call( streams(true),
python_query(Self,Line),
Gate,
restreams(Gate)
).
python_query(Self,Line).
restreams(redo) :-
restreams(call) :-
streams(true).
restreams(fail) :-
streams(false).
restreams(answer) :-
streams(false).
restreams(answer).
restreams(exit) :-
streams(false).
restreams(!) :-
streams(false).
restreams(external_exception(_)) :-
streams(false).
restreams(exception) :-
streams(false).
restreams(!).
restreams(external_exception(_)).
restreams(exception).
jupyter_consult(Text) :-
blank( Text ),
@@ -83,7 +75,6 @@ streams(false) :-
streams(false).
streams(true) :-
nb_setval(jupyter_cell, true),
start_low_level_trace,
\+ current_stream('/python/input',_,_),
open('/python/input', read, Input, [alias(user_input),bom(false),script(false)]),
assert( cell_stream( Input) ),

View File

@@ -560,6 +560,8 @@ class YAPRun:
pg = jupyter_query( self, program, squery)
self.query = self.yapeng.query(pg)
self.query.answer = {}
self.yapeng.mgoal(streams(False),"user", True)
self.yapeng.mgoal(streams(True),"user", True)
while self.query.next():
answer = self.query.answer
found = True
@@ -568,6 +570,7 @@ class YAPRun:
if self.query.port == "exit":
self.os = None
sys.stderr.writeln('Done, with', self.bindings)
self.yapeng.mgoal(streams(False),"user", True)
return True,self.bindings
if stop or howmany == self.iterations:
return True, self.bindings
@@ -576,12 +579,14 @@ class YAPRun:
else:
self.os = None
self.query.close()
self.query = None
`` self.query = None
sys.stderr.write('Fail\n')
return True,self.bindings
self.yapeng.mgoal(streams(False),"user", True)
return True,self.bindings
except Exception as e:
sys.stderr.write('Exception after', self.bindings, '\n')
has_raised = True
self.yapeng.mgoal(streams(False),"user", True)
return False,[]
@@ -628,6 +633,7 @@ class YAPRun:
# ask = True
# launch the query
info = interactiveshell.ExecutionInfo(
raw_cell, store_history, silent, shell_futures)
@@ -731,11 +737,10 @@ class YAPRun:
# run the new command using the given tracer
#
# self.yapeng.mgoal(streams(True),"user", True)
# tracer.runfunc(f,self,cell,state)
self.jupyter_query( cell )
# state = tracer.runfunc(jupyter_query( self, cell ) )
# self.yapeng.mgoal(streams(False),"user", True)
self.yapeng.mgoal(streams(False),"user", True)
self.shell.last_execution_succeeded = True
self.result.result = (True, dicts)