takluyver / nbopen

Open a Jupyter notebook in the best available server
BSD 3-Clause "New" or "Revised" License
301 stars 58 forks source link

open multiple notebooks with one call to nbopen? #53

Open jeisner opened 6 years ago

jeisner commented 6 years ago

Thanks very much for nbopen. Simple suggestion: It would be nice to permit opening multiple files (in separate browser tabs) with one call to nbopen, like this:

nbopen foo.ipynb bar.ipynb
nbopen *.ipynb

I expected this to work and was surprised when it gave an error.

While it might seem almost as easy to write

nbopen foo.ipynb; nbopen bar.ipynb
for f in *.ipynb; do nbopen $f; done

these don't actually work because the first call to nbopen may have to open a notebook server, in which case it doesn't terminate until that server is closed. One would have to run the first call in the background.

Also, it is sometimes convenient to have a single command running that mentions a group of related filenames. This can make it easier to use commands like jobs and ps -f and pgrep -f and pkill -f, which list or match the full command.

takluyver commented 6 years ago

Thanks, I think that makes sense. It may take a bit of working out, because of the behaviour that uses an existing server if one is available that can reach the files in question, or starts a new one if necessary. So for multiple files, it needs a bit more smarts to figure out whether and where to launch new servers.

jeisner commented 6 years ago

Is it possible that one call to nbopen (on multiple files) would have to launch multiple new servers? If so, then their messages would be mingled on stdout/stderr -- not sure if that's a problem.

takluyver commented 6 years ago

Possibly - it depends on how it chooses the directories. At present, if it can't find an existing server to use, it will start a new one either at your home directory, or (for notebooks outside that) at the directory containing the notebook.

If it's passed notebooks in different directories, it would have to choose one of:

  1. Launch multiple servers
  2. Launch one server in the common ancestor directory (doesn't work for different drives on Windows, but I imagine almost no-one would ever pass paths to different drives in one command).
  3. Error out and ask the user to split up commands.
jeisner commented 6 years ago

Could it launch a server in the directory of the first file, and use relative or absolute pathnames for the other files? (This is a variant of 2 -- use the first file instead of the common ancestor. I think that's more intuitive.)

When this is not possible, I guess it would have to fall back on 1. or 3.

takluyver commented 6 years ago

The limitation is that a notebook server can only open notebooks below the directory it's started at - it can't look up to higher directories, or across to sibling directories.

But I imagine that most of the times when someone would try to open multiple notebooks, they'd be in the same folder. So maybe we could avoid most of the complexity, at least at first.