Changed example to point to magma childproc instead of bash.
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
"""A bash kernel for Jupyter"""
|
||||
|
||||
__version__ = '0.4.1'
|
||||
@@ -1,3 +0,0 @@
|
||||
from ipykernel.kernelapp import IPKernelApp
|
||||
from .kernel import BashKernel
|
||||
IPKernelApp.launch_instance(kernel_class=BashKernel)
|
||||
@@ -1,11 +1,11 @@
|
||||
[metadata]
|
||||
module = bash_kernel
|
||||
author = Thomas Kluyver
|
||||
author-email = thomas@kluyver.me.uk
|
||||
home-page = https://github.com/takluyver/bash_kernel
|
||||
module = magma_kernel
|
||||
author = Chris Granade
|
||||
author-email = cgranade@cgranade.com
|
||||
home-page = https://github.com/takluyver/magma_kernel
|
||||
requires = pexpect (>=3.3)
|
||||
description-file = README.rst
|
||||
classifiers = Framework :: IPython
|
||||
License :: OSI Approved :: BSD License
|
||||
Programming Language :: Python :: 3
|
||||
Topic :: System :: Shells
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
"""A magma kernel for Jupyter"""
|
||||
|
||||
__version__ = '0.0.1dev1'
|
||||
@@ -0,0 +1,3 @@
|
||||
from ipykernel.kernelapp import IPKernelApp
|
||||
from .kernel import MagmaKernel
|
||||
IPKernelApp.launch_instance(kernel_class=MagmaKernel)
|
||||
@@ -5,10 +5,10 @@ import sys
|
||||
from jupyter_client.kernelspec import install_kernel_spec
|
||||
from IPython.utils.tempdir import TemporaryDirectory
|
||||
|
||||
kernel_json = {"argv":[sys.executable,"-m","bash_kernel", "-f", "{connection_file}"],
|
||||
"display_name":"Bash",
|
||||
"language":"bash",
|
||||
"codemirror_mode":"shell",
|
||||
kernel_json = {"argv":[sys.executable,"-m","magma_kernel", "-f", "{connection_file}"],
|
||||
"display_name":"Magma",
|
||||
"language":"magma",
|
||||
"codemirror_mode":"magma",
|
||||
"env":{"PS1": "$"}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ def install_my_kernel_spec(user=True):
|
||||
# TODO: Copy resources once they're specified
|
||||
|
||||
print('Installing IPython kernel spec')
|
||||
install_kernel_spec(td, 'bash', user=user, replace=True)
|
||||
install_kernel_spec(td, 'magma', user=user, replace=True)
|
||||
|
||||
def _is_root():
|
||||
try:
|
||||
@@ -1,5 +1,5 @@
|
||||
from ipykernel.kernelbase import Kernel
|
||||
from pexpect import replwrap, EOF
|
||||
from pexpect import replwrap, EOF, spawn
|
||||
|
||||
from subprocess import check_output
|
||||
from os import unlink
|
||||
@@ -10,7 +10,7 @@ import re
|
||||
import signal
|
||||
import urllib
|
||||
|
||||
__version__ = '0.2'
|
||||
__version__ = '0.0.1dev1'
|
||||
|
||||
version_pat = re.compile(r'version (\d+(\.\d+)+)')
|
||||
|
||||
@@ -19,10 +19,11 @@ from .images import (
|
||||
)
|
||||
|
||||
|
||||
class BashKernel(Kernel):
|
||||
implementation = 'bash_kernel'
|
||||
class MagmaKernel(Kernel):
|
||||
implementation = 'magma_kernel'
|
||||
implementation_version = __version__
|
||||
|
||||
'''
|
||||
@property
|
||||
def language_version(self):
|
||||
m = version_pat.search(self.banner)
|
||||
@@ -35,29 +36,39 @@ class BashKernel(Kernel):
|
||||
if self._banner is None:
|
||||
self._banner = check_output(['bash', '--version']).decode('utf-8')
|
||||
return self._banner
|
||||
'''
|
||||
|
||||
@property
|
||||
def banner(self):
|
||||
return ""
|
||||
|
||||
language_info = {'name': 'bash',
|
||||
'codemirror_mode': 'shell',
|
||||
language_info = {'name': 'magma',
|
||||
'codemirror_mode': 'magma',
|
||||
'mimetype': 'text/x-sh',
|
||||
'file_extension': '.sh'}
|
||||
'file_extension': '.mgm'}
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
Kernel.__init__(self, **kwargs)
|
||||
self._start_bash()
|
||||
self._start_magma()
|
||||
|
||||
def _start_bash(self):
|
||||
def _start_magma(self):
|
||||
# Signal handlers are inherited by forked processes, and we can't easily
|
||||
# reset it from the subprocess. Since kernelapp ignores SIGINT except in
|
||||
# message handlers, we need to temporarily reset the SIGINT handler here
|
||||
# so that bash and its children are interruptible.
|
||||
sig = signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||
try:
|
||||
self.bashwrapper = replwrap.bash()
|
||||
magma = spawn('magma', echo=False, encoding='utf-8')
|
||||
magma.expect('> ')
|
||||
magma.sendline('SetLineEditor(false);')
|
||||
magma.expect('> ')
|
||||
magma.sendline('')
|
||||
self.magmawrapper = replwrap.REPLWrapper(magma, '> ', 'SetPrompt("{}");')
|
||||
finally:
|
||||
signal.signal(signal.SIGINT, sig)
|
||||
|
||||
# Register Bash function to write image data to temporary file
|
||||
self.bashwrapper.run_command(image_setup_cmd)
|
||||
# self.magmawrapper.run_command(image_setup_cmd)
|
||||
|
||||
def do_execute(self, code, silent, store_history=True,
|
||||
user_expressions=None, allow_stdin=False):
|
||||
@@ -67,24 +78,25 @@ class BashKernel(Kernel):
|
||||
|
||||
interrupted = False
|
||||
try:
|
||||
output = self.bashwrapper.run_command(code.rstrip(), timeout=None)
|
||||
output = self.magmawrapper.run_command(code.rstrip(), timeout=None)
|
||||
except KeyboardInterrupt:
|
||||
self.bashwrapper.child.sendintr()
|
||||
self.magmawrapper.child.sendintr()
|
||||
interrupted = True
|
||||
self.bashwrapper._expect_prompt()
|
||||
output = self.bashwrapper.child.before
|
||||
self.magmawrapper._expect_prompt()
|
||||
output = self.magmawrapper.child.before
|
||||
except EOF:
|
||||
output = self.bashwrapper.child.before + 'Restarting Bash'
|
||||
self._start_bash()
|
||||
output = self.magmawrapper.child.before + 'Restarting Bash'
|
||||
self._start_magma()
|
||||
|
||||
if not silent:
|
||||
image_filenames, output = extract_image_filenames(output)
|
||||
#image_filenames, output = extract_image_filenames(output)
|
||||
|
||||
# Send standard output
|
||||
stream_content = {'name': 'stdout', 'text': output}
|
||||
self.send_response(self.iopub_socket, 'stream', stream_content)
|
||||
|
||||
# Send images, if any
|
||||
'''
|
||||
for filename in image_filenames:
|
||||
try:
|
||||
data = display_data_for_image(filename)
|
||||
@@ -93,15 +105,17 @@ class BashKernel(Kernel):
|
||||
self.send_response(self.iopub_socket, 'stream', message)
|
||||
else:
|
||||
self.send_response(self.iopub_socket, 'display_data', data)
|
||||
'''
|
||||
|
||||
if interrupted:
|
||||
return {'status': 'abort', 'execution_count': self.execution_count}
|
||||
|
||||
'''
|
||||
try:
|
||||
exitcode = int(self.bashwrapper.run_command('echo $?').rstrip())
|
||||
except Exception:
|
||||
exitcode = 1
|
||||
|
||||
|
||||
if exitcode:
|
||||
error_content = {'execution_count': self.execution_count,
|
||||
'ename': '', 'evalue': str(exitcode), 'traceback': []}
|
||||
@@ -110,45 +124,6 @@ class BashKernel(Kernel):
|
||||
error_content['status'] = 'error'
|
||||
return error_content
|
||||
else:
|
||||
return {'status': 'ok', 'execution_count': self.execution_count,
|
||||
'payload': [], 'user_expressions': {}}
|
||||
|
||||
def do_complete(self, code, cursor_pos):
|
||||
code = code[:cursor_pos]
|
||||
default = {'matches': [], 'cursor_start': 0,
|
||||
'cursor_end': cursor_pos, 'metadata': dict(),
|
||||
'status': 'ok'}
|
||||
|
||||
if not code or code[-1] == ' ':
|
||||
return default
|
||||
|
||||
tokens = code.replace(';', ' ').split()
|
||||
if not tokens:
|
||||
return default
|
||||
|
||||
matches = []
|
||||
token = tokens[-1]
|
||||
start = cursor_pos - len(token)
|
||||
|
||||
if token[0] == '$':
|
||||
# complete variables
|
||||
cmd = 'compgen -A arrayvar -A export -A variable %s' % token[1:] # strip leading $
|
||||
output = self.bashwrapper.run_command(cmd).rstrip()
|
||||
completions = set(output.split())
|
||||
# append matches including leading $
|
||||
matches.extend(['$'+c for c in completions])
|
||||
else:
|
||||
# complete functions and builtins
|
||||
cmd = 'compgen -cdfa %s' % token
|
||||
output = self.bashwrapper.run_command(cmd).rstrip()
|
||||
matches.extend(output.split())
|
||||
|
||||
if not matches:
|
||||
return default
|
||||
matches = [m for m in matches if m.startswith(token)]
|
||||
|
||||
return {'matches': sorted(matches), 'cursor_start': start,
|
||||
'cursor_end': cursor_pos, 'metadata': dict(),
|
||||
'status': 'ok'}
|
||||
|
||||
|
||||
'''
|
||||
return {'status': 'ok', 'execution_count': self.execution_count,
|
||||
'payload': [], 'user_expressions': {}}
|
||||
Reference in New Issue
Block a user