From b2156aad2d84b815f2a171c9c86a1f01fd199f6b Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 21 Sep 2016 14:55:09 -0500 Subject: [PATCH] python swig work --- packages/python/__init__.py | 3 +++ packages/python/__main__.py | 3 +++ packages/python/examples/plot.py | 10 ++++++++++ packages/python/pytils.yap | 1 + packages/python/yap_kernel/yap_kernel.py | 5 +++-- packages/python/yapex.py | 8 +++++--- 6 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 packages/python/__init__.py create mode 100644 packages/python/__main__.py create mode 100644 packages/python/examples/plot.py create mode 100644 packages/python/pytils.yap diff --git a/packages/python/__init__.py b/packages/python/__init__.py new file mode 100644 index 000000000..ae45c83a8 --- /dev/null +++ b/packages/python/__init__.py @@ -0,0 +1,3 @@ +"""A Prolog kernel for Jupyter""" + +__version__ = '0.0.1' diff --git a/packages/python/__main__.py b/packages/python/__main__.py new file mode 100644 index 000000000..f7e95ef82 --- /dev/null +++ b/packages/python/__main__.py @@ -0,0 +1,3 @@ +if __name__ == '__main__': + from yapkernel import kernelapp as app + app.launch_new_instance() diff --git a/packages/python/examples/plot.py b/packages/python/examples/plot.py new file mode 100644 index 000000000..77a5c6809 --- /dev/null +++ b/packages/python/examples/plot.py @@ -0,0 +1,10 @@ + +:- [library(python)]. + +main :- +:= import matplotlib.pyplot, +:= Plt = ematplotlib.pyplot, +Plt.plot([1,2,3,4]), +Plt.ylabel(`some numbers`), +Plt.show(). + diff --git a/packages/python/pytils.yap b/packages/python/pytils.yap new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/packages/python/pytils.yap @@ -0,0 +1 @@ + diff --git a/packages/python/yap_kernel/yap_kernel.py b/packages/python/yap_kernel/yap_kernel.py index 2169a27d0..11fb46730 100644 --- a/packages/python/yap_kernel/yap_kernel.py +++ b/packages/python/yap_kernel/yap_kernel.py @@ -23,7 +23,7 @@ def eprint(*args, **kwargs): class YAPKernel(IPythonKernel): - implementation = 'MetaKernel YAP' + implementation = 'YAP Kernel' implementation_version = '1.0' language = 'text' language_version = '0.1' @@ -88,7 +88,8 @@ class YAPKernel(IPythonKernel): else: i = bind.numberVars(i, True) print(name.text() + " = " + bind.text()) - print("yes") + else: + print("yes") if self.q.deterministic(): self.closeq() return diff --git a/packages/python/yapex.py b/packages/python/yapex.py index ef0996be5..f42c58a4e 100644 --- a/packages/python/yapex.py +++ b/packages/python/yapex.py @@ -1,3 +1,4 @@ + import yap import sys @@ -50,8 +51,8 @@ def query_prolog(engine, s): ask = False else: break - print("No (more) answers") - q.close() + print("No (more) answers") + q.close() return @@ -75,8 +76,9 @@ def live(): except: print("Unexpected error:", sys.exc_info()[0]) raise - + engine.close() # # initialize engine # engine = yap.YAPEngine(); # engine = yap.YAPEngine(yap.YAPParams()); +live()