python support
This commit is contained in:
@@ -1,78 +1,72 @@
|
||||
|
||||
set (EXTRAS
|
||||
MANIFEST.in
|
||||
YAP_KERNEL.md
|
||||
)
|
||||
set (EXTRAS
|
||||
MANIFEST.in
|
||||
YAP_KERNEL.md
|
||||
)
|
||||
|
||||
set (PYTHON_SOURCES
|
||||
yap_kernel_launcher.py
|
||||
data_kernelspec/kernel.json
|
||||
yap_kernel/__init__.py
|
||||
yap_kernel/__main__.py
|
||||
yap_kernel/_version.py
|
||||
yap_kernel/codeutil.py
|
||||
yap_kernel/connect.py
|
||||
yap_kernel/datapub.py
|
||||
yap_kernel/displayhook.py
|
||||
yap_kernel/embed.py
|
||||
yap_kernel/eventloops.py
|
||||
yap_kernel/heartbeat.py
|
||||
yap_kernel/interactiveshell.py
|
||||
yap_kernel/iostream.py
|
||||
yap_kernel/jsonutil.py
|
||||
yap_kernel/kernelapp.py
|
||||
yap_kernel/kernelbase.py
|
||||
yap_kernel/kernelspec.py
|
||||
yap_kernel/log.py
|
||||
yap_kernel/parentpoller.py
|
||||
yap_kernel/pickleutil.py
|
||||
yap_kernel/serialize.py
|
||||
yap_kernel/yapkernel.py
|
||||
yap_kernel/zmqshell.py
|
||||
yap_kernel/comm/__init__.py
|
||||
yap_kernel/comm/comm.py
|
||||
yap_kernel/comm/manager.py
|
||||
yap_kernel/gui/__init__.py
|
||||
yap_kernel/gui/gtk3embed.py
|
||||
yap_kernel/gui/gtkembed.py
|
||||
yap_kernel/inprocess/__init__.py
|
||||
yap_kernel/inprocess/blocking.py
|
||||
yap_kernel/inprocess/channels.py
|
||||
yap_kernel/inprocess/client.py
|
||||
yap_kernel/inprocess/constants.py
|
||||
yap_kernel/inprocess/ipkernel.py
|
||||
yap_kernel/inprocess/manager.py
|
||||
yap_kernel/inprocess/socket.py
|
||||
yap_kernel/pylab/__init__.py
|
||||
yap_kernel/pylab/backend_inline.py
|
||||
yap_kernel/pylab/config.py
|
||||
)
|
||||
set (PYTHON_SOURCES
|
||||
yap_kernel_launcher.py
|
||||
data_kernelspec/kernel.json
|
||||
yap_kernel/__init__.py
|
||||
yap_kernel/__main__.py
|
||||
yap_kernel/_version.py
|
||||
yap_kernel/codeutil.py
|
||||
yap_kernel/connect.py
|
||||
yap_kernel/datapub.py
|
||||
yap_kernel/displayhook.py
|
||||
yap_kernel/embed.py
|
||||
yap_kernel/eventloops.py
|
||||
yap_kernel/heartbeat.py
|
||||
yap_kernel/interactiveshell.py
|
||||
yap_kernel/iostream.py
|
||||
yap_kernel/jsonutil.py
|
||||
yap_kernel/kernelapp.py
|
||||
yap_kernel/kernelbase.py
|
||||
yap_kernel/kernelspec.py
|
||||
yap_kernel/log.py
|
||||
yap_kernel/parentpoller.py
|
||||
yap_kernel/pickleutil.py
|
||||
yap_kernel/serialize.py
|
||||
yap_kernel/yapkernel.py
|
||||
yap_kernel/zmqshell.py
|
||||
yap_kernel/comm/__init__.py
|
||||
yap_kernel/comm/comm.py
|
||||
yap_kernel/comm/manager.py
|
||||
yap_kernel/gui/__init__.py
|
||||
yap_kernel/gui/gtk3embed.py
|
||||
yap_kernel/gui/gtkembed.py
|
||||
yap_kernel/inprocess/__init__.py
|
||||
yap_kernel/inprocess/blocking.py
|
||||
yap_kernel/inprocess/channels.py
|
||||
yap_kernel/inprocess/client.py
|
||||
yap_kernel/inprocess/ipkernel.py
|
||||
yap_kernel/inprocess/manager.py
|
||||
yap_kernel/inprocess/socket.py
|
||||
yap_kernel/pylab/__init__.py
|
||||
yap_kernel/pylab/backend_inline.py
|
||||
yap_kernel/pylab/config.py
|
||||
)
|
||||
|
||||
foreach(i ${PYTHON_SOURCES})
|
||||
configure_file(${i} ${CMAKE_CURRENT_BINARY_DIR}/${i})
|
||||
endforeach()
|
||||
configure_file("setup.py" ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
|
||||
configure_file("MANIFEST.in" ${CMAKE_CURRENT_BINARY_DIR}/MANIFEST.in)
|
||||
configure_file("YAP_KERNEL.md" ${CMAKE_CURRENT_BINARY_DIR}/README)
|
||||
configure_file("yap_kernel/_version.py" ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/_version.py )
|
||||
configure_file("${CMAKE_SOURCE_DIR}/docs/icons/yap_32x32x32.png" ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/logo-32x32.png)
|
||||
configure_file("${CMAKE_SOURCE_DIR}/docs/icons/yap_64x64x32.png" ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/logo-64x64.png)
|
||||
configure_file("${CMAKE_SOURCE_DIR}/misc/editors/prolog.js" ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/prolog.js)
|
||||
configure_file(setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
|
||||
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources)
|
||||
file(COPY yap_kernel DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
file( COPY MANIFEST.in setup.cfg data_kernelspec yap_kernel_launcher.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
# file( GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/README.md INPUT YAP_KERNEL.md )
|
||||
file( COPY yap_kernel/_version.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel )
|
||||
file( GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/logo-32x32.png INPUT ${CMAKE_SOURCE_DIR}/docs/icons/yap_32x32x32.png )
|
||||
file( GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/logo-64x64.png INPUT ${CMAKE_SOURCE_DIR}/docs/icons/yap_64x64x32.png )
|
||||
file( COPY ${CMAKE_SOURCE_DIR}/misc/editors/prolog.js DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/)
|
||||
|
||||
set(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
|
||||
set( PYTHON_INSTALL sdist bdist_wheel)
|
||||
set(SETUP_PY ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
|
||||
|
||||
add_custom_target( YAPKernel ALL
|
||||
add_custom_target( YAPKernel ALL
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} sdist
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
COMMAND ${PYTHON_EXECUTABLE} setup.py clean sdist bdist_wheel
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
DEPENDS libYap ${SWIG_MODULE_Py2YAP_REAL_NAME}
|
||||
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install --no-index -f dist yap_kernel
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
|
||||
|
||||
)
|
||||
|
||||
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install --no-index -f dist yap_kernel")
|
||||
|
||||
install(FILES jupyter.yap
|
||||
DESTINATION ${libpl}
|
||||
)
|
||||
# install(FILES jupyter.yap
|
||||
# DESTINATION ${libpl} )
|
||||
|
@@ -14,10 +14,11 @@ name = 'yap_kernel'
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
import sys
|
||||
import setuptools
|
||||
|
||||
v = sys.version_info
|
||||
if v[:2] < (2,7) or (v[0] >= 3 and v[:2] < (3,3)):
|
||||
error = "ERROR: %s requires Python version 2.7 or 3.3 or above." % name
|
||||
error = "ERROR: %s requires Python version 3.3 or above." % name
|
||||
print(error, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
@@ -34,23 +35,26 @@ import shutil
|
||||
from distutils.core import setup
|
||||
|
||||
pjoin = os.path.join
|
||||
here = os.path.relpath(os.path.dirname(__file__))
|
||||
pkg_root = pjoin(here, name)
|
||||
here = os.path.abspath(os.path.dirname(__file__))
|
||||
# pkg_root = pjoin(here, name)
|
||||
|
||||
packages = []
|
||||
for d, _, _ in os.walk(pjoin(here, name)):
|
||||
if os.path.exists(pjoin(d, '__init__.py')):
|
||||
packages.append(d[len(here)+1:].replace(os.path.sep, '.'))
|
||||
packages = setuptools.find_packages('${CMAKE_CURRENT_SOURCE_DIR}')
|
||||
# for d, _, _ in os.walk(pjoin(here, name)):
|
||||
# if os.path.exists(pjoin(d, '__init__.py')):
|
||||
# packages.append(d[len(here)+1:].replace(os.path.sep, '.'))
|
||||
|
||||
package_data = {
|
||||
'ipykernel': ['resources/*.*'],
|
||||
'yap_kernel': ['resources/*.*'],
|
||||
}
|
||||
|
||||
|
||||
version_ns = {}
|
||||
with open(pjoin(here, name, '_version.py')) as f:
|
||||
with open(pjoin('${CMAKE_CURRENT_SOURCE_DIR}', name, '_version.py')) as f:
|
||||
exec(f.read(), {}, version_ns)
|
||||
|
||||
|
||||
|
||||
|
||||
setup_args = dict(
|
||||
name = name,
|
||||
version = version_ns['__version__'],
|
||||
@@ -59,8 +63,8 @@ setup_args = dict(
|
||||
py_modules = ['yap_kernel_launcher'],
|
||||
package_data = package_data,
|
||||
description = "YAP Kernel for Jupyter",
|
||||
author = 'IPython Development Team and Vitor Santos Costa',
|
||||
author_email = 'vsc@dcc.fc.up.ot',
|
||||
author = 'YP Development Team',
|
||||
author_email = 'YAP-dev@scipy.org',
|
||||
url = 'http://ipython.org',
|
||||
license = 'BSD',
|
||||
platforms = "Linux, Mac OS X, Windows",
|
||||
@@ -70,8 +74,8 @@ setup_args = dict(
|
||||
'Intended Audience :: System Administrators',
|
||||
'Intended Audience :: Science/Research',
|
||||
'License :: OSI Approved :: BSD License',
|
||||
'Programming Language :: Prolog',
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Programming Language :: Python :: 3',
|
||||
],
|
||||
)
|
||||
@@ -85,7 +89,6 @@ install_requires = setuptools_args['install_requires'] = [
|
||||
'traitlets>=4.1.0',
|
||||
'jupyter_client',
|
||||
'tornado>=4.0',
|
||||
'yap4py'
|
||||
]
|
||||
|
||||
if any(a.startswith(('bdist', 'build', 'install')) for a in sys.argv):
|
||||
@@ -101,10 +104,6 @@ if any(a.startswith(('bdist', 'build', 'install')) for a in sys.argv):
|
||||
(pjoin('share', 'jupyter', 'kernels', KERNEL_NAME), glob(pjoin(dest, '*'))),
|
||||
]
|
||||
|
||||
setuptools_args['zip_safe']=False
|
||||
setuptools_args['eager_resources'] = ['yap_kernel']
|
||||
setuptools_args['include_package_data']=True
|
||||
|
||||
extras_require = setuptools_args['extras_require'] = {
|
||||
'test:python_version=="2.7"': ['mock'],
|
||||
'test': ['nose_warnings_filters', 'nose-timer'],
|
||||
|
@@ -1,3 +1,4 @@
|
||||
|
||||
"""An in-process kernel"""
|
||||
|
||||
# Copyright (c) IPython Development Team.
|
||||
|
@@ -73,7 +73,6 @@ from IPython.utils.io import ask_yes_no
|
||||
from IPython.utils.ipstruct import Struct
|
||||
from IPython.paths import get_ipython_dir
|
||||
from IPython.utils.path import get_home_dir, get_py_filename, ensure_dir_exists
|
||||
from IPython.utils.process import system, getoutput
|
||||
from IPython.utils.py3compat import (builtin_mod, unicode_type, string_types,
|
||||
with_metaclass, iteritems)
|
||||
from IPython.utils.strdispatch import StrDispatch
|
||||
@@ -93,7 +92,8 @@ bindvars = namedtuple('bindvars', 'list')
|
||||
library = namedtuple('library', 'list')
|
||||
v = namedtuple('_', 'slot')
|
||||
load_files = namedtuple('load_files', 'file ofile args')
|
||||
|
||||
python_query = namedtuple('python_query', 'query_mgr string')
|
||||
python_output = namedtuple('python_output', 'oldOut oldErryapi')
|
||||
|
||||
class YAPInteraction:
|
||||
"""An enhanced, interactive shell for YAP."""
|
||||
@@ -114,9 +114,11 @@ class YAPInteraction:
|
||||
# args.setYapPrologBootFile(os.path.join(yap_lib_path."startup.yss"))
|
||||
self.yapeng = yap.YAPEngine(self.args)
|
||||
self.q = None
|
||||
self.yapeng.goal(use_module(library('yapi')))
|
||||
self.shell = shell
|
||||
self.run = False
|
||||
self.yapeng.goal(use_module(library('python')))
|
||||
self.yapeng.goal(use_module(library('yapi')))
|
||||
self.yapeng.goal(python_output(OldOi ))
|
||||
|
||||
def eng(self):
|
||||
return self.yapeng
|
||||
@@ -126,9 +128,41 @@ class YAPInteraction:
|
||||
self.q.close()
|
||||
self.q = None
|
||||
|
||||
def numbervars(self, l):
|
||||
return self.yapeng.fun(bindvars(l))
|
||||
def more(self):
|
||||
if self.q.next():
|
||||
if self.q.deterministic():
|
||||
# done
|
||||
self.q.close()
|
||||
self.q = None
|
||||
return True
|
||||
self.q.close()
|
||||
self.q = None
|
||||
return False
|
||||
|
||||
def query_prolog(self, s):
|
||||
if self.q:
|
||||
return self.restart(s)
|
||||
if not s:
|
||||
return True
|
||||
self.q = self.yapeng.qt(python_query(self,s))
|
||||
# for eq in vs:
|
||||
# if not isinstance(eq[0],str):
|
||||
# print( "Error: Variable Name matches a Python Symbol")
|
||||
# return False
|
||||
return self.more()
|
||||
|
||||
def restart(self, s):
|
||||
if s.startswith(';') or s.startswith('y'):
|
||||
return self.more()
|
||||
elif s.startswith('#'):
|
||||
exec(s.lstrip('#'))
|
||||
elif s.startswith('*'):
|
||||
while self.more():
|
||||
pass
|
||||
print("No (more) answers")
|
||||
self.q.close()
|
||||
self.q = None
|
||||
return False
|
||||
|
||||
|
||||
def run_cell(self, s, store_history=True, silent=False,
|
||||
@@ -160,63 +194,48 @@ class YAPInteraction:
|
||||
result : :class:`ExecutionResult`
|
||||
"""
|
||||
|
||||
# construct a query from a one-line string
|
||||
# q is opaque to Python
|
||||
# vs is the list of variables
|
||||
# you can print it out, the left-side is the variable name,
|
||||
# the right side wraps a handle to a variable
|
||||
# pdb.set_trace()
|
||||
# #pdb.set_trace()
|
||||
# atom match either symbols, or if no symbol exists, strings, In this case
|
||||
# variable names should match strings
|
||||
# ask = True
|
||||
# launch the query
|
||||
result = ExecutionResult()
|
||||
result.execution_count = self.shell.execution_count
|
||||
|
||||
def error_before_exec(value):
|
||||
result.error_before_exec = value
|
||||
self.shell.last_execution_succeeded = False
|
||||
if not s or s.isspace():
|
||||
self.shell.last_execution_succeeded = True
|
||||
return result
|
||||
|
||||
# inspect for ?? in the text
|
||||
# print(st)
|
||||
#
|
||||
maxits = 2
|
||||
if store_history:
|
||||
result.execution_count = self.shell.execution_count
|
||||
|
||||
s = s.strip('\n\j\r\t ')
|
||||
if not self.q or s:
|
||||
(self.q,out) = self.top_level(s, out)
|
||||
else:
|
||||
out = q.next_answer()
|
||||
if self.q:
|
||||
st = s.strip('\n\j\r\t ')
|
||||
if st and st == '*':
|
||||
maxits = 1
|
||||
elif st and st.isdigit():
|
||||
maxits = int(st)*2
|
||||
elif st and st != ';':
|
||||
self.closeq()
|
||||
if not self.q:
|
||||
try:
|
||||
if s:
|
||||
self.q = self.yapeng.query(ya[q.__hash__])
|
||||
self.vs = self.q.namedVarsVector()
|
||||
else:
|
||||
return
|
||||
except SyntaxError:
|
||||
return error_before_exec(sys.exc_info()[1])
|
||||
|
||||
cell = s # cell has to exist so it can be stored/logged
|
||||
# Store raw and processed history
|
||||
# if not silent:
|
||||
# self.shell..logger.log(cell, s)
|
||||
has_raised = False
|
||||
try:
|
||||
while (maxits != 0):
|
||||
self.do_loop(maxits, gs)
|
||||
except Exception:
|
||||
result.error_in_exec = sys.exc_info()[1]
|
||||
has_raised = True
|
||||
self.closeq()
|
||||
self.query_prolog(s)
|
||||
self.shell.last_execution_succeeded = True
|
||||
result.result = True
|
||||
except Exception as e:
|
||||
print(e)
|
||||
self.shell.last_execution_succeeded = False
|
||||
result.result = False
|
||||
|
||||
self.shell.last_execution_succeeded = not has_raised
|
||||
result.result = self.shell.last_execution_succeeded
|
||||
# Reset this so later displayed values do not modify the
|
||||
# ExecutionResult
|
||||
# self.displayhook.exec_result = None
|
||||
|
||||
# self.events.trigger('post_execute')
|
||||
# if not silent:
|
||||
# self.events.trigger('post_self.run_cell')
|
||||
#self.events.trigger('post_execute')
|
||||
#if not silent:
|
||||
# self.events.trigger('post_run_cell')
|
||||
|
||||
if store_history:
|
||||
# Write output to the database. Does nothing unless
|
||||
# history output logging is enabled.
|
||||
# self.history_manager.store_output(self.execution_count)
|
||||
# Each cell is a *single* input, regardless of how many lines it has
|
||||
self.shell.execution_count += 1
|
||||
|
||||
return result
|
||||
|
||||
|
@@ -12,6 +12,7 @@ from traitlets import Instance, Type, Any, List
|
||||
from .comm import CommManager
|
||||
from .kernelbase import Kernel as KernelBase
|
||||
from .zmqshell import ZMQInteractiveShell
|
||||
from .interactiveshell import YAPInteraction
|
||||
|
||||
class YAPKernel(KernelBase):
|
||||
shell = Instance('IPython.core.interactiveshell.InteractiveShellABC',
|
||||
|
Reference in New Issue
Block a user