Skip to content

Commit f75e44f

Browse files
committed
Remove unused types/methods and clean up the messages interface.
1 parent 1d4547e commit f75e44f

File tree

2 files changed

+25
-66
lines changed

2 files changed

+25
-66
lines changed

kernel.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ type SocketGroup struct {
4444
Key []byte
4545
}
4646

47-
// kernelStatus holds a kernel state, for status broadcast messages.
48-
type kernelStatus struct {
49-
ExecutionState string `json:"execution_state"`
50-
}
51-
5247
// KernelLanguageInfo holds information about the language that this kernel executes code in.
5348
type kernelLanguageInfo struct {
5449
Name string `json:"name"`
@@ -81,6 +76,12 @@ type shutdownReply struct {
8176
Restart bool `json:"restart"`
8277
}
8378

79+
const (
80+
kernelStarting = "starting"
81+
kernelBusy = "busy"
82+
kernelIdle = "idle"
83+
)
84+
8485
// runKernel is the main entry point to start the kernel.
8586
func runKernel(connectionFile string) {
8687

@@ -269,11 +270,11 @@ func handleExecuteRequest(ir *classic.Interp, receipt msgReceipt) error {
269270

270271
// Tell the front-end that the kernel is working and when finished notify the
271272
// front-end that the kernel is idle again.
272-
if err := receipt.PublishKernelStatus(KernelBusy); err != nil {
273+
if err := receipt.PublishKernelStatus(kernelBusy); err != nil {
273274
log.Printf("Error publishing kernel status 'busy': %v\n", err)
274275
}
275276
defer func() {
276-
if err := receipt.PublishKernelStatus(KernelIdle); err != nil {
277+
if err := receipt.PublishKernelStatus(kernelIdle); err != nil {
277278
log.Printf("Error publishing kernel status 'idle': %v\n", err)
278279
}
279280
}()

messages.go

Lines changed: 17 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,10 @@ type msgReceipt struct {
3737
Sockets SocketGroup
3838
}
3939

40-
// OutputMsg holds the data for a pyout message.
41-
type OutputMsg struct {
42-
Execcount int `json:"execution_count"`
43-
Data map[string]string `json:"data"`
44-
Metadata map[string]interface{} `json:"metadata"`
45-
}
46-
47-
// ErrMsg encodes the traceback of errors output to the notebook.
48-
type ErrMsg struct {
49-
EName string `json:"ename"`
50-
EValue string `json:"evalue"`
51-
Traceback []string `json:"traceback"`
52-
}
40+
// bundledMIMEData holds data that can be presented in multiple formats. The keys are MIME types
41+
// and the values are the data formatted with respect to it's MIME type. All bundles should contain
42+
// at least a "text/plain" representation with a string value.
43+
type bundledMIMEData map[string]interface{}
5344

5445
// InvalidSignatureError is returned when the signature on a received message does not
5546
// validate.
@@ -214,32 +205,20 @@ func (receipt *msgReceipt) Reply(msgType string, content interface{}) error {
214205
return receipt.SendResponse(receipt.Sockets.ShellSocket, msg)
215206
}
216207

217-
// MIMEDataBundle holds data that can be presented in multiple formats. The keys are MIME types
218-
// and the values are the data formatted with respect to it's MIME type. All bundle should contain
219-
// at least a "text/plain" representation with a string value.
220-
type MIMEDataBundle map[string]interface{}
221-
222-
// NewTextMIMEDataBundle creates a MIMEDataBundle that only contains a text representation described
223-
// the the parameter 'value'.
224-
func NewTextMIMEDataBundle(value string) MIMEDataBundle {
225-
return MIMEDataBundle{
208+
// newTextMIMEDataBundle creates a bundledMIMEData that only contains a text representation described
209+
// by the value parameter.
210+
func newTextBundledMIMEData(value string) bundledMIMEData {
211+
return bundledMIMEData{
226212
"text/plain": value,
227213
}
228214
}
229215

230-
type KernelStatus string
231-
232-
const (
233-
KernelStarting KernelStatus = "starting"
234-
KernelBusy = "busy"
235-
KernelIdle = "idle"
236-
)
237-
238-
// PublishKernelStatus publishes a status message notifying front-ends of the state the kernel is in.
239-
func (receipt *msgReceipt) PublishKernelStatus(status KernelStatus) error {
216+
// PublishKernelStatus publishes a status message notifying front-ends of the state the kernel is in. Supports
217+
// states "starting", "busy", and "idle".
218+
func (receipt *msgReceipt) PublishKernelStatus(status string) error {
240219
return receipt.Publish("status",
241220
struct {
242-
ExecutionState KernelStatus `json:"execution_state"`
221+
ExecutionState string `json:"execution_state"`
243222
}{
244223
ExecutionState: status,
245224
},
@@ -264,13 +243,13 @@ func (receipt *msgReceipt) PublishExecutionInput(execCount int, code string) err
264243
func (receipt *msgReceipt) PublishExecutionResult(execCount int, output string) error {
265244
return receipt.Publish("execute_result",
266245
struct {
267-
ExecCount int `json:"execution_count"`
268-
Data MIMEDataBundle `json:"data"`
269-
Metadata MIMEDataBundle `json:"metadata"`
246+
ExecCount int `json:"execution_count"`
247+
Data bundledMIMEData `json:"data"`
248+
Metadata bundledMIMEData `json:"metadata"`
270249
}{
271250
ExecCount: execCount,
272-
Data: NewTextMIMEDataBundle(output),
273-
Metadata: make(MIMEDataBundle),
251+
Data: newTextBundledMIMEData(output),
252+
Metadata: make(bundledMIMEData),
274253
},
275254
)
276255
}
@@ -289,24 +268,3 @@ func (receipt *msgReceipt) PublishExecutionError(err string, trace []string) err
289268
},
290269
)
291270
}
292-
293-
type Stream string
294-
295-
const (
296-
StreamStdout Stream = "stdout"
297-
StreamStderr = "stderr"
298-
)
299-
300-
// PublishWriteStream prints the data string to a stream on the front-end. This is
301-
// either `StreamStdout` or `StreamStderr`.
302-
func (receipt *msgReceipt) PublishWriteStream(stream Stream, data string) error {
303-
return receipt.Publish("stream",
304-
struct {
305-
Stream Stream `json:"name"`
306-
Data string `json:"text"`
307-
}{
308-
Stream: stream,
309-
Data: data,
310-
},
311-
)
312-
}

0 commit comments

Comments
 (0)