MNT: Refactor generate_dir_rst and generate_gallery_rst#1332
MNT: Refactor generate_dir_rst and generate_gallery_rst#1332larsoner merged 20 commits intosphinx-gallery:masterfrom
generate_dir_rst and generate_gallery_rst#1332Conversation
larsoner
left a comment
There was a problem hiding this comment.
Thanks for working on this refactoring, I agree it should help!
* upstream/master: MNT: Refactor `generate_dir_rst` and `generate_gallery_rst` (sphinx-gallery#1332) MNT: Refactor `generate_file_rst` (sphinx-gallery#1335) MNT: Refactor `_fill_gallery_conf_defaults` (sphinx-gallery#1334) MNT Use `os.sep` everywhere (sphinx-gallery#1333) DOC Improve `nested_sections` (sphinx-gallery#1326)
|
This appears to have broken (I say broken, as I'm assuming a refactor didn't intend to change behaviour) generating the zip files for the top-level gallery if it has an (On a side note, large refactors like this are why I dislike squash merging PRs; it makes bisecting more difficult than it should be.) |
|
Sorry I'll take a look tomorrow. |
|
A change like this does seem to fix it: diff --git a/sphinx_gallery/gen_gallery.py b/sphinx_gallery/gen_gallery.py
index f8b3c7b..89d8998 100644
--- a/sphinx_gallery/gen_gallery.py
+++ b/sphinx_gallery/gen_gallery.py
@@ -608,13 +608,15 @@ def _finish_index_rst(
)
indexst += subsections_toctree
- if sg_root_index:
- # Download examples
- if gallery_conf["download_all_examples"]:
- download_fhindex = generate_zipfiles(
- gallery_dir_abs_path, app.builder.srcdir, gallery_conf
- )
+ # Download examples
+ if gallery_conf["download_all_examples"]:
+ download_fhindex = generate_zipfiles(
+ gallery_dir_abs_path, app.builder.srcdir, gallery_conf
+ )
+ if sg_root_index:
indexst += download_fhindex
+
+ if sg_root_index:
# Signature
if app.config.sphinx_gallery_conf["show_signature"]:
indexst += SPHX_GLR_SIGShould I open a PR, or do you think this should be refactored somewhere else? |
There has been a few PRs recently adding a fair bit of stuff to
generate_dir_rstandgenerate_gallery_rst, making them quite long and difficult to understand.Prompted by trying to read the code after #1323.
A lot of simply pulling code out into helper functions, removing redundant things. Notable changes:
generate_dir_rstnow only writes index.rst file ifsrc_diris a subsection filegenerate_gallery_rstabout thisinclude_toctreealready indicated whether it was a subsection or not, we just weren't fully utilising itindex.rstfile or notcollect_gallery_files- this is opinionated so I am happy to revert or amendutils/- to prevent circular import as I wanted to use it ingen_rst.py. This is technically a public function but a quick search on github seems to suggest only one or two cases of its use, most are forks of SGexample_extensionsit makes sense to check all supported exts