Closed fperez closed 2 years ago
With this workflow, it's just running one command, enter, paste, enter, click on the GH green authorize button, close tab, done. I kind of like it :)
BTW - I'm going to make a PR against IPython adding this new magic:
from IPython.core.magic import register_line_magic
@register_line_magic
def pym(line):
"Equivalent to 'python -m'"
import runpy
runpy.run_module(line)
which then gives us this clean workflow (my ghauth
module is the same as yours, just with the above JS code and a shorter name for convenience):
The idea here is that, once we put %pym
into IPython, then any python package/module that offers a python -m
entry point can become a cmd line magic as %pym pkg
! And we can then expose nice Jupyter-oriented functionality in packages without the need for them to explicitly register magics or have users import anything :)
@fperez wow this is awesome! PR would be lovely - especially if we can make the Javascript
calls conditional on us running in a notebook, so this could continue to run in terminals still. HPC users might need that still.
Yup! I haven't moved forward with the PR precisely b/c I'm thinking of how to make it as smooth as possible for all use cases, terminal and notebook, without introducing user-facing annoyances... I think I know how to proceed, I just need to block a couple of hours to do a bit of refactoring on your code and add a clean version of the above. But having this scratch proof of concept helps :)
Hey, I found a better solution! It turns out that %run
already provides a -m
flag! I'll make a quick PR now, and we can discuss there :)
This was fixed up in #8!
Try running this version in a notebook:
and then just call
main()
either in the notebook or a console attached to it. I think works really nicely!Do you want a PR for this? Or you can go ahead and do it :)
I'd refactor the code a bit to reuse more at the cmd line and Jupyter, and I'd add a magic, say %ghauth, to shorten this. We can then add the magic to
__init__
and pre-import it, or even add it to a button/menu on the UI that shows the current GH connection status and lets you refresh the auth by clicking on it...But anyway, I think this is now good enough for everyday use, esp. if we add a magic we preload or similar for convenience....