gojupyterscaffold

package
v0.0.0-...-45aac0a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2019 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package gojupyterscaffold provides a scaffold of Jupyter kernel implemented by Go.

References: https://github.com/ipython/ipykernel/blob/master/ipykernel/kernelbase.py https://github.com/jupyter/jupyter_client/blob/master/jupyter_client/session.py

Misc: ZMQ pubsub with inproc is broken (https://github.com/JustinTulloss/zeromq.node/issues/22) though it's not used in this code now.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompleteReply

type CompleteReply struct {
	// The list of all matches to the completion request, such as
	// ['a.isalnum', 'a.isalpha'] for the above example.
	Matches []string `json:"matches"`

	// The range of text that should be replaced by the above matches when a completion is accepted.
	// typically cursor_end is the same as cursor_pos in the request.
	CursorStart int `json:"cursor_start"`
	CursorEnd   int `json:"cursor_end"`

	// status should be 'ok' unless an exception was raised during the request,
	// in which case it should be 'error', along with the usual error message content
	// in other messages.
	Status string `json:"status"`
}

type CompleteRequest

type CompleteRequest struct {
	// The code context in which completion is requested
	// this may be up to an entire multiline cell, such as
	// 'foo = a.isal'
	Code string `json:"code"`
	// The cursor position within 'code' (in unicode characters) where completion is requested
	CursorPos int `json:"cursor_pos"`
}

http://jupyter-client.readthedocs.io/en/latest/messaging.html#completion

type DisplayData

type DisplayData struct {
	Data      map[string]interface{} `json:"data,omitempty"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
	Transient map[string]interface{} `json:"transient,omitempty"`
}

DisplayData represents display_data defined in http://jupyter-client.readthedocs.io/en/latest/messaging.html#display-data

omitempty is important not to output "metadata: null", which results in Failed validating u'type' in display_data[u'properties'][u'metadata'] in Jupyter notebook.

c.f. The definition of MIME-type and the right format of value: Search for "MIME_HTML" https://github.com/jupyter/notebook/blob/master/notebook/static/notebook/js/outputarea.js A special handling of "application/json" https://github.com/jupyter/jupyter_client/blob/master/jupyter_client/adapter.py

type ExecuteRequest

type ExecuteRequest struct {
	Code         string `json:"code"`
	Silent       bool   `json:"silent"`
	StoreHistory bool   `json:"store_history"`
	AllowStdin   bool   `json:"allow_stdin"`
	StopOnError  bool   `json:"stop_on_error"`
}

type ExecuteResult

type ExecuteResult struct {
	Status         string `json:"status"`
	ExecutionCount int    `json:"execution_count,omitempty"`
}

http://jupyter-client.readthedocs.io/en/latest/messaging.html#execution-results

type InspectReply

type InspectReply struct {
	// 'ok' if the request succeeded or 'error', with error information as in all other replies.
	Status string `json:"status"`
	// found should be true if an object was found, false otherwise
	Found bool `json:"found"`
	// data can be empty if nothing is found
	Data map[string]interface{} `json:"data,omitempty"`
}

See http://jupyter-client.readthedocs.io/en/latest/messaging.html#introspection

type InspectRequest

type InspectRequest struct {
	Code      string `json:"code"`
	CursorPos int    `json:"cursor_pos"`
	// The level of detail desired.  In IPython, the default (0) is equivalent to typing
	// 'x?' at the prompt, 1 is equivalent to 'x??'.
	// The difference is up to kernels, but in IPython level 1 includes the source code
	// if available.
	DetailLevel int `json:"detail_level"`
}

See http://jupyter-client.readthedocs.io/en/latest/messaging.html#introspection

type IsCompleteReply

type IsCompleteReply struct {
	// One of 'complete', 'incomplete', 'invalid', 'unknown'
	Status string `json:"status"`
	// If status is 'incomplete', indent should contain the characters to use
	// to indent the next line. This is only a hint: frontends may ignore it
	// and use their own autoindentation rules. For other statuses, this
	// field does not exist.
	Indent string `json:"indent"`
}

http://jupyter-client.readthedocs.io/en/latest/messaging.html#code-completeness

type IsCompleteRequest

type IsCompleteRequest struct {
	// The code entered so far as a multiline string
	Code string `json:"code"`
}

http://jupyter-client.readthedocs.io/en/latest/messaging.html#code-completeness

type KernelInfo

type KernelInfo struct {
	ProtocolVersion       string             `json:"protocol_version"`
	Implementation        string             `json:"implementation"`
	ImplementationVersion string             `json:"implementation_version"`
	LanguageInfo          KernelLanguageInfo `json:"language_info"`
	Banner                string             `json:"banner"`
}

type KernelLanguageInfo

type KernelLanguageInfo struct {
	Name          string `json:"name"`
	Version       string `json:"version"`
	Mimetype      string `json:"mimetype"`
	FileExtension string `json:"file_extension"`
}

type RequestHandlers

type RequestHandlers interface {
	HandleKernelInfo() KernelInfo
	// HandleExecuteRequest handles execute_request.
	// writeStream sends stdout/stderr texts and writeDisplayData sends display_data
	// (or update_display_data if update is true) to the client.
	HandleExecuteRequest(ctx context.Context,
		req *ExecuteRequest,
		writeStream func(name, text string),
		writeDisplayData func(data *DisplayData, update bool)) *ExecuteResult
	HandleComplete(req *CompleteRequest) *CompleteReply
	HandleInspect(req *InspectRequest) *InspectReply
	// http://jupyter-client.readthedocs.io/en/latest/messaging.html#code-completeness
	HandleIsComplete(req *IsCompleteRequest) *IsCompleteReply
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(connectionFile string, handlers RequestHandlers) (server *Server, err error)

NewServer returns a new jupyter kernel server.

func (*Server) Context

func (s *Server) Context() context.Context

Context returns the context of the server

func (*Server) Loop

func (s *Server) Loop()

Loop starts the server main loop

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL