-
Notifications
You must be signed in to change notification settings - Fork 326
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
don't warn on fallback if no highlight theme was requested #1264
Conversation
on second thought, there's a deeper problem here: @HealthyPear says they have accessible-pygments installed, and yet it's setting fallback Tango or Monokai. So below, line 958 ought to have picked up that the theme default (specified in our pydata-sphinx-theme/src/pydata_sphinx_theme/__init__.py Lines 955 to 958 in 956edcf
...but it didn't, which means |
|
@HealthyPear could you test this branch to see if it now sets |
argh nevermind, what I have now works for rebuilds but not for first builds. |
ok locally this seems to work for both builds and rebuilds. @HealthyPear can you test it on your site please? |
src/pydata_sphinx_theme/__init__.py
Outdated
theme_name = app.builder.globalcontext.get(f"theme_{style_key}") | ||
|
||
if theme_name is None: | ||
theme_name = app.builder.theme.get_options()[style_key] |
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.
Note that you might be able to use this helper function we use elsewhere:
def _get_theme_options(app): |
If calling get_options()
is the "right" way to do this, maybe we should update that function too. Gah there are way too many ways to do the same thing in Sphinx
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 am already using that helper function 2 lines above; this line is only called if the style key wasn't found by the helper. Most of this you already know @choldgraf, but for completeness / future selves:
-
app.builder.get_theme_config()
returnsapp.builder.config.html_theme
(just the theme name)app.builder.config.html_theme_options
(dict of theme options).initialized here as an empty dict, it's not clear to me when it's populated, and with whatit's populated directly from user'sconf.py
duringapp.config.read()
.
-
app.builder.theme_options
is a copy ofapp.builder.config.html_theme_options
.- The copy is made during
builder.init_templates()
- Apparently there are cases where that copy never happens (e.g., linkcheck?) so we have that helper function that checks
app.builder.config.html_theme_options
too.
- The copy is made during
-
Calling
app.builder.theme.get_options()
will get just the values intheme.conf
without any user overrides.- Normally it's called by sphinx as
.get_options(app.builder.theme_options)
, which makes me strongly suspect thatapp.builder.theme_options
includes only the user-providedhtml_theme_options
from theirconf.py
(and not the theme's defaults). EDIT see strikethrough edit above, it's clear now thathtml_theme_options
does not include theme default values fromtheme.conf
- Here's where it's called during sphinx builds: during
builder.prepare_writing()
, right afterglobalcontext
is created. - I suspect our problem has been that
builder.prepare_writing()
is sometimes never called (e.g. if no files have changed?). That would explain why we had to work around missingglobalcontext
and also why the theme's defaults weren't available/accessible.
- Normally it's called by sphinx as
In this case, I think it would be possible / sensible to update the helper function to also check the theme.conf
values. Might be a good use case for ChainMap
?
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.
Sphinx never ceases to amaze me lol. Thanks for putting all of this together!
after further thought I don't think it's good to add
I considered adding a separate helper func for the query case (to prevent accidental modification) but it seemed like overkill because in the end we only access the theme options 3 times in our
the second one we fall back to Ready for merge when CIs are done |
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.
thanks for putting all this together !
sorry for the delay! I copy/pasted the edits of this merge request into the corresponding file within my conda environment and the problem seems to have disappeared - you have my delayed positive feedback :) |
Do you plan to make a bugfix release? I am sure someone set their Sphinx build to error on warning and this bug would be a stopper for them (obviously totally unrelated to my use case) |
hopefully tomorrow. @12rambau if you have bandwidth to do this today, I'd say go for it. |
0.13.2 including your fix is out |
@12rambau 🙏🏻🙏🏻🙏🏻 |
* sanitize babel calls * move the gallery directive to an extention folder * clean test folder * split __init__.py * add links between tests * drop flake8 from pyproject.toml * rename folder * update docstring * only import modules instead of functions * ignore bootstrap license * reintegrate modifications from #1264 * typos / docstring improvements / whitespace * fix: expose traverse_or_findall in utils --------- Co-authored-by: Daniel McCloy <[email protected]>
closes #1263
closes executablebooks/sphinx-book-theme#690