-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
lsmagic returns JSON which makes for awkward UX in JupyterLab #11793
Comments
That is used by the qtconsole to populate the qt menus dynamically I believe; so we would need to patch qtconsole to run with the cc @ccordoba12 |
No problem in our side, the change should be quite simple to apply in qtconsole. |
I'd like to work on this. If I understand correctly, we want %lsmagic to return plain text instead of JSON in Jupyter Lab like it does in the terminal, right? That said, I'm not really sure where this might happen. I see that core/magics/basic.py defines MagicsDisplay._lsmagic which is called by MagicsDisplay.str but I'm not sure where and how this is changed for Jupyter Lab. Could anyone point me in the right direction? |
This is quite some time ago but are there any news/ workarounds on this issue? |
Sorry I missed your reply @DrAmygdala!! The needed change would be to make |
Thanks for the clarification! From what I understand, Assuming that JupyterLab shouldn't need to make a change, I think I'm missing something here. I assume there's something hiding the need for Perhaps I'm misunderstanding what is meant by default here. Assuming that default is what you get from the IPython shell, I believe it returns a string by default and it can be made to return a JSON by using something that recognizes the |
@DrAmygdala - it's a UX thing, nothing wrong with the underlying pieces of the implementation. But since a primary use case of @ccordoba12 indicated that adapting to this for the purposes of QtConsole wouldn't be a problem. This is a widely used pattern in command-line tools, see for example how |
Yep, I think that's what @fperez is suggesting: leaving the json repr of In that case, I don't think we need to make any changes in Qtconsole because it can't display objects with json repr's. |
I've seen the pattern as well, so I'm not lost there, I think. Perhaps what I'm missing then is the entry point. It seems to me that, to use What's not clear to me is where this default way of getting the Stepping back from that line of thinking, the alternative I can see would be something like: # BasicMagics
# ...
@magic_arguments.magic_arguments()
@magic_arguments.argument('-j', '--json', action="store_true", """Output as JSON""")
@line_magic
def lsmagic(self, parameter_s=''):
args = magic_arguments.parse_argstring(self.lsmagic, parameter_s)
md = MagicsDisplay(self.shell.magics_manager, ignore=[])
if args.json:
return md._repr_json_()
return str(md) |
That looks good enough to me, but I couldn't tell for sure because I don't know the IPython code very well. |
I'm not sure why
lsmagic
needs to return a JSON data structure by default - but the end result is that in JupyterLab, it becomes kind of useless... In Classic calling%lsmagic
produces (clipped for simplicity):while in Lab, this is the output:
Lab defaults to showing JSON reprs when available, which typically makes sense, so while this is a change in behavior re. Classic, I'm inclined to think it's a good step forward.
Users can get the text via
but that's a pretty awkward experience. Do we really need
lsmagic
to produce JSON by default? It seems to me that generating plain text would be fine most of the time, perhaps with a--json/-j
option for JSON output when desired?The text was updated successfully, but these errors were encountered: