-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Add a metadata attribute to messages #2051
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
Conversation
|
Of course, docs need to change as well, and there may be other places in the codebase that would need to be changed. I'm willing to do those, but I want to make sure that you guys are good with the idea before putting in that time. |
|
I think this is sensible, let's hear what @ellisonbg has to say. |
|
As we experiment with this, we realize that we also need to add this sort of information on display_data messages, pyout messages, etc. Maybe it would be cleaner to add a metadata attribute to the session object, and anytime the session sends a message (on the iopub channel?), it adds the metadata to the message. Should this sort of iopub-level metadata be added to the header instead of the content, though? |
|
Looking into things even more, it seems like if we just add the capability to define a default subheader in the session object, that might do all that we want. |
|
If we did put the metadata in the subheader, we'd also need to modify kernel.js to pass the header information (or maybe just a header metadata attribute) to callbacks, in the Kernel.execute function. |
|
I just added some commits which implement a configurable subheader object and also pass the header to javascript callbacks. |
|
Okay, here's a third idea, since having the metadata in the header just seems awkward. For one, the header lives on as parent_headers for possibly a long time. Secondly, an application (like callbacks in javascript) could care about metadata, but would probably rarely care about message ids or session uuids, so there seems to be a logical distinction between metadata/subheader and the header. In a sense, the header deals with routing, while metadata deals with the content. Instead, how about adding a (optional?) |
|
I like the notion of metadata being a fundamental message property. Since we already put it in the content for some messages, I would say we should extend that to metadata being an optional key in the content dict of all message types. I'm not 100% sure about the API for this, at the Session level or otherwise. |
|
Further thinking out loud: There are three options:
Personally, I'm thinking 2. is the best choice right now, as @jasongrout proposed. |
|
I'm liking the idea of a metadata top-level element more. The distinction from the content is elegant, in my mind. I think we may be to the point where a post to ipython-dev would make sense to get a wider audience; I'll post right now. |
|
I think the patches above add a top-level metadata attribute to messages in the right place. When the design decision has been made, I can squash the commits to make the history make more sense. It'd be nice if github kept track of old versions of the description, so we could change it, but not lose context of the comments at the top. |
|
I added a few more commits to start working towards having metadata a mandatory element of messages. There might still be parts where I'm missing things (for example, the javascript code that creates messages?) I'm stopping working on this until a decision is made about a design direction, though, since the source changes now seem to be more and more involved. |
|
After SciPy discussion with enthought/enaml, we are definitely going with your metadata approach. I will check the JS to see if there's anything more that needs to be done. One thing I would do is totally remove the subheader, and put all uses of that into metadata. Since I believe that 100% of subheader code is written by me, I am happy to do that. |
|
Great! Who is enaml? |
|
https://github.com/enthought/enaml Chris Colbert is the main developer here. |
|
Can you add the few commits from my branch? They remove subheader entirely, using metadata instead, and make sure the notebook works as well. @ellisonbg can you weigh in on this one? |
|
Sure. Can you just submit a pull request to my branch to make it easy? |
|
I tried to, but it didn't let me. Perhaps you have pull requests disabled for your branch? You can still do |
|
It didn't let you? That's very odd---what did it say? I don't even know if there is a way to disable pull requests on a branch. I know I can pull, but I thought it would be good to learn the ins and outs of github better. If you don't want to diagnose this further, though, I can just pull. I just did it in a test branch and it merged just fine. |
|
(so just let me know if you want to try to figure github out better, or if you want me to just pull and get on with coding.) |
|
I honestly have no idea why. But in the list of available pull targets in the New PR UI, which includes dozens of IPython forks, your fork is not listed. I think just give it a pull, and maybe it's a GitHub bug that will work itself out magically. |
|
huh, interesting. Okay, I pulled and pushed. |
|
Also, are there any other implementations of the spec that need to be changed? qtconsole or anything like that? |
|
The Session object is the only implementation, shared by all IPython applications. The subheader was only used at the application level in IPython.parallel, so there shouldn't be anything to change anywhere else. |
…level default metadata attribute.
…ges" This reverts commit c32771c.
|
Great! |
|
This actually needs a rebase, due to a cleanup PR earlier in the month. It's just on the blocks of assertEquals in test_session in one commit. If you want to do that rebase, go ahead. I also made a rebased version of this branch at minrk/metadata-rebased, so you can just use my version in-place with: |
|
If you've already done the work, great! I just pushed the rebased branch. It also probably wouldn't hurt to squash some of my commits down, since my early commits were just exploring ideas. |
|
Since this PR is owned by you, you would have to do the squashing. You are welcome to do a |
|
Well, it's a question about the style of the project---do you want the thinking process, the scaffolding, as it were, or do you want a nice finished set of commits. If you think it can go in as-is, that's great. If you want me to clean it up a bit, let me know. |
|
We definitely don't require that each commit be final - cleaning up a PR is usually up to the style preferences of the committer (I tend to try to squash my own typos), but not enforced unless a big mess is made. |
|
Test results for commit 58134b4 merged into master
Not available for testing: python3.1 |
Add a metadata attribute to messages subheader is removed in favor of the new metadata dict, reducing degeneracy.
|
I guess we were working past each other. I just cleaned things up and force pushed again, but I think it was after you merged, so hopefully things didn't get messed up. |
|
I'm glad it's in! Now we can run the Sage cell server off of ipython master rather than our own custom branch. |
|
Sorry about that - we are working through our outstanding PRs, and I wanted this one in before others of mine that might have caused this to need another rebase. Thanks for the work! |
Add a metadata attribute to messages subheader is removed in favor of the new metadata dict, reducing degeneracy.
We'd like to easily add metadata to messages. Adding an optional top-level metadata attribute to messages seems like a natural solution.
With this pull request, we can add metadata to a session using a context handler like:
(is there a better way to get the session object than to get it from sys.stdout?)
Old Description
We'd like to attach some metadata to stdout and stderr messages, for example, indicating where
the frontend should put the output. It would be really convenient if sys.stdout and sys.stderr (which I think is
IPython.zmq.iostream.OutStream, right?) had a 'metadata' attribute that could be set and would be added to each outgoing message. This would also change the messaging spec to add a 'metadata' attribute to the
content dict for stream messages (just like display_data messages already have).