Documentation
¶
Overview ¶
Package jupyter serves the Jupyter messaging protocol over ZeroMQ for a kernel: the five channels a connection file names, the signing of every message, and the request kinds a front end sends, each answered by an Engine. The engine over the REPL session is in this package too.
Index ¶
- Constants
- Variables
- func Stderr() *log.Logger
- type Completion
- type ConnectionInfo
- type Engine
- type ExecError
- type Header
- type HelpLink
- type Info
- type Inspection
- type IsCompleteStatus
- type Kernel
- type LanguageInfo
- type MIMEBundle
- type Message
- type Output
- type REPLEngine
- func (e *REPLEngine) Complete(code string, cursor int) Completion
- func (e *REPLEngine) Execute(code string, out Output) error
- func (e *REPLEngine) Inspect(code string, cursor int, detail int) Inspection
- func (e *REPLEngine) Interrupt()
- func (e *REPLEngine) IsComplete(code string) (IsCompleteStatus, string)
- func (e *REPLEngine) Session() *repl.Session
- func (e *REPLEngine) Shutdown(bool)
- func (e *REPLEngine) String() string
Constants ¶
const ProtocolVersion = "5.3"
ProtocolVersion is the version of the Jupyter messaging protocol the kernel speaks.
Variables ¶
var ( ErrNoDelimiter = errors.New("no <IDS|MSG> delimiter") ErrShortMessage = errors.New("fewer than four frames after the delimiter") ErrBadSignature = errors.New("signature does not verify") )
Errors a wire message is refused for.
Functions ¶
Types ¶
type Completion ¶
Completion is the answer to a completion request: the candidates, and the span of the code they replace, as rune offsets.
type ConnectionInfo ¶
type ConnectionInfo struct {
Transport string `json:"transport"`
IP string `json:"ip"`
ShellPort int `json:"shell_port"`
IOPubPort int `json:"iopub_port"`
StdinPort int `json:"stdin_port"`
ControlPort int `json:"control_port"`
HBPort int `json:"hb_port"`
Key string `json:"key"`
SignatureScheme string `json:"signature_scheme"`
KernelName string `json:"kernel_name,omitempty"`
}
ConnectionInfo is what a Jupyter connection file holds: where each channel listens, and the key messages are signed with.
func ReadConnectionFile ¶
func ReadConnectionFile(path string) (ConnectionInfo, error)
ReadConnectionFile reads the connection file a front end wrote for the kernel.
func (ConnectionInfo) Validate ¶
func (c ConnectionInfo) Validate() error
Validate reports a connection the kernel cannot serve: a transport other than TCP or IPC, a channel without a port, or a signature scheme other than HMAC-SHA256 when a key is set.
type Engine ¶
type Engine interface {
// Execute runs one cell, writing what it produces to out, and reports a
// failure as an *ExecError; out.Error is the kernel's to call.
Execute(code string, out Output) error
Complete(code string, cursor int) Completion
IsComplete(code string) (IsCompleteStatus, string)
Inspect(code string, cursor int, detail int) Inspection
// Interrupt stops the cell running, if one is.
Interrupt()
// Shutdown ends the engine; restart says whether another is to follow.
Shutdown(restart bool)
}
Engine is what the kernel asks of the language: it runs cells and answers what a front end asks about code. The kernel calls Execute, Complete, IsComplete and Inspect one at a time; Interrupt may be called while Execute runs, from another goroutine.
type ExecError ¶
ExecError is how an engine reports a cell that failed: the name of the error, what it says, and the traceback lines.
type Header ¶
type Header struct {
MsgID string `json:"msg_id"`
Session string `json:"session"`
Username string `json:"username"`
Date string `json:"date"`
MsgType string `json:"msg_type"`
Version string `json:"version"`
}
Header identifies a message: who sent it, in which session, and what kind it is.
type Info ¶
type Info struct {
Implementation string
ImplementationVersion string
Language LanguageInfo
Banner string
HelpLinks []HelpLink
}
Info is what the kernel tells a front end about itself.
type Inspection ¶
type Inspection struct {
Found bool
Data MIMEBundle
}
Inspection is the answer to an inspection request: whether the cursor is on something known, and what to show about it.
type IsCompleteStatus ¶
type IsCompleteStatus string
IsCompleteStatus is the answer to whether a cell is complete.
const ( Complete IsCompleteStatus = "complete" Incomplete IsCompleteStatus = "incomplete" Invalid IsCompleteStatus = "invalid" Unknown IsCompleteStatus = "unknown" )
The answers the protocol admits.
type Kernel ¶
type Kernel struct {
// contains filtered or unexported fields
}
Kernel serves one connection: the five channels, each on its own socket, shell requests answered in order and control requests beside them.
func (*Kernel) Interrupt ¶
func (k *Kernel) Interrupt()
Interrupt stops the cell running, as a SIGINT from the front end does.
func (*Kernel) Listen ¶
func (k *Kernel) Listen(ctx context.Context) (ConnectionInfo, error)
Listen binds the five channels and returns the connection they are bound on. A TCP channel whose port is 0 is bound on a free port, and the connection returned names the port taken; any other port is bound as given, so a port already in use fails here. ctx ending closes the sockets, whether or not Serve was called. A binding not yet served must be served before the kernel can listen again.
type LanguageInfo ¶
type LanguageInfo struct {
Name string `json:"name"`
Version string `json:"version"`
MIMEType string `json:"mimetype"`
FileExtension string `json:"file_extension"`
PygmentsLexer string `json:"pygments_lexer,omitempty"`
CodeMirrorMode string `json:"codemirror_mode,omitempty"`
}
LanguageInfo is what the kernel tells a front end about its language.
type MIMEBundle ¶
MIMEBundle is the data of one output, keyed by MIME type, each the representation a front end may pick. Text values are strings; a JSON value is any value that marshals to the JSON a front end expects.
type Message ¶
type Message struct {
// Identities are the routing frames a ROUTER socket prepends, echoed back on
// the reply so it reaches the sender.
Identities [][]byte
Header Header
ParentHeader Header
Metadata map[string]any
Content map[string]any
Buffers [][]byte
}
Message is one Jupyter message, decoded from or encoded to its wire frames.
type Output ¶
type Output interface {
// Stream writes text to a stream: "stdout" or "stderr".
Stream(name, text string)
// Display shows a rich output.
Display(data MIMEBundle, metadata map[string]any)
// Result shows the value of the cell: the last expression's.
Result(data MIMEBundle)
// Error reports a failure, with the lines a traceback shows for it.
Error(name, value string, traceback []string)
}
Output is where an engine writes what a cell produces, in the order produced.
type REPLEngine ¶
type REPLEngine struct {
// contains filtered or unexported fields
}
REPLEngine runs cells against a REPL session: each cell is split into the statements the prompt would read from it, and each statement is submitted as the prompt submits it, so a notebook and a terminal session behave alike.
func NewREPLEngine ¶
func NewREPLEngine(session *repl.Session) *REPLEngine
NewREPLEngine is an engine over the session.
func (*REPLEngine) Complete ¶
func (e *REPLEngine) Complete(code string, cursor int) Completion
Complete answers completion at the cursor: the prompt completes a line, so the cursor's line is completed, and the span replaced is spelled back in the cell's rune offsets.
func (*REPLEngine) Execute ¶
func (e *REPLEngine) Execute(code string, out Output) error
Execute runs the cell's statements in order and stops at the first that fails, as a cell of any other kernel does.
func (*REPLEngine) Inspect ¶
func (e *REPLEngine) Inspect(code string, cursor int, detail int) Inspection
Inspect describes the name under the cursor as %print does.
func (*REPLEngine) Interrupt ¶
func (e *REPLEngine) Interrupt()
Interrupt stops the statement running.
func (*REPLEngine) IsComplete ¶
func (e *REPLEngine) IsComplete(code string) (IsCompleteStatus, string)
IsComplete reports whether the cell is ready to run: a declaration left open by a brace, parenthesis or bracket is not, and its continuation is indented.
func (*REPLEngine) Session ¶
func (e *REPLEngine) Session() *repl.Session
Session is the session the engine runs.
func (*REPLEngine) Shutdown ¶
func (e *REPLEngine) Shutdown(bool)
Shutdown has nothing to release: the session is the process's.