fixes to use new IO
This commit is contained in:
parent
5b5e954dbc
commit
a7bc4a3c71
@ -50,10 +50,6 @@
|
|||||||
configure_file(setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
|
configure_file(setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
|
||||||
|
|
||||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources)
|
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-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( 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/)
|
file( COPY ${CMAKE_SOURCE_DIR}/misc/editors/prolog.js DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/)
|
||||||
@ -61,11 +57,11 @@
|
|||||||
set(SETUP_PY ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
|
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
|
COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} build sdist bdist
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install --no-index -f dist yap_kernel
|
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install --ignore-installed --no-deps .
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
|
||||||
|
|
||||||
# install(FILES jupyter.yap
|
# install(FILES jupyter.yap
|
||||||
|
@ -1,13 +1,5 @@
|
|||||||
[bdist_wheel]
|
[bdist_wheel]
|
||||||
universal=0
|
universal=0
|
||||||
|
|
||||||
[nosetests]
|
|
||||||
warningfilters= default |.* |DeprecationWarning |ipykernel.*
|
|
||||||
default |.* |DeprecationWarning |IPython.*
|
|
||||||
ignore |.*assert.* |DeprecationWarning |.*
|
|
||||||
ignore |.*observe.* |DeprecationWarning |IPython.*
|
|
||||||
ignore |.*default.* |DeprecationWarning |IPython.*
|
|
||||||
ignore |.*default.* |DeprecationWarning |jupyter_client.*
|
|
||||||
ignore |.*Metada.* |DeprecationWarning |IPython.*
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,113 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# coding: utf-8
|
|
||||||
|
|
||||||
# Copyright (c) IPython Development Team.
|
|
||||||
# Distributed under the terms of the Modified BSD License.
|
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
# the name of the package
|
|
||||||
name = 'yap_kernel'
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
|
||||||
# Minimal Python version sanity check
|
|
||||||
#-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
import sys
|
|
||||||
|
|
||||||
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
|
|
||||||
print(error, file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
PY3 = (sys.version_info[0] >= 3)
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
|
||||||
# get on with it
|
|
||||||
#-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
from glob import glob
|
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
|
|
||||||
from distutils.core import setup
|
|
||||||
|
|
||||||
pjoin = os.path.join
|
|
||||||
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, '.'))
|
|
||||||
|
|
||||||
package_data = {
|
|
||||||
'yap_kernel': ['resources/*.*'],
|
|
||||||
}
|
|
||||||
|
|
||||||
version_ns = {}
|
|
||||||
with open(pjoin(here, name, '_version.py')) as f:
|
|
||||||
exec(f.read(), {}, version_ns)
|
|
||||||
|
|
||||||
|
|
||||||
setup_args = dict(
|
|
||||||
name = name,
|
|
||||||
version = version_ns['__version__'],
|
|
||||||
scripts = glob(pjoin('scripts', '*')),
|
|
||||||
packages = packages,
|
|
||||||
py_modules = ['yap_kernel_launcher'],
|
|
||||||
package_data = package_data,
|
|
||||||
description = "YAP Kernel for Jupyter",
|
|
||||||
author = 'YAP Development Team',
|
|
||||||
author_email = 'ipython-dev@scipy.org',
|
|
||||||
url = 'http://ipython.org',
|
|
||||||
license = 'BSD',
|
|
||||||
platforms = "Linux, Mac OS X, Windows",
|
|
||||||
keywords = ['Interactive', 'Interpreter', 'Shell', 'Web'],
|
|
||||||
classifiers = [
|
|
||||||
'Intended Audience :: Developers',
|
|
||||||
'Intended Audience :: System Administrators',
|
|
||||||
'Intended Audience :: Science/Research',
|
|
||||||
'License :: OSI Approved :: BSD License',
|
|
||||||
'Programming Language :: Python',
|
|
||||||
'Programming Language :: Python :: 2.7',
|
|
||||||
'Programming Language :: Python :: 3',
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
if 'develop' in sys.argv or any(a.startswith('bdist') for a in sys.argv):
|
|
||||||
import setuptools
|
|
||||||
|
|
||||||
setuptools_args = {}
|
|
||||||
install_requires = setuptools_args['install_requires'] = [
|
|
||||||
'ipython>=4.0.0',
|
|
||||||
'traitlets>=4.1.0',
|
|
||||||
'jupyter_client',
|
|
||||||
'tornado>=4.0',
|
|
||||||
'yap4py'
|
|
||||||
]
|
|
||||||
|
|
||||||
if any(a.startswith(('bdist', 'build', 'install')) for a in sys.argv):
|
|
||||||
from ipykernel.kernelspec import write_kernel_spec, make_ipkernel_cmd, KERNEL_NAME
|
|
||||||
|
|
||||||
argv = make_ipkernel_cmd(executable='python')
|
|
||||||
dest = os.path.join(here, 'data_kernelspec')
|
|
||||||
if os.path.exists(dest):
|
|
||||||
shutil.rmtree(dest)
|
|
||||||
write_kernel_spec(dest, overrides={'argv': argv})
|
|
||||||
|
|
||||||
setup_args['data_files'] = [
|
|
||||||
(pjoin('share', 'jupyter', 'kernels', KERNEL_NAME), glob(pjoin(dest, '*'))),
|
|
||||||
]
|
|
||||||
|
|
||||||
extras_require = setuptools_args['extras_require'] = {
|
|
||||||
'test:python_version=="2.7"': ['mock'],
|
|
||||||
'test': ['nose_warnings_filters', 'nose-timer'],
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'setuptools' in sys.modules:
|
|
||||||
setup_args.update(setuptools_args)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
setup(**setup_args)
|
|
@ -44,7 +44,7 @@ packages = setuptools.find_packages('${CMAKE_CURRENT_SOURCE_DIR}')
|
|||||||
# packages.append(d[len(here)+1:].replace(os.path.sep, '.'))
|
# packages.append(d[len(here)+1:].replace(os.path.sep, '.'))
|
||||||
|
|
||||||
package_data = {
|
package_data = {
|
||||||
'yap_kernel': ['resources/*.*'],
|
'yap_kernel': ['resources/*.*','prolog/*.*'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -62,6 +62,7 @@ setup_args = dict(
|
|||||||
packages = packages,
|
packages = packages,
|
||||||
py_modules = ['yap_kernel_launcher'],
|
py_modules = ['yap_kernel_launcher'],
|
||||||
package_data = package_data,
|
package_data = package_data,
|
||||||
|
package_dir = {'':"${CMAKE_CURRENT_SOURCE_DIR}" },
|
||||||
description = "YAP Kernel for Jupyter",
|
description = "YAP Kernel for Jupyter",
|
||||||
author = 'YP Development Team',
|
author = 'YP Development Team',
|
||||||
author_email = 'YAP-dev@scipy.org',
|
author_email = 'YAP-dev@scipy.org',
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from ipykernel import kernelapp as app
|
from inprocesss.ipkernel import kernelapp as app
|
||||||
app.launch_new_instance()
|
app.launch_new_instance()
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,10 +63,10 @@ kernel_aliases.update({
|
|||||||
kernel_flags = dict(base_flags)
|
kernel_flags = dict(base_flags)
|
||||||
kernel_flags.update({
|
kernel_flags.update({
|
||||||
'no-stdout' : (
|
'no-stdout' : (
|
||||||
{'YAP_KernelApp' : {'no_stdout' : True}},
|
{'YAP_KernelApp' : {'no_stdout' : False}},
|
||||||
"redirect stdout to the null device"),
|
"redirect stdout to the null device"),
|
||||||
'no-stderr' : (
|
'no-stderr' : (
|
||||||
{'YAP_KernelApp' : {'no_stderr' : True}},
|
{'YAP_KernelApp' : {'no_stderr' : False}},
|
||||||
"redirect stderr to the null device"),
|
"redirect stderr to the null device"),
|
||||||
'pylab' : (
|
'pylab' : (
|
||||||
{'YAP_KernelApp' : {'pylab' : 'auto'}},
|
{'YAP_KernelApp' : {'pylab' : 'auto'}},
|
||||||
|
@ -92,7 +92,9 @@ library = namedtuple('library', 'list')
|
|||||||
v = namedtuple('_', 'slot')
|
v = namedtuple('_', 'slot')
|
||||||
load_files = namedtuple('load_files', 'file ofile args')
|
load_files = namedtuple('load_files', 'file ofile args')
|
||||||
python_query= namedtuple('python_query', 'query_mgr string')
|
python_query= namedtuple('python_query', 'query_mgr string')
|
||||||
jupyter_query = namedtuple('jupyter_query', 'query_mgr string')
|
jupyter_query = namedtuple('jupyter_query', 'self string')
|
||||||
|
enter_cell = namedtuple('enter_cell', 'self' )
|
||||||
|
exit_cell = namedtuple('exit_cell', 'self' )
|
||||||
|
|
||||||
class YAPInteraction:
|
class YAPInteraction:
|
||||||
"""An enhanced, interactive shell for YAP."""
|
"""An enhanced, interactive shell for YAP."""
|
||||||
@ -107,6 +109,7 @@ class YAPInteraction:
|
|||||||
pjoin = os.path.join
|
pjoin = os.path.join
|
||||||
here = os.path.abspath(os.path.dirname(__file__))
|
here = os.path.abspath(os.path.dirname(__file__))
|
||||||
yap_lib_path = pjoin(here, "../yap4py/prolog")
|
yap_lib_path = pjoin(here, "../yap4py/prolog")
|
||||||
|
#friend_path = os.path.abspath(pjoin(here, "../yap4py/prolog"))
|
||||||
yap_dll_path = pjoin(here, "../yap4py")
|
yap_dll_path = pjoin(here, "../yap4py")
|
||||||
self.args = yap.YAPEngineArgs()
|
self.args = yap.YAPEngineArgs()
|
||||||
self.args.setYapLibDir(yap_dll_path)
|
self.args.setYapLibDir(yap_dll_path)
|
||||||
@ -116,9 +119,9 @@ class YAPInteraction:
|
|||||||
self.q = None
|
self.q = None
|
||||||
self.shell = shell
|
self.shell = shell
|
||||||
self.run = False
|
self.run = False
|
||||||
self.yapeng.goal(use_module(library('jupyter')))
|
self.yapeng.goal(use_module(pjoin(here, 'prolog/jupyter.yap')))
|
||||||
|
self.os = ""
|
||||||
|
self.status = None
|
||||||
|
|
||||||
def run_cell(self, s, store_history=True, silent=False,
|
def run_cell(self, s, store_history=True, silent=False,
|
||||||
shell_futures=True):
|
shell_futures=True):
|
||||||
@ -145,8 +148,10 @@ class YAPInteraction:
|
|||||||
__future__ imports are not shared in either direction.
|
__future__ imports are not shared in either direction.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
|
|
||||||
-------
|
-------
|
||||||
rquwer result : :class:`ExecutionResult`
|
|
||||||
|
`result : :class:`ExecutionResult`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# construct a query from a one-line string
|
# construct a query from a one-line string
|
||||||
@ -167,12 +172,17 @@ rquwer
|
|||||||
|
|
||||||
if store_history:
|
if store_history:
|
||||||
result.execution_count = self.shell.execution_count
|
result.execution_count = self.shell.execution_count
|
||||||
|
self.shell.execution_count += 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if self.q == jupyter_query(s, Dict):
|
self.bindings = dict = {}
|
||||||
|
state =self.jupyter_query(s, dict)
|
||||||
|
if state:
|
||||||
|
print("yes")
|
||||||
self.shell.last_execution_succeeded = True
|
self.shell.last_execution_succeeded = True
|
||||||
result.result = (True, Dict)
|
result.result = (True, dict)
|
||||||
else:
|
else:
|
||||||
|
print("no")
|
||||||
self.shell.last_execution_succeeded = True
|
self.shell.last_execution_succeeded = True
|
||||||
result.result = (True, {})
|
result.result = (True, {})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -197,25 +207,25 @@ rquwer
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def answer(q):
|
def jupyter_query(self, s, bindings):
|
||||||
try:
|
# import pdb; pdb.set_trace()
|
||||||
return q.next()
|
|
||||||
except Exception as e:
|
|
||||||
print(e.args[1])
|
|
||||||
return False
|
|
||||||
|
|
||||||
def prolog_query( s ):
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# construct a query from a one-line string
|
# construct a self.query from a one-line string
|
||||||
# q is opaque to Python
|
# self.q is opaque to Python
|
||||||
q = jupyter_query(s,dict)
|
self.bindings = {}
|
||||||
|
self.status = "call"
|
||||||
|
self.yapeng.goal(enter_cell(self))
|
||||||
|
if self.q and s != self.os:
|
||||||
|
self.q.close()
|
||||||
|
self.q = None
|
||||||
|
if not self.q:
|
||||||
|
self.q = self.yapeng.query(jupyter_query(self, s))
|
||||||
|
self.os = s
|
||||||
# vs is the list of variables
|
# vs is the list of variables
|
||||||
# you can print it out, the left-side is the variable name,
|
# you can print it out, the left-side is the variable name,
|
||||||
# the right side wraps a handle to a variable
|
# the right side wraps a handle to a variable
|
||||||
# pdb.set_trace()
|
# pdb.set_trace()
|
||||||
#vs = q.namedVarsVector()
|
# #pdb.set_trace()
|
||||||
#pdb.set_trace()
|
|
||||||
# atom match either symbols, or if no symbol exists, sttrings, In this case
|
# atom match either symbols, or if no symbol exists, sttrings, In this case
|
||||||
# variable names should match strings
|
# variable names should match strings
|
||||||
#for eq in vs:
|
#for eq in vs:
|
||||||
@ -224,7 +234,26 @@ rquwer
|
|||||||
# return
|
# return
|
||||||
ask = True
|
ask = True
|
||||||
# launch the query
|
# launch the query
|
||||||
while answer(q):
|
if self.answer(self.q):
|
||||||
# this new vs should contain bindings to vars
|
# deterministic = one solution
|
||||||
print( dict )
|
if self.status == "exit":
|
||||||
|
# done
|
||||||
|
self.q.close()
|
||||||
|
self.q = None
|
||||||
|
self.os = ""
|
||||||
|
print("yes")
|
||||||
|
self.yapeng.goal(exit_cell(self))
|
||||||
|
return True, self.bindings
|
||||||
|
print("No (more) answers")
|
||||||
|
self.q.close()
|
||||||
|
self.q = None
|
||||||
|
self.yapeng.goal(exit_cell(self))
|
||||||
|
return True, None
|
||||||
|
|
||||||
|
def answer(self, q):
|
||||||
|
try:
|
||||||
|
return q.next()
|
||||||
|
except Exception as e:
|
||||||
|
print(e.args[1])
|
||||||
|
self.yapeng.goal(exit_cell(self))
|
||||||
|
return False, None
|
||||||
|
@ -437,6 +437,7 @@ class YAPKernelApp(BaseIPythonApplication, InteractiveShellApp,
|
|||||||
|
|
||||||
@catch_config_error
|
@catch_config_error
|
||||||
def initialize(self, argv=None):
|
def initialize(self, argv=None):
|
||||||
|
print("**************************************************************")
|
||||||
super(YAPKernelApp, self).initialize(argv)
|
super(YAPKernelApp, self).initialize(argv)
|
||||||
if self.subapp is not None:
|
if self.subapp is not None:
|
||||||
return
|
return
|
||||||
|
@ -54,7 +54,7 @@ def get_kernel_dict(extra_arguments=None):
|
|||||||
"""Construct dict for kernel.json"""
|
"""Construct dict for kernel.json"""
|
||||||
return {
|
return {
|
||||||
'argv': make_yap_kernel_cmd(extra_arguments=extra_arguments),
|
'argv': make_yap_kernel_cmd(extra_arguments=extra_arguments),
|
||||||
'display_name': 'YAP 6a',
|
'display_name': 'YAP 6',
|
||||||
'language': 'prolog',
|
'language': 'prolog',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
28
packages/python/yap_kernel/yap_kernel/prolog/jupyter.yap
Normal file
28
packages/python/yap_kernel/yap_kernel/prolog/jupyter.yap
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
|
||||||
|
:- use_module(library(python)).
|
||||||
|
|
||||||
|
:- initialization
|
||||||
|
ensure_loaded(library(yapi) ),
|
||||||
|
python_import(sys).
|
||||||
|
|
||||||
|
%% @pred yap_query(0:Goalc, - Dictionary)
|
||||||
|
%%
|
||||||
|
%% dictionary, Examples
|
||||||
|
%%
|
||||||
|
%%
|
||||||
|
jupyter_query( Self, String ) :-
|
||||||
|
set_python_output( Self, Output , Error),
|
||||||
|
python_query( Self, String ),
|
||||||
|
close( Output ),
|
||||||
|
cloe( Error ).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
set_python_output(_Self,Output,Error) :-
|
||||||
|
open('//python/sys.stdout', append, Output, [alias(output)]),
|
||||||
|
open('//python/sys.stderr', append, Error, [alias(error)]),
|
||||||
|
yap_flag(user_output, output),
|
||||||
|
yap_flag(user_error, error).
|
||||||
|
|
||||||
|
|
@ -12,5 +12,5 @@ if __name__ == '__main__':
|
|||||||
if sys.path[0] == '':
|
if sys.path[0] == '':
|
||||||
del sys.path[0]
|
del sys.path[0]
|
||||||
|
|
||||||
from yap_kernel import kernelapp as app
|
from inprocess.ipkernel import kernelapp as app
|
||||||
app.launch_new_instance()
|
app.launch_new_instance()
|
||||||
|
Reference in New Issue
Block a user