takluyver / nbopen

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

root directory for notebook server #38

Closed den-run-ai closed 7 years ago

den-run-ai commented 7 years ago

How does nbopen determine if the current notebook file (.ipynb) can be opened in the current notebook server?

e.g. if I have 2 notebook servers opened in 2 directories, can nbopen find whether to launch a third server when opening a new notebook with nbopen command or from explorer?

The issue is that notebook server may not have access to a new notebook, if it is not located in one of its sub-directories.

takluyver commented 7 years ago

It checks whether the any running server was started in a path that's a prefix of the current notebook path. E.g. if I have a server running in /home/thomas and I try to open /home/thomas/foo/bar.ipynb, it will use the existing server. But if I try to open /opt/baz.ipynb, it will start a new server.

den-run-ai commented 7 years ago

Well, I got an error on Windows this afternoon, but this is working on Linux. Let me check tomorrow morning again. Maybe my mistake with the paths or something.

On Tue, Nov 15, 2016 at 12:05 AM, Thomas Kluyver notifications@github.com wrote:

It checks whether the any running server was started in a path that's a prefix of the current notebook path. E.g. if I have a server running in /home/thomas and I try to open /home/thomas/foo/bar.ipynb, it will use the existing server. But if I try to open /opt/baz.ipynb, it will start a new server.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/takluyver/nbopen/issues/38#issuecomment-260555675, or mute the thread https://github.com/notifications/unsubscribe-auth/AHgZ5ZPg30z-Gfj00mdae39424-oRBDqks5q-UuxgaJpZM4KyI0I .

takluyver commented 7 years ago

There may be a bug because I'm used to case-sensitive Linux paths, and Windows paths are case-insensitive.

den-run-ai commented 7 years ago

I spent quite some time debugging and fixing this problem only to find this pull request which fixes the issue in the master:

https://github.com/takluyver/nbopen/pull/42

My solution is based on notebookapp, but is essentially the same:

        relpath = os.path.relpath(filename, start=server_inf['notebook_dir'])
        # based on "start" method in notebookapp
        uri = url_escape(url_path_join('notebooks', *relpath.split(os.sep)))
        url = url_path_join(server_inf['url'], uri)