Conversation
ContentsManager.show_globs trait
|
Actually this needs to take precedence over |
show_globs now overrides allow_hidden as well as hide_globs, matching against individual path components so a shown directory exposes its contents. This lets a deployment surface e.g. .jupyter/ while keeping other hidden files gated.
d79733a to
092c399
Compare
|
OK, this is a little harder than I thought. This might stay in draft for a bit. Need to eat dinner. |
show_globs now exempts hidden path components individually: a pattern must match a hidden component (by bare name or path from root) for it to be shown. Exempting a parent like .jupyter surfaces its non-hidden contents but keeps a nested dotfile (.jupyter/.secret) hidden unless a pattern covers it too.
092c399 to
b517f1a
Compare
|
Previous related discussions:
With the proposed |
|
@krassowski Good question. Unfortunately I think this is a limitation of the # BAD
c.ContentsManager.show_globs = ['.jupyter']
# GOOD
c.ContentsManager.show_globs = (c.ContentsManager.show_globs or []) + ['.jupyter'] |
|
I'm a bit stuck on this PR because doing glob matching on files is actually quite a bit more complex than I thought. I want the following behavior:
However, there don't seem to be any good stdlib approaches that satisfy all 4 of these requirements. All of the ones I found fail at one of these requirements:
This PR shows an AI-generated custom implementation, but frankly I do not trust it so I'm keeping this in draft. I do think it's worth considering to add a minimal dependency to support this & simplify glob handling across Jupyter Server, but I understand that this would be a larger change that requires consensus from more maintainers. |
I think that's true for |
|
While having a feature to selectively show paths that are hidden by default seems good, I just have a note for the motivation: Jupyter is normally meant to be ok to start from any folder. While the .jupyter config folder is often in the user's home dir or similar. The two might not overlap, so I would recommend that whatever way there is for configuring/adding personas should not rely on the config dir being within the root folder of the Jupyter server. |
Motivation
It would be nice to have traitlets configuration that allows extensions to selectively show files that are hidden via the
ContentsManagerby default. In Jupyter AI, we would like to use this setting to show.jupyter/always by default, since this is where people can upload their custom AI personas (which will be much easier to create in Jupyter AI v3.2, BTW!).Currently, we have to work around the lack of an equivalent
ContentsManager.show_globstrait by settingContentsManager.allow_hidden=Trueand settingContentsManager.hide_globsto try to hide everything a user probably doesn't want to see. But, we have gotten complaints about ourhide_globsconfiguration being either too loose or too wide. So I've put together my recommended fix here.Summary
Adds a
show_globsList(Unicode) trait alongsidehide_globs, defaulting to[]. A path matching anyshow_globspattern is always shown, taking precedence over bothhide_globsand hidden-file filtering. This lets a deployment layer targeted exceptions on top of the otherwise all-or-nothingallow_hiddenswitch, so it can keep hidden files hidden by default while always exposing a curated set of paths.A path is hidden when any of its components starts with a dot, and a
show_globspattern exempts such a component when it matches the component's bare name or its path from the root. A path is shown only when all of its hidden components are exempt. So[".jupyter"]surfaces the.jupyterdirectory and its non-hidden contents (e.g..jupyter/personas/foo.py) even withallow_hidden=False, but a nested dotfile like.jupyter/.secretstays hidden unless a pattern covers it too (add".jupyter/.secret"or".jupyter/.*").Technical details
should_listgains ashow_globscheck for the name-glob listing filter. The hidden-file behavior lives inFileContentsManager(inherited by the async manager), where theallow_hidden/is_hiddenchecks now also consultshow_globs: the two directory-listing sites, plus the access gates inget,save,delete, andrename, so a shown path is listable, readable, and writable rather than 404ing when opened.Testing
Added unit tests asserting that a name matching both lists is listed (show wins), that a
show_globshidden directory and its non-hidden contents are surfaced and accessible withallow_hidden=False, that a nested dotfile stays gated unless a pattern exempts it too, and that unrelated dotfiles remain hidden.