Skip to content

Fix minigallery duplicates and add tests and update documenation#1435

Merged
lucyleeow merged 12 commits intosphinx-gallery:masterfrom
lucyleeow:minigal_followup
Feb 11, 2025
Merged

Fix minigallery duplicates and add tests and update documenation#1435
lucyleeow merged 12 commits intosphinx-gallery:masterfrom
lucyleeow:minigal_followup

Conversation

@lucyleeow
Copy link
Copy Markdown
Contributor

@lucyleeow lucyleeow commented Feb 11, 2025

Follow up to #1430. A few things happening in this PR (sorry!)

Fixes duplicates between object and file inputs

In #1430 the dict key used for objects was Path(target_dir, filename), whereas the dict key used for file inputs was Path(src_dir, filename). Thus, files selected via both object and file path would be duplicated.

There were two ways I could have fixed this:

  • Change key for file inputs to use target_dir - we would have needed to get the target_dir anyway to get the thumbnail and it may have been better to raise an error earlier if input path is not in an examples_dir (done in _get_target_dir) BUT we probably want to sort on Path(src_dir, filename) as it's probably easier for users vs Path(target_dir, filename)
  • Change key for object inputs to use src_dir meaning I write BOTH target_dir and src_dir to backreferences_all.json - probably 'safest' as we know src_dir and target_dir and do not have to do any complex ambiguity checking (as we do in _get_target_dir) but probably a bit much more expensive?

I went with the latter option.

Tests

  • Adds unit tests in test_gen_gallery.py - I've had to amend sphinx_gallery/tests/testconfs/src/plot_1.py to use a SG function, so I can test an object backreference input
  • Add a check in test_full.py via minigallery.rst
  • Add unit tests for the utility functions i added (_combine_backreferences, _read_json, _write_json)

Docs

  • Moved general minigallery info under the main header, so users don't have to go under "Create mini-galleries using file paths" to find it
  • Amended to say duplicates are removed
  • Mention new backreferences_all.json file and updated to say '.examples' files to be for backward compatibility only
  • Improved section on enabling backreferences (personal nitpick changes)
  • Update what will be passed to minigallery sortkey functions

app.connect("config-inited", post_configure_jupyterlite_sphinx, priority=900)

if "sphinx.ext.autodoc" in app.extensions:
app.connect("autodoc-process-docstring", touch_empty_backreferences)
Copy link
Copy Markdown
Contributor Author

@lucyleeow lucyleeow Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this @larsoner
Now that we don't use the '.examples' files this is not required for us. But is it possible some 3rd party relies on these empty '.examples' files (created for objects that are never used in any example)?!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But is it possible some 3rd party relies on these empty '.examples' files (created for objects that are never used in any example)?!

Yeah it probably is, otherwise Sphinx will complain about .. include:: files that are missing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright i will add this back in!

@lucyleeow lucyleeow added the bug label Feb 11, 2025
@lucyleeow
Copy link
Copy Markdown
Contributor Author

Doc build failing due to #1436

Copy link
Copy Markdown
Contributor

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI pushed a commit to try to fix CircleCI but it failed, I'll see if I can push another one to fix it

app.connect("config-inited", post_configure_jupyterlite_sphinx, priority=900)

if "sphinx.ext.autodoc" in app.extensions:
app.connect("autodoc-process-docstring", touch_empty_backreferences)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But is it possible some 3rd party relies on these empty '.examples' files (created for objects that are never used in any example)?!

Yeah it probably is, otherwise Sphinx will complain about .. include:: files that are missing

@larsoner
Copy link
Copy Markdown
Contributor

Okay the remaining CircleCI failure is just from the pandas site being down, feel free to address the comment above @lucyleeow !

@lucyleeow
Copy link
Copy Markdown
Contributor Author

Alright this is green and I'm merging 🤞 Thanks for the review and fixing the CI @larsoner !

@lucyleeow lucyleeow merged commit 91810a9 into sphinx-gallery:master Feb 11, 2025
@lucyleeow lucyleeow deleted the minigal_followup branch February 11, 2025 23:20
@lucyleeow
Copy link
Copy Markdown
Contributor Author

@ogrisel I built the docs locally and checked the duplication is fixed in PartialDependenceDisplay you mentioned in #1414:

image

But best not to trust me and check yourself as well (is there a CI job that uses SG dev?), before I make a new release! Thank you!

cc @glemaitre

@ogrisel
Copy link
Copy Markdown
Contributor

ogrisel commented Feb 12, 2025

Feel free to open a draft PR on the scikit learn repo to test the dev version of sg and use the [doc build] commit message marker to trigger a full gallery build in your PR.

@ogrisel
Copy link
Copy Markdown
Contributor

ogrisel commented Feb 12, 2025

But since it works locally, i would just trust you instead ;)

@lucyleeow
Copy link
Copy Markdown
Contributor Author

It looks fixed: scikit-learn/scikit-learn#30820

@glemaitre
Copy link
Copy Markdown
Contributor

Nice. Thank you very much for that fix.

@glemaitre
Copy link
Copy Markdown
Contributor

And thanks for the release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants