fixes to use new IO

This commit is contained in:
Vitor Santos Costa 2017-08-09 08:15:51 +01:00
parent 5b5e954dbc
commit a7bc4a3c71
11 changed files with 96 additions and 162 deletions

View File

@ -50,10 +50,6 @@
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/)
@ -61,11 +57,11 @@
set(SETUP_PY ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
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}
)
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})")
# install(FILES jupyter.yap

View File

@ -1,13 +1,5 @@
[bdist_wheel]
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.*

View File

@ -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)

View File

@ -44,7 +44,7 @@ packages = setuptools.find_packages('${CMAKE_CURRENT_SOURCE_DIR}')
# packages.append(d[len(here)+1:].replace(os.path.sep, '.'))
package_data = {
'yap_kernel': ['resources/*.*'],
'yap_kernel': ['resources/*.*','prolog/*.*'],
}
@ -62,6 +62,7 @@ setup_args = dict(
packages = packages,
py_modules = ['yap_kernel_launcher'],
package_data = package_data,
package_dir = {'':"${CMAKE_CURRENT_SOURCE_DIR}" },
description = "YAP Kernel for Jupyter",
author = 'YP Development Team',
author_email = 'YAP-dev@scipy.org',

View File

@ -1,5 +1,5 @@
if __name__ == '__main__':
from ipykernel import kernelapp as app
from inprocesss.ipkernel import kernelapp as app
app.launch_new_instance()

View File

@ -63,10 +63,10 @@ kernel_aliases.update({
kernel_flags = dict(base_flags)
kernel_flags.update({
'no-stdout' : (
{'YAP_KernelApp' : {'no_stdout' : True}},
{'YAP_KernelApp' : {'no_stdout' : False}},
"redirect stdout to the null device"),
'no-stderr' : (
{'YAP_KernelApp' : {'no_stderr' : True}},
{'YAP_KernelApp' : {'no_stderr' : False}},
"redirect stderr to the null device"),
'pylab' : (
{'YAP_KernelApp' : {'pylab' : 'auto'}},
@ -114,8 +114,8 @@ class YAP_KernelApp(BaseIPythonApplication, InteractiveShellApp,
poller = Any() # don't restrict this even though current pollers are all Threads
heartbeat = Instance(Heartbeat, allow_none=True)
ports = Dict()
subcommands = {
'install': (
'yap_kernel.kernelspec.InstallYAPKernelSpecApp',

View File

@ -92,7 +92,9 @@ library = namedtuple('library', 'list')
v = namedtuple('_', 'slot')
load_files = namedtuple('load_files', 'file ofile args')
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:
"""An enhanced, interactive shell for YAP."""
@ -107,6 +109,7 @@ class YAPInteraction:
pjoin = os.path.join
here = os.path.abspath(os.path.dirname(__file__))
yap_lib_path = pjoin(here, "../yap4py/prolog")
#friend_path = os.path.abspath(pjoin(here, "../yap4py/prolog"))
yap_dll_path = pjoin(here, "../yap4py")
self.args = yap.YAPEngineArgs()
self.args.setYapLibDir(yap_dll_path)
@ -116,9 +119,9 @@ class YAPInteraction:
self.q = None
self.shell = shell
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,
shell_futures=True):
@ -145,8 +148,10 @@ class YAPInteraction:
__future__ imports are not shared in either direction.
Returns
-------
rquwer result : :class:`ExecutionResult`
`result : :class:`ExecutionResult`
"""
# construct a query from a one-line string
@ -167,12 +172,17 @@ rquwer
if store_history:
result.execution_count = self.shell.execution_count
self.shell.execution_count += 1
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
result.result = (True, Dict)
result.result = (True, dict)
else:
print("no")
self.shell.last_execution_succeeded = True
result.result = (True, {})
except Exception as e:
@ -197,25 +207,25 @@ rquwer
return result
def answer(q):
try:
return q.next()
except Exception as e:
print(e.args[1])
return False
def prolog_query( s ):
def jupyter_query(self, s, bindings):
# import pdb; pdb.set_trace()
#
# construct a query from a one-line string
# q is opaque to Python
q = jupyter_query(s,dict)
# construct a self.query from a one-line string
# self.q is opaque to Python
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
# you can print it out, the left-side is the variable name,
# the right side wraps a handle to a variable
# 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
# variable names should match strings
#for eq in vs:
@ -224,7 +234,26 @@ rquwer
# return
ask = True
# launch the query
while answer(q):
# this new vs should contain bindings to vars
print( dict )
if self.answer(self.q):
# deterministic = one solution
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

View File

@ -437,6 +437,7 @@ class YAPKernelApp(BaseIPythonApplication, InteractiveShellApp,
@catch_config_error
def initialize(self, argv=None):
print("**************************************************************")
super(YAPKernelApp, self).initialize(argv)
if self.subapp is not None:
return

View File

@ -54,7 +54,7 @@ def get_kernel_dict(extra_arguments=None):
"""Construct dict for kernel.json"""
return {
'argv': make_yap_kernel_cmd(extra_arguments=extra_arguments),
'display_name': 'YAP 6a',
'display_name': 'YAP 6',
'language': 'prolog',
}

View 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).

View File

@ -12,5 +12,5 @@ if __name__ == '__main__':
if 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()