-
Notifications
You must be signed in to change notification settings - Fork 207
ENH: Allow setting example order #275
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
Comments
but to be a bit more helpful, I'd see this as an extension of #234 ...if folks are cool with it (and personally I am as long as it doesn't add much complexity), I think the solution should be similar to what's in there so that we don't have too many different ways of accomplishing the same kind of thing... I think this would encourage the use of sphinx-gallery for more narrative or tutorial-style galleries |
FWIW I think this would be better handled by a custom (toctree-like) directive e.g. at the level of the README.txt (as this is closer to the actual place of usage, rather than hidden within an already lengthy conf.py). Something like
Allowing for skipping files could then be done with a directive option, e.g.
(I certainly support the feature request, of course.) |
FWIW I think this would be better handled by a custom (toctree-like)
directive e.g. at the level of the README.txt (as this is closer to the
actual place of usage, rather than hidden within an already length conf.py).
Agreed that this is simpler and nicer, I hadn't considered that
possibility. I haven't worked with Sphinx directives before (let alone
integrating with SG) but I assume there is a way to accomplish this without
too much pain.
|
Although in principle the subsection ordering could have been done in the
same fashion but wasn't. So maybe the entry is better for consistency...?
@choldgraf not sure what you mean about integrating the two keys, they seem
separable to me. Feel free to propose an alternative API you find nicer.
|
Well I would argue that the subsection ordering should also be done using rst syntax, so I would generate something like https://sphinx-gallery.readthedocs.io/en/latest/auto_examples/index.html using
which seems way more explicit. (Well that would not support |
Okay but the subsection ordering is already done in conf. Are you proposing
to have two ways to do it, or that the old way should be deprecated and
removed?
|
I would just get rid of the old way. Actually, the toctree even has a globbing facility (http://www.sphinx-doc.org/en/stable/markup/toctree.html), so we could likewise even get rid of filename_pattern in favor of
|
I would just get rid of the old way.
This might create bad deprecation pains for users depending on how widely
used the feature is. I lean toward erring on the side of avoiding such
deprecation (and maintaining consistent interface), so I'm still +0.5 on
putting it in conf.py over moving to README.
|
The "old way" was only released in 0.12 (i.e. yesterday), so it can't be that widely used. |
Indeed controlling the examples ordering within a subsection was in the back of our mind in #234 (this is part of the reason #234 took some time) so that is the way I would go for. The idea would be to have an additional key like |
Indeed we had examples ordering in vision. And I strongly support using a sortkey in this case as well. I don't want nevertheless to mix it with the subsection order sortkey, it should be independent. [(full_example_path, amount_of_code, rst_thumbnail), ...] Then the sortkey can sort this list. My opinion against Sphinx directive. They are not so simple to develop nor maintain, and our testing framework is not advanced enough to have tests for them(although I'm trying to improve on the test system). But above all, Sphinx seems to make breaking changes in their API or internal code on every release and it is quite a pain to keep up on those changes and then make patches for the various versions. I want to avoid that maintenance burden on features we can do without relying on Sphinx internals. |
😕 I was advocating having a separate key
If you have the filename you can figure out the amount of code inside the file to mimic the current behaviour, can you not? @Titan-C I thought there was some consensus on this and I am slightly puzzled that we are still debating it. I feel I have already made this argument but I 'll make it again: simplicity and ease of use. You can customise the "between subsection ordering" and the "within subsection ordering" in a similar manner. For completeness' sake, this is what I have in mind: sphinx_gallery_conf = {
...
'subsection_order': ExplicitOrderKey(...),
'within_subsection_order': AlphabeticalOrderKey()
...
} |
@lesteve I missunderstood your first comment. I also have in mind what you put in your code example. 2 separate entries with separate sortkeys.
Yes you can. But you need to read the file again to infer that. On the other hand that is a value we have already evaluated. Said that, multiple reads of the same file have been a common pattern in our codebase and does not affect performance to much. |
Great to hear that!
Agreed, in most cases opening the file multiple times is going to be peanuts compared to running the example inside the file. |
AlphabeticalOrderKey seems ambiguous, maybe AlphabeticalFilenameOrderKey
and AlphabeticalTitleOrderKey (current default, right?).
Otherwise I think I have enough information to proceed to making a PR.
|
I know that filenames get passed to the sort key (probably not obvious to any user of course), so Note the default is length of the example (number of characters or lines in the file, I can't remember) of the as a proxy of "example complexity" so simple (i.e. short) examples come first. You'll need to find a nice name for this one as well ;-). |
+1 on a PR, I think this is a logical extension of functionality |
Great point! FWIW at the moment the "amount of code" is computed by |
I must say that the default ordering for strings in Python is case sensitive and alphabetical. Thus such default would go as |
I'm OK with that as long as we document the "python default" case :-) |
I thought about The sorting key is straightfoward to implement (not tested): class AlphabeticalOrder(object):
def __call__(self, item):
return item |
|
good point @lesteve ! |
Okay I'll incorporate these ideas when taking over #278 |
you are on a roll right now @Eric89GXL !!! |
I recently migrated PySurfer over to SG, and want to be able to set the example file order. There currently is no way to do that, correct? The workarounds would be to either build subdirectories, or re-title the examples e.g. "01. Basic visualization" etc. to get them in the correct order, which is not so satisfactory.
I propose adding an
example_order
dict toconf.py
to complement the existingsubsection_order
. The design would be nested dicts:So the first-level dict would be key-value pair for
subsection: order
. If a subdirectory isn't listed, use default (title-alphabetical) sorting. If one is listed, it must list all SG-relevant files in the directory or an error is thrown. This seems the most conservative API-wise and should be fully backward compatible.The text was updated successfully, but these errors were encountered: