-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Conversation
So the idea if that we should be able to open files from the CLI by using the existing |
cc @parmentelat if you want to try with the built artifacts: https://github.com/jupyter/notebook/actions/runs/5356963835?pr=6946 |
For reference
|
@@ -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" |
There was a problem hiding this comment.
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
:
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) |
Investigate ways to fix #6914