-
Notifications
You must be signed in to change notification settings - Fork 206
ENH: allow rst files to pass through #1071
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
Should be fixed now... |
OK, I think the CI failures are expected. Before I do a bunch of code cleanup, and write more docs (other than the self-documenting of the examples):
Thanks! |
So to me this PR is actually two separable things:
For (1), I like the current design -- it seems simple enough and I don't think it will break things for people. At least I don't think we allow the source and generated dirs to be the same -- if we did, that's a problem for For (2), I think we might want to think about a proper API. For example, people have asked about being able to copy other stuff (e.g., images) as well (e.g., #1063 (comment)) but my thought so far was "just do this yourself if you want it". But now that it's been brought up at least a couple of times, something like |
Hmm, that is probably easy, and may actually simplify my exploratory code above now that I think of it that way. But even simpler, is there any reason to not copy everything in the gallery source directory over to the target directory? Maybe excluding README.*, particularly README.rst? |
Yes, because examples can produce/write junk files, people can have crufty .orig files on their systems, etc. What you're talking about would be the equivalent of something like |
OK, fair. Adding a Edit: think I did that right, and the code is somewhat simpler as well! |
3871b5c
to
c7a7d57
Compare
Assuming this is working the way folks are happy with, what is the advice on how to document/test. Currently I've just added two new galleries: I think there are two options - the first is keep Finally, I've not dug into your testing yet, but I assume I can figure it out. |
API suggestion:
This reads for example
instead of
|
I'm fine with a list of fnmatch patterns as well if thats what the s-g maintainers prefer. |
Looking through our existing config values there are several that use regex and none that use glob/fnmatch, so we should probably stick with regex for within-package consistency |
c415924
to
0658cf6
Compare
sphinx_gallery/tests/test_full.py
Outdated
N_TOT = 18 # examples (plot_*.py in examples/**) | ||
|
||
N_FAILING = 2 | ||
N_GOOD = N_TOT - N_FAILING | ||
N_RST = 17 + N_TOT + 1 # includes module API pages, etc. | ||
N_RST = 17 + N_TOT + 1 + 12 # includes module API pages, etc. | ||
N_RST = '(%s|%s)' % (N_RST, N_RST - 1) # AppVeyor weirdness |
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'll admit these numbers are completely empirical to me. I don't understand what is included here and what should not be. I added files to tinybuild
and obviously they changed the totals, but I'm not clear where +12 comes from exactly, or how it relates to +5 in N_TOT. Perhaps whoever architected these tests can tell me how to make this deterministic, and I can try. (Note I also got screwed up for quite a while as I think you cannot run these tests standalone - you need to run the whole file?)
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's likely not up to date anymore, and I agree it's not clear (even though I think I came up with it!). I think we probably want something like
N_EXAMPLES = ... # examples/*.py files that get turned to RST
N_FAILING = 2
N_GOOD = N_EXAMPLES - N_FAILING
N_INDEX = ... # index.rst files that SG generates
N_OTHER = ... # other pages (API/modules, etc.)
N_RST = N_EXAMPLES + N_INDEX + N_OTHER
N_RST = '(%s|%s)' % (N_RST, N_RST - 1) # AppVeyor weirdness
or so, would that make sense to you? It might be a good idea to do this in master
first to make sure it's working properly, though... I can do this sometime this week or next unless you want to try @jklymak
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.
Sure let me try as I looked at it all recently. I tried doing what you have here but failed, but starting from master makes sense and then after that I can add one file at a time and get it to make sense.
a30af5b
to
95c45de
Compare
.. this is rebased on #1072 |
74f6072
to
4fa8f41
Compare
sphinx_gallery/gen_gallery.py
Outdated
# Write toctree with gallery items from gallery root folder | ||
if len(this_toctree_items) > 0: | ||
this_toctree = """ | ||
if this_content: |
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.
Everything from here to the else
is just an indentation change of the original code...
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.
Github "Hide whitespace " viewing mode agrees :)
ab21196
to
a81b091
Compare
@@ -447,6 +457,24 @@ def _prepare_sphx_glr_dirs(gallery_conf, srcdir): | |||
return list(zip(examples_dirs, gallery_dirs)) | |||
|
|||
|
|||
def _format_toctree(items, includehidden=False): |
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 refactored this out because the lack of indentation was making it hard to follow.
Commit 2 (and 3) are a refactor of how I ignore the README.txt logic if the index.rst exists. I think I prefer the new way, but it's a bit more intertwined with the README.txt logic. The advantage is less duplication. Disadvantage is that the index.rst.new gets made even though it will never get used, which is a bit confusing. |
Sounds worth it given the advantages. And it should be plenty fast anyway! |
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.
Just one minor adjustment to the docs (assuming my understanding is correct), otherwise LGTM!
@timhoffm can you see if you're happy with the API as well?
I think so, as the loop I was bailing out of also did a number of other things, like sg_execution_times, and zipped 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.
Let's see if @timhoffm wants to look or comment, but otherwise let's merge!
@timhoffm has limited time currently due to family obligations. But happy to wait for him or other folks. I think the API here is relatively opt-in, so it should not affect anyone who doesn't want this pass-through to happen. |
Let's try it -- thanks @jklymak ! |
Thanks for your help and work maintaining sphinx-gallery! |
Thank you so much @jklymak. There's nothing better than heavy users (matplotlib) helping to shape the library.
|
… to version 0.12.1 v0.12.1 ------- **Fixed bugs:** - BUG: Fix bug with show_api_usage `#1095 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1095>`__ (`larsoner <https://github.com/larsoner>`__) - FIX: Add blank line at end of table of contents block `#1094 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1094>`__ (`sdhiscocks <https://github.com/sdhiscocks>`__) v0.12.0 ------- Support for Sphinx < 4 dropped in this release. Requirement is Sphinx >= 4. **Implemented enhancements:** - ENH: allow rst files to pass through `#1071 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1071>`__ (`jklymak <https://github.com/jklymak>`__) (NEWS truncated at 15 lines)
Closes #1067.
Ready for review 27 Jan...
This allows *.rst files in galleries to pass through as rst. So in
/examples_with_rst/
rst_example1.rst
is passed though to the build directory. Note that thetoctree
does not get an entry for this, so the user will need to add atoctree
to theirREADME.txt
Secondly, it allows
index.rst
to be in a gallery, and then generating theindex.rst
is not done. Obviously the user is responsible for creating thetoctree
by hand for this.Again, the motivation for this is from Matplotlib, where we really like to write long tutorials with lots of plots as python files, but other narrative documentation pages are more natural as rst. Similarly, we are going to want manual control of our table of contents, so we would like to be able to write our own
index.rst
.BTW, I tested that this works well with
nested_sections=True
as well (which is responsible for some of the code complexity)Open to suggestions as to how to better structure this. I think I've put things at the natural place to inject the passthroughs, but it does lead to a couple large if/else blocks that could probably be optimized.