Skip to content
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

Fix opening files from the CLI #6946

Merged
merged 1 commit into from Jun 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 1 addition & 8 deletions notebook/app.py
Expand Up @@ -234,7 +234,7 @@ class JupyterNotebookApp(NotebookConfigShimMixin, LabServerApp):
app_version = version
extension_url = "/"
default_url = Unicode("/tree", config=True, help="The default URL to redirect to from `/`")
file_url_prefix = "/notebooks"
file_url_prefix = "/tree"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the idea of using /tree is that there is already a redirect handler to open either with /edit or /notebooks:

notebook/notebook/app.py

Lines 127 to 160 in 7f1a2f4

async def get(self, path=None):
"""
Display appropriate page for given path.
- A directory listing is shown if path is a directory
- Redirected to notebook page if path is a notebook
- Render the raw file if path is any other file
"""
path = path.strip("/")
cm = self.contents_manager
if await ensure_async(cm.dir_exists(path=path)):
if await ensure_async(cm.is_hidden(path)) and not cm.allow_hidden:
self.log.info("Refusing to serve hidden directory, via 404 Error")
raise web.HTTPError(404)
# Set treePath for routing to the directory
page_config = self.get_page_config()
page_config["treePath"] = path
tpl = self.render_template("tree.html", page_config=page_config)
return self.write(tpl)
elif await ensure_async(cm.file_exists(path)):
# it's not a directory, we have redirecting to do
model = await ensure_async(cm.get(path, content=False))
if model["type"] == "notebook":
url = ujoin(self.base_url, "notebooks", url_escape(path))
else:
# Return raw content if file is not a notebook
url = ujoin(self.base_url, "files", url_escape(path))
self.log.debug("Redirecting %s to %s", self.request.path, url)
self.redirect(url)
else:
raise web.HTTPError(404)

load_other_extensions = True
app_dir = app_dir
subcommands: dict = {}
Expand Down Expand Up @@ -329,13 +329,6 @@ def initialize_handlers(self):
# if the serverapp set one
page_config["token"] = ""

self.handlers.append(
(
rf"/{self.file_url_prefix}/((?!.*\.ipynb($|\?)).*)",
web.RedirectHandler,
{"url": ujoin(self.serverapp.base_url, "/edit/{0}")},
)
)
self.handlers.append(("/?", RedirectHandler))
self.handlers.append(("/tree(.*)", TreeHandler))
self.handlers.append(("/notebooks(.*)", NotebookHandler))
Expand Down