-
Notifications
You must be signed in to change notification settings - Fork 263
Jupyter v5 protocol #70
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
Jupyter v5 protocol #70
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not an expert wrt Jupyter protocol (including v5 :P)
thus, just a superficial review...
execution.go
Outdated
@@ -2,92 +2,77 @@ package main | |||
|
|||
import ( | |||
"fmt" | |||
"go/token" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove that blank line (we group stdlib imports together)
gophernotes.go
Outdated
@@ -8,6 +8,8 @@ import ( | |||
"log" | |||
"os" | |||
|
|||
"runtime" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
kernel.go
Outdated
// kernelStatus holds a kernel state, for status broadcast messages. | ||
type kernelStatus struct { | ||
ExecutionState string `json:"execution_state"` | ||
} | ||
|
||
// KernelLanguageInfo holds information about the language that this kernel executes code in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
kernel.go
Outdated
NBConvertExporter string `json:"nbconvert_exporter"` | ||
} | ||
|
||
// HelpLink stores data to be displayed in the help menu of the notebook |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Period in Comment.
kernel.go
Outdated
@@ -244,8 +263,18 @@ func handleExecuteRequest(ir *classic.Interp, receipt msgReceipt) error { | |||
ExecCounter++ | |||
} | |||
|
|||
// Prepare the map that will hold the reply content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Period. I will stop commenting on these, but you get the idea. I would just scrub the comments.
kernel.go
Outdated
content["execution_count"] = ExecCounter | ||
|
||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I could see that separation of concerns. Good point.
kernel.go
Outdated
// 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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above.
messages.go
Outdated
|
||
// PublishExecuteResult publishes a serialized error that was encountered during execution. | ||
func (receipt *msgReceipt) PublishExecutionError(err string, trace string) { | ||
receipt.Publish("error", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error?
messages.go
Outdated
) | ||
} | ||
|
||
// WriteStreamData holds data to be written to a stream (stdout, stderr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Period in comment.
messages.go
Outdated
|
||
// PublishWriteStdOut publishes the data string to the front-end's stdout | ||
func (receipt *msgReceipt) PublishWriteStdOut(data string) { | ||
receipt.Publish("stream", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error?
messages.go
Outdated
|
||
// PublishWriteStdErr publishes the data string to the front-end's stderr | ||
func (receipt *msgReceipt) PublishWriteStdErr(data string) { | ||
receipt.Publish("stream", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error?
messages.go
Outdated
} | ||
|
||
// WriteStreamData holds data to be written to a stream (stdout, stderr) | ||
type WriteStreamData struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few nitpicks and we are good to merge! Awesome work.
messages.go
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this and any other types up to the top of messages.go, with all the funcs below.
messages.go
Outdated
StreamStderr = "stderr" | ||
) | ||
|
||
// PublishWriteStream prints the data string to a stream on the front-end. This is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this function or the above constants and types used at this point? If not, let's remove and add them when needed.
messages.go
Outdated
|
||
type KernelStatus string | ||
|
||
const ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest the following minor changes regarding these constants and the PublishKernelStatus
function:
- Let's let
PublishKernelStatus
accept a string rather than theKernelStatus
type. 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
KernelStatus
type 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.
messages.go
Outdated
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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