-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Added a flag to allow access of hidden files #2819
Conversation
The flag '--allow-hidden' will allow Tornado to access hidden files such as '.images/my_img.jpg'
Jupyterlab stores its options in a different location than the standard notebook. Added the ability to check there as well.
Previously I was accessing the settings dict based on the name of the app that was being used. ex 'NotebookApp', or 'LabApp'. Now the setting is passed directly into the Tornado settings, and can be accessed via a more general method.
Fixed broken unit tests by setting the default to allow_hidden=False then added unit test in FilesTest:test_hidden_files that checks for the accessibility of files with allow_hidden=True
Thanks! I think this makes sense. We're just trying to release notebook 5.1, so we'll review this more closely once we've got that out. |
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.
Makes sense to me. I just have minor questions inline about how/where it should be exposed, but in general I think it's a good idea.
notebook/notebookapp.py
Outdated
@@ -445,6 +445,11 @@ def start(self): | |||
_("Allow the notebook to be run from root user.") | |||
) | |||
|
|||
flags['allow-hidden']=( |
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.
I don't believe this argument is of sufficient priority that it should get this level of promotion. There's a cost to adding noise here. All options are always accessible via lower level config, e.g. --NotebookApp.allow_hidden=True
.
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.
That's a good option. The only thing that is weird about it is that it's kind of unintuitive to type jupyter lab --NotebookApp.allow_hidden=True
when you're actually launching the LabApp. Although the back end is still notebook, it might seem weird to a user to have to type that when launching a different app (or they might not even think twice about it).
Alternatively, a user probably wouldn't have come across this option unless they knew what they were doing, so they might understand why it's a NotebookApp option.
notebook/notebookapp.py
Outdated
@@ -550,6 +555,10 @@ def _default_log_format(self): | |||
help=_("Whether to allow the user to run the notebook as root.") | |||
) | |||
|
|||
allow_hidden = Bool(False, config=True, |
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.
It seems like this would more logically be on FileContentsManager
, rather than NotebookApp. What do you think?
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.
Interestingly, the abstract ContentsManager (which doesn't know about files) defines an is_hidden()
method, but doesn't appear to use it for anything. It's FileContentsManager which is deciding not to show hidden files.
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.
Hrm I think, for my original intentions, it would be mildly confusing to put it in FileContentsManager
.
FileContentsManager
controls the ability to travel to hidden directories.AuthenticatedFileHandler
controls the ability to access hidden files in markdown (maybe more?)TreeHandler
controls the ability to access hidden files in the filebrowser
For my personal use, this PR was to allow access to hidden files through markdown, not to allow travel to hidden directories/open hidden files. But issue #2659 wanted that ability, so I'm not sure what the best course of action is.
If you think I should include the ability to travel to hidden directories and access hidden files, I can though.
I'm happy to have that as an option. We have to be careful, I believe some of the "is_hidden" logic does (used to ?) do two things; a file is hidden if either:
I think we still want the files outside of the root to be unaccessible. In which case this implementation is not totally correct. |
That's a good point, I will think of a way to change that. edit: |
I don't think this has ever been true. I believe we've always allowed the use of symlinks to serve files outside root (my default notebooks dir is just a folder full of symlinks to elsewhere). |
Is this ready to merge? Or should we mark it as 5.3? |
I don't know exactly how to proceed. I mentioned this above, but I'll summarize: For my personal use, this PR was to allow access to hidden files through markdown, not to allow travel to hidden directories/open hidden files in the filebrowser. In order to add that ability you would have to add an option to the filebrowser to view these, you pretty much only have to edit the function Editing that is relatively easy and straightforward, but i feel like the filebrowser would be super clogged with tons of dotfiles, and could be annoying unless there's a gui option on the filebrowser for showing hidden files, I think it would have to be a toggle specific to TreeHandler, could be wrong, once I start I'll double check. Do you think I should go ahead with that instead of my original proposal? |
Yeah, there's really two things to control: allowing access to hidden files, and showing them in the list. I think it's fine to add an option to allow access but leave them hidden. Showing them is more complex, because you probably want that to be switchable at runtime, not just from a config file. It sounds like @gnestor is getting ready to release 5.2 in the next couple of days, so I think this PR may need to wait for 5.3. |
Proposal: Add a "Toggle hidden files" item to the View menu? |
Previously allow-hidden flag only allowed hidden files to be accessed via tornado. Now you can use the allow-hidden flag to access hidden directories and files via the filebrowser.
I don't know javascript at all. I tried for a little bit, but I couldn't figure it out. Maybe someone else can help on that part? In any case, the --allow-hidden flag now should let you see hidden files in the filebrowser, and travel to hidden directories. You also still cannot create hidden files via the filemanager. I don't know how to move variables between JS and python, but it looks relatively simple if you could. let me know if the implementation is poor! |
I've had a go at simplifying this:
|
Thanks @takluyver! Should we try to include this in 5.3? |
I'd say go for it - it should be low risk. |
I thought this flag would be useful. However, looking back it looks like there was some discussion as to if this should ever be allowed. So not a big deal if you don't want it in, but since I've been using this for myself for a while I figured I'd at least give it a shot.
The flag '--allow-hidden' will allow Tornado to access hidden files
such as '.images/my_img.jpg'
relevant threads:
issue:#2659
jupyterlab/jupyterlab#2910
ipython/ipython#5157
Sorry for the multiple commits, didn't think to test something other than jupyter notebook originally
Reduce option priority.I don't think this makes much sense considering how much had to be changed.