8000 ENH Clean-up code by early initialization of sphinx_gallery_conf by lesteve · Pull Request #1120 · sphinx-gallery/sphinx-gallery · GitHub
[go: up one dir, main page]

Skip to content

ENH Clean-up code by early initialization of sphinx_gallery_conf #1120

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

Merged
merged 10 commits into from
Mar 31, 2023

Conversation

lesteve
Copy link
Member
@lesteve lesteve commented Mar 31, 2023

Motivation

While working on #977, I noticed that the config initialization happened at builder-inited time in gen_gallery.parse_config, but it would have been more convenient for me that it happened at config-inited time because some of the JupyterLite config is used at config-inited. I needed to duplicate some logic like default values in code sphinx_gallery_conf.get('jupyterlite', {}) and in gen_gallery.DEFAULT_GALLERY_CONF, call check_jupyterlite_config in multiple places, etc ...

I thought it would be a lot better if the config could be "completed" (as we say in the code in some places, I used normalized in other places, but I am open to better naming suggestions ...) once early and we would be able to use it without always wondering whether an optional key exists or not. It would also to get rid of repeated .get(..., default_value) in multiple places.

I also believe that it would also potentially avoid the show_api_usage issue seen in #1093 although I am not 100% sure I have to say. It does feel like the config-inited will happen before the autodoc-process-docstring event. I have removed the code from #1095 for now but I can put it back if deemed
safer.

Edit: I tried on my branch with the instructions from #1095 (comment) and the issue doesn't happen on my branch it seems.

Of course things were not quite as simple as I initially hoped, since there is also some configuration update that needs to be done at builder-inited

Overview of the changes

  • split gen_gallery._complete_gallery_conf in two function one for config-inited one for builder-inited
  • define gen_gallery.normalize_gallery_conf_config_inited and gen_gallery.normalize_gallery_conf_builder_inited that we connect to the config-inited and builder-inited event
  • remove gen_gallery.parse_config that we don't need anymore
  • most other changes are:
    • test updates to initialise to put the sphinx_gallery_conf in a good enough state to be able to test the behaviour
    • removal of unnecessary sphinx_gallery_conf.get(key, default_value) in favour of sphinx_gallery_conf['key']

@larsoner
Copy link
Contributor

Agreed this should fix the show-api-usage bug, and agree this is much cleaner. I looked at the code and don't see any issues so in it goes, thanks @lesteve !

@larsoner larsoner merged commit 4abd070 into sphinx-gallery:master Mar 31, 2023
@larsoner larsoner added the bug label Mar 31, 2023
@lesteve lesteve deleted the early-config-validation branch April 3, 2023 08:50
clrpackages referenced this pull request in clearlinux-pkgs/pypi-sphinx_gallery Apr 18, 2023
… to version 0.13.0

v0.13.0
-------

**Implemented enhancements:**

-  ENH: Create backreferences for default roles `#1122 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1122>`__ (`StefRe <https://github.com/StefRe>`__)
-  ENH raise error in check_jupyterlite_conf with unknown key `#1119 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1119>`__ (`lesteve <https://github.com/lesteve>`__)
-  ENH Add functionality to modify Jupyterlite notebooks based on their content `#1113 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1113>`__ (`lesteve <https://github.com/lesteve>`__)
-  ENH: Add support for WebP `#1111 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1111>`__ (`StefRe <https://github.com/StefRe>`__)

**Fixed bugs:**

-  ENH Clean-up code by early initialization of sphinx_gallery_conf `#1120 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1120>`__ (`lesteve <https://github.com/lesteve>`__)
-  FIX JupyterLite button links `#1115 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1115>`__ (`lesteve <https://github.com/lesteve>`__)
-  Fix thumbnail text formatting `#1108 <https://github.com/sphinx-gallery/sphinx-gallery/pull/1108>`__ (`StefRe <https://github.com/StefRe>`__)

(NEWS truncated at 15 lines)
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.

2 participants
0