-
Notifications
You must be signed in to change notification settings - Fork 207
[ENH] Minigallery can take arbitrary files/glob patterns as input #1226
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
Conversation
Not sure if this will break anything or not. But you could do it and we could check to see if things still render properly.
I'm not sure how it would work to use RST to define the order, but agree it makes sense to define it somewhere somehow. A solution that would be more consistent with other order setting mechanics would be to provide a |
Was thinking about this 'cause #1068 but realizing the answer to both this is probably a |
de52aae
to
29c580b
Compare
923c28c
to
236dc27
Compare
b/c I have gone down way too deep an html/xml rabbit hole, does it matter if the heading is before or in the thumbnail parent div? my bias is for in b/c then it stays together as part of the DOM ETA: also main reason for completely rewriting the minigallery test was to get a better sense of expected behavior. |
236dc27
to
d25d03b
Compare
I have nothing to contribute here but I just wanted to thank you for your hard work. Also the CIs are failing because scipy docs site certificate has expired scipy/docs.scipy.org#80 |
I am not really sure but if I had to guess I would say no it shouldn't matter, so feel free to try moving it |
Moved it inside in this PR and the build looks the same to me. |
d25d03b
to
7d96adf
Compare
I think a standalone/separate PR would be to make something like a Also test failures are I think cause I moved the title into the div/changed the backreferences file, so I'll sort that out probably in the coming week or so. |
Thinking about this more... I'm not sure we can/should implement this at the SG end, at least to start. You could already implement and use this in https://sphinx-gallery.github.io/stable/_modules/sphinx_gallery/sorting.html#ExampleTitleSortKey I'd expect something like the following, where the
|
... in other words, I think the hard/interesting work here is in the |
900b24d
to
30e61f6
Compare
0e1897e
to
4ba2a06
Compare
65b5d4d
to
03e3fe3
Compare
for more information, see https://pre-commit.ci
That's fine, I've used this ordering. Some minor changes:
|
Thanks @story645 for all your work. Just made minor fixes to save you time. |
sortkey = config.sphinx_gallery_conf["minigallery_sort_order"] | ||
for obj, path in sorted( | ||
set(file_paths), | ||
key=((lambda x: sortkey(str(x[-1].name))) if sortkey else None), |
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 I think you want more than just the name if you want to keep files in a subfolder together.
Mentioned this in a review, but this won't let you keep files in a subfolder together and will collapse two files of the same name in different subfolders & I think those are some of the primary reasons I'd want to sort. |
Ah sorry I missed that. What about the making the paths relative to We could probably do that here: elif paths := Path(src_dir).glob(obj):
file_paths.extend([(obj, p) for p in paths]) ? Maybe we could add a test to capture this? And update the documentation so people know what we're sorting on. Let me know if you don't want to work on it. |
I was actually gonna open up a PR to put back sorting on the full path.
|
That's fine. We can do it in the sortkey, maybe adding a |
Ehh, Matplotlib does some wonky nested nonsense so I'd rather be as general as possible. |
Sure I'm okay with it the previous status, but it should be documented so people know what we're sorting on (and that it's not just the filename). And tested if possible... |
Actually, the filepath input arg to the directive would be okay? Since they have to give the filepath relative to |
Don't think so b/c it can also be a glob expression |
Oh yeah good point. I realise now why I thought it should be the filename, the example we give is along the lines of |
I meant that I think sphinx gallery only looks 1 level down for subdirs, though matplotlib may do funny things to get around this? |
Hmm, I'm probably wrong then and we only have one level of subdirs? Where https://github.com/matplotlib/matplotlib/tree/main/galleries is our tree...hmm,
I think a worthwhile followup PR is for the sortkey callables to take Path or string, but is out of scope here I think. |
… to version 0.16.0 v0.16.0 ------- Sphinx 7.3.0 and above changed caching and serialization checks. Now instead of passing instantiated classes like ``ResetArgv()``, classes like ``FileNameSortKey``, or callables like ``notebook_modification_function`` in ``sphinx_gallery_conf``, you should pass fully qualified name strings to classes or callables. If you change to using name strings, you can simply use a function as the use of classes to ensure a stable ``__repr__`` would be redundant. See :ref:`importing_callables` for details. **Implemented enhancements:** - ENH: Allow plain list as subsection_order and support a wildcard `#1295 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1295>`__ (`timhoffm <https://github.com/timhoffm>`__) - [ENH] Minigallery can take arbitrary files/glob patterns as input `#1226 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1226>`__ (`story645 <https://github.com/story645>`__) (NEWS truncated at 15 lines)
raise ExtensionError( | ||
f"Error in gallery lookup: input={obj}, matches={dirs}, " | ||
f"examples={config.sphinx_gallery_conf['examples_dirs']}" | ||
) |
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.
@story645 I stumbled on this error accidentally but I don't fully follow what situation this is meant to catch?
I managed to contrive a case where I added a file to a path not in examples_dir
to a minigallery directive. In that case there were no matches and the error message didn't really make sense.
I assume it is meant to catch cases when dirs>1
? So maybe a sub-gallery directory is named the same as a examples gallery?
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.
A more informative error message would be great. There is no test for this but depending on what this is mean to catch, maybe it would be too difficult to write a test.
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.
cc @larsoner just in case you remember...? 😬
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.
No idea 😞
Closes #1029
still have to finish up tests and docs, but wanted some feedback if this was in the right direction.
If so, I'm also wondering if I could strip the thumbnail parent div out of the backref files so that I could do it in the loop.
get .py files in .rst folders working - seems to work by default and issue was sorting
file sort order