jupyterhub / binderhub

Run your code in the cloud, with technology so advanced, it feels like magic!
https://binderhub.readthedocs.io
BSD 3-Clause "New" or "Revised" License
2.57k stars 390 forks source link

Way to share lab python magic with different commands #1454

Open alex-orange opened 2 years ago

alex-orange commented 2 years ago

When using binderhub with auth (as for instance described here https://binderhub.readthedocs.io/en/latest/authentication.html) the suggestion is to set jupyterhub.singleuser.cmd to jupyterhub-singleuser. Doing so overrides the magic that has been added to default to lab if it's installed. I can handle this by taking said magic out of the values.yaml file and adding it to my config.yaml file, as shown below, but it would be nice if there were a different variable to put things like "jupyter-notebook" or "jupyethub-singleuser" in that then got substituted into the os.execvp bit. I have no idea what the architecture of this bit of code is, so I wouldn't know how to do what I want, but something like inner_cmd: jupyterhub-singleuser would seem nice.

cmd:
  - python3
  - "-c"
  - |
    import os
    import sys

    try:
        import jupyterlab
        major = int(jupyterlab.__version__.split(".", 1)[0])
    except Exception:
        have_lab = False
    else:
        have_lab = major >= 3

    if have_lab and "NotebookApp.default_url" not in " ".join(sys.argv):
        # if recent-enough lab is available, make it the default UI
        sys.argv.insert(1, "--NotebookApp.default_url=/lab/")

    # launch the notebook server
    os.execvp("jupyterhub-singleuser", sys.argv)