Skip to content

Support bash kernel in notebook-http mode #382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions kernel_gateway/gatewayapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,18 @@ def init_http_server(self):
'no available port could be found.')
self.exit(1)

def start(self):
"""Starts an IO loop for the application."""
def start_app(self):
"""Starts the application (with ioloop to follow). """
super(KernelGatewayApp, self).start()
self.log.info('Jupyter Kernel Gateway {} is available at http{}://{}:{}'.format(
KernelGatewayApp.version, 's' if self.keyfile else '', self.ip, self.port
))

def start(self):
"""Starts an IO loop for the application."""

self.start_app()

self.io_loop = ioloop.IOLoop.current()

if sys.platform != 'win32':
Expand Down
2 changes: 2 additions & 0 deletions kernel_gateway/notebook_http/request_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def format_request(bundle, kernel_language=''):
bundle = json.dumps(bundle)
if kernel_language.lower() == 'perl':
statement = "my $REQUEST = {}".format(bundle)
elif kernel_language.lower() == 'bash':
statement = "REQUEST={}".format(bundle)
else:
statement = "REQUEST = {}".format(bundle)
return statement
Expand Down
5 changes: 5 additions & 0 deletions kernel_gateway/tests/notebook_http/test_request_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,8 @@ def test_format_request_with_a_kernel_language_perl(self):
test_request = ('''{"body": "", "headers": {}, "args": {}, "path": {}}''')
request_code = format_request(test_request, 'perl')
self.assertTrue(request_code.startswith("my $REQUEST"), 'Call format_request with a kernel language "perl" was not formatted correctly')

def test_format_request_with_a_kernel_language_bash(self):
test_request = ('''{"body": "", "headers": {}, "args": {}, "path": {}}''')
request_code = format_request(test_request, 'bash')
self.assertTrue(request_code.startswith("REQUEST=\"{"), 'Call format_request with a kernel language "bash" was not formatted correctly')
12 changes: 12 additions & 0 deletions kernel_gateway/tests/test_gatewayapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import logging
import nbformat
import os
from io import StringIO
import unittest
from unittest.mock import patch
from kernel_gateway.gatewayapp import KernelGatewayApp, ioloop
from kernel_gateway import __version__
from ..notebook_http.swagger.handlers import SwaggerSpecHandler
from tornado.testing import AsyncHTTPTestCase, ExpectLog

Expand Down Expand Up @@ -101,6 +104,15 @@ def test_load_notebook_local(self):
app.init_configurables()
self.assertEqual(app.seed_notebook, nb_contents)

@patch('sys.stderr', new_callable=StringIO)
def test_start_banner(self, stderr):

app = KernelGatewayApp()
app.init_configurables()
app.start_app()
banner = stderr.getvalue()
self.assertIn(f"Jupyter Kernel Gateway {__version__}", banner)


class TestGatewayAppBase(AsyncHTTPTestCase, ExpectLog):
"""Base class for integration style tests using HTTP/Websockets against an
Expand Down