Jupyter v5 protocol - #70
Conversation
| import ( | ||
| "fmt" | ||
| "go/token" | ||
|
|
There was a problem hiding this comment.
please remove that blank line (we group stdlib imports together)
| "log" | ||
| "os" | ||
|
|
||
| "runtime" |
There was a problem hiding this comment.
please keep the stdlib imports together
|
@SpencerPark This is great. I will review asap, and thank you so much for the contribution. FYI, I am working in the |
|
@SpencerPark This adds some great improvements. I would like to integrate this into the version 1 refactor if that is ok with you? I would really love to focus on that, as it will be a huge improvement in general. Do you think you could re-arrange this to merge into that branch? I don't want to burden you too much, so I can help with the re-arranging if you like based on this PR. Just let me know your thoughts? We can always merge this into master prior to the |
|
@dwhitena using a less hacky interpreter sounds fantastic! I'm still new to Go so I don't have much to offer with respect to comments on libraries. I would really like to help get v1 out as it looks to be quite the improvement. I don't mind integrating this into the v1 branch but I'll have to see about how to actually switch up the PR to do that. Should it just be a separate one or can I salvage this one? |
|
That would be awesome @SpencerPark! I think you could do this: https://github.com/blog/2224-change-the-base-branch-of-a-pull-request. It's so great to have you as a contributor, and I can't wait to integrate your changes. (Also, we would love to have you in the discussion at #data-science in Gophers slack. Although happy to interact here as well. Feel free to reach out if I can offer any help in getting plugged into the Go data community in general.) |
2edaa6b to
5e1f16d
Compare
5e1f16d to
825aefd
Compare
dwhitena
left a comment
There was a problem hiding this comment.
This is awesome!!! Thank you so much. Some huge improvements here overall. Most of my comments are small. The main things that need to be addressed are the handling of errors for Publishing messages.
| ExecutionState string `json:"execution_state"` | ||
| } | ||
|
|
||
| // KernelLanguageInfo holds information about the language that this kernel executes code in |
There was a problem hiding this comment.
Comment should be a complete sentence (i.e., including periods etc.). This is because these comments turn into the GoDocs. Minor thing, but should be consistent throughout.
| NBConvertExporter string `json:"nbconvert_exporter"` | ||
| } | ||
|
|
||
| // HelpLink stores data to be displayed in the help menu of the notebook |
| ExecCounter++ | ||
| } | ||
|
|
||
| // Prepare the map that will hold the reply content |
There was a problem hiding this comment.
Period. I will stop commenting on these, but you get the idea. I would just scrub the comments.
|
|
||
| // Tell the front-end that the kernel is working and when finished notify the | ||
| // front-end that the kernel is idle again | ||
| receipt.PublishKernelBusy() |
There was a problem hiding this comment.
I might prefer to just put the Publish method inline here for busy, idle, etc. messages. This could be a one line call and would avoid hiding what's actually happening in these methods. Also, I would handle the error here. Looks like the error from Publish isn't handled in these methods.
There was a problem hiding this comment.
Also, many of these publish messages (busy, idle, etc.) appear to be identical minus the actual status. Could you just pass in the status in as an argument and not duplicate the methods. You could just have PublishKernelStatus().
There was a problem hiding this comment.
The reasoning behind hiding the message being sent is to encapsulate the details of the protocol inside messages.go. This should make it easier to maintain when Jupyter updates again in the future.
I agree with the second comment, I can clean up the kernel status messages.
There was a problem hiding this comment.
I guess I could see that separation of concerns. Good point.
| // Tell the front-end that the kernel is working and when finished notify the | ||
| // front-end that the kernel is idle again | ||
| receipt.PublishKernelBusy() | ||
| defer receipt.PublishKernelIdle() |
|
|
||
| // PublishExecuteResult publishes a serialized error that was encountered during execution. | ||
| func (receipt *msgReceipt) PublishExecutionError(err string, trace string) { | ||
| receipt.Publish("error", |
| ) | ||
| } | ||
|
|
||
| // WriteStreamData holds data to be written to a stream (stdout, stderr) |
|
|
||
| // PublishWriteStdOut publishes the data string to the front-end's stdout | ||
| func (receipt *msgReceipt) PublishWriteStdOut(data string) { | ||
| receipt.Publish("stream", |
|
|
||
| // PublishWriteStdErr publishes the data string to the front-end's stderr | ||
| func (receipt *msgReceipt) PublishWriteStdErr(data string) { | ||
| receipt.Publish("stream", |
| } | ||
|
|
||
| // WriteStreamData holds data to be written to a stream (stdout, stderr) | ||
| type WriteStreamData struct { |
There was a problem hiding this comment.
See comment above on types.
fix godoc comment formatting.
|
I'm getting a bad kernel info error when starting a Go kernel notebook: Any ideas @SpencerPark? |
|
@SpencerPark My old Python is likely the problem:
|
|
The absence of the When starting the kernel a log message should appear like the following While adding the field I noticed the |
dwhitena
left a comment
There was a problem hiding this comment.
Just a few nitpicks and we are good to merge! Awesome work.
| return receipt.SendResponse(receipt.Sockets.ShellSocket, msg) | ||
| } | ||
|
|
||
| // MIMEDataBundle holds data that can be presented in multiple formats. The keys are MIME types |
There was a problem hiding this comment.
Let's move this and any other types up to the top of messages.go, with all the funcs below.
| StreamStderr = "stderr" | ||
| ) | ||
|
|
||
| // PublishWriteStream prints the data string to a stream on the front-end. This is |
There was a problem hiding this comment.
Is this function or the above constants and types used at this point? If not, let's remove and add them when needed.
|
|
||
| type KernelStatus string | ||
|
|
||
| const ( |
There was a problem hiding this comment.
I suggest the following minor changes regarding these constants and the PublishKernelStatus function:
- Let's let
PublishKernelStatusaccept a string rather than theKernelStatustype. Not sure that the type buys us a lot, unless you have something specific in mind. It doesn't prevent other devs from defining a new KernelStatus that we didn't anticipate, and we are only going to use the constant statuses. - We can then remove the
KernelStatustype and move theconst (...)declarations to the top ofkernel.go, because they are really relevant to the kernel itself, not the messaging. - Lastly, I think we can make the status constants unexported.
| // MIMEDataBundle holds data that can be presented in multiple formats. The keys are MIME types | ||
| // and the values are the data formatted with respect to it's MIME type. All bundle should contain | ||
| // at least a "text/plain" representation with a string value. | ||
| type MIMEDataBundle map[string]interface{} |
There was a problem hiding this comment.
I think we can make this type unexported right?
|
This works for me now without error! LGTM. Merging. |

Communicate with front-ends using the current Jupyter messaging spec.
See http://jupyter-client.readthedocs.io/en/latest/messaging.html