Skip to content
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

Standardize logo image behavior between Sphinx and this theme #1132

Merged
merged 23 commits into from
Feb 3, 2023

Conversation

12rambau
Copy link
Collaborator

related to #1130

I don't manage to reproduce the current behavior on my local computer, I want to check if it's related to the distant build.

@12rambau 12rambau marked this pull request as ready for review January 23, 2023 20:00
@12rambau
Copy link
Collaborator Author

I have 0 clue what changed but it's back to normal.

superceed #1131
Fix #1130

@choldgraf
Copy link
Collaborator

choldgraf commented Jan 26, 2023

Does this mean that people in general need to add the _static in front of their logos now?

Fwiw the logo looks broken in the RTD build, but only for the light theme

https://pydata-sphinx-theme--1132.org.readthedocs.build/en/1132/

@choldgraf
Copy link
Collaborator

I think we may need to add a conditional check in our template. so that if it is sphinx 6 we do not add _static and if < 6 we do?

@12rambau
Copy link
Collaborator Author

arf, my computer uses the dark theme I forgot that they were piloted from 2 different images.

@choldgraf
Copy link
Collaborator

choldgraf commented Jan 26, 2023

Ah interesting - yeah we should make sure that the link behavior is the same between html_logo and the logo theme configuration

I think it's going to confuse people if there is an implicit "_static" if the config is nested under "logo" but if we require the "_static" if using html_logo

@12rambau
Copy link
Collaborator Author

Ok, I think I find a way to be compatible with everything:

  • Move logic away from jinja
  • Create logo_light and logo_dark from the logo/image_light/image_dark
  • Use the same logic as in sphinx so compatible with sphinx 4-5-6
  • if by any chance they modify their jinja template again, we won't be impacted

@12rambau 12rambau marked this pull request as draft January 26, 2023 15:11
@12rambau 12rambau added the help wanted Extra attention is needed label Jan 26, 2023
@12rambau
Copy link
Collaborator Author

I'm stuck. The only configuration that continues to fail is:
html_theme_options["logo"] is not set at all in the conf.py. If that's the case, the update of theme_options is not persisted to the jinja template and the logo images are not displayed. Does anybody have an idea why ?

@choldgraf
Copy link
Collaborator

choldgraf commented Jan 26, 2023

OK so I think this might be what is happening:

We are updating various configuration options in the builder-inited phase:

def update_config(app):
theme_options = app.config.html_theme_options
# DEPRECATE >= v0.10
if theme_options.get("search_bar_position") == "navbar":
logger.warning(
"Deprecated config `search_bar_position` used."
"Use `search-field.html` in `navbar_end` template list instead."
)

However, when builder-inited has triggered, this by definition means that the builder has already been defined and set. So the options that were in html_theme_options are now already baked into the context variables and such. At this point, changing html_theme_options will have no effect because the builder is already inited.

So if I'm right, we'd need to either:

  1. Trigger the "update the html_theme_options values" function before the builder is inited (but we cannot use config-inited unless we force users to add this theme as an extension as well).
  2. Figure out what inside the builder we need to update since it has already been set up, and make the changes there instead of in html_theme_options

Option 3 is that I'm totally wrong and it's a different problem :-)

@12rambau
Copy link
Collaborator Author

12rambau commented Jan 26, 2023

hmmm, then why is working when I set 2 absolute url or 1 html_logo and a html_theme_options["logo"]["dark_image"] ?
It is as if I cannot add more keys but I can still modify them. OR (and then it's worse) they are linked and not copied #mutableobject and that's why it's working in all the other config

@12rambau
Copy link
Collaborator Author

Thanks @choldgraf for the emotional support, that was a amazing catch. So context is reading html_theme_option but not copying them: thus the weird behavior.

Calling everything from context works like a charm.

I need #1136 to validate windows build. As it seems very unlikely that I generated any bugs there, I think it's ready to merge.

src/pydata_sphinx_theme/__init__.py Outdated Show resolved Hide resolved
src/pydata_sphinx_theme/__init__.py Outdated Show resolved Hide resolved
src/pydata_sphinx_theme/__init__.py Outdated Show resolved Hide resolved
src/pydata_sphinx_theme/__init__.py Outdated Show resolved Hide resolved
@12rambau 12rambau marked this pull request as ready for review January 27, 2023 07:05
@12rambau
Copy link
Collaborator Author

12rambau commented Feb 1, 2023

I finally got something that works in all our test. It required a lot of special cases, I made my best to make it seemless, it wil not block moving forward as "logo_url" will always be set.

@12rambau 12rambau marked this pull request as ready for review February 3, 2023 18:57
@12rambau
Copy link
Collaborator Author

12rambau commented Feb 3, 2023

  • I updated the link in the documentation to point to Sphinx doc
  • I refactored the code to add breath between the 2 logo block
  • I use an image_relative dict so that it will be callable using a jinja variable (trust me it will be useful very soon)
  • ✅ test
  • ✅ docs

I don't care about #1065 as it is not blocking anything. Let's do the 0.13rc1 release once merged

Copy link
Collaborator

@choldgraf choldgraf left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for putting so much thought into getting this one right!

@choldgraf choldgraf changed the title Standardize logo image paths behavior between Sphinx and this theme Standardize logo image behavior between Sphinx and this theme Feb 3, 2023
@choldgraf choldgraf merged commit f9f26d2 into pydata:main Feb 3, 2023
@12rambau 12rambau deleted the logo branch February 3, 2023 20:19
@drammock
Copy link
Collaborator

drammock commented Feb 3, 2023

Super good work @12rambau !!

@jklymak
Copy link
Contributor

jklymak commented Feb 28, 2023

This broke Matplotlib's doc build with 0.13. The Changelog is quite terse and this thread is pretty long, and the PR description oblique. What is the TLDR summary of the change here?

@12rambau
Copy link
Collaborator Author

we deal now with logos the same way Sphinx is doing it: https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_logo

  • it will work whatever the version (there are internal changes between 5 and 6 that we were unable to handle)
  • the path need to be relative to the configuration directory

@12rambau
Copy link
Collaborator Author

@jklymak in the case of matplotlib I don't understand why it was working before, where are the file you point to as logos ? https://github.com/matplotlib/matplotlib/blob/217f8f70875279709f6d34f98d5c1447d6a6d822/doc/conf.py#L457

@jklymak
Copy link
Contributor

jklymak commented Feb 28, 2023

We supply the logos as part of mpl-sphinx-theme, which is a thin wrapper around pydata-sphinx-theme. https://github.com/jklymak/mpl-sphinx-theme/tree/main/mpl_sphinx_theme. Placing the logos in static/images/ of the theme used to copy them to build/html/_static/images, and referring to them in the theme as images/logo.svg used to work. We abstract the logos to mpl-sphinx-theme so that a number of sites can have consistent logos and navbars.

I'm sure we can get this all to work; I haven't spent any time trying to debug, but was hoping for a little more clarity on what happened here that broke that flow. Thanks!

@12rambau
Copy link
Collaborator Author

12rambau commented Feb 28, 2023

I think changing "images/logo.svg" to "_static/images/logo.svg" will do the trick

@jklymak
Copy link
Contributor

jklymak commented Feb 28, 2023

mpl-sphinx-theme distributes static/images/logo2.svg (https://github.com/jklymak/mpl-sphinx-theme/blob/main/mpl_sphinx_theme/static/images/logo2.svg).

In 0.12.0, during the build this is copied to _build/html/_static/images and linked at /_static/images/logo2.svg, using a conf.py that looked like:

html_theme_options = {
    "logo": {"link": "https://matplotlib.org/stable/",
             "image_light": "images/logo2.svg",
             "image_dark": "images/logo_dark.svg"},
...}

In 0.13.0, the file is still copied to _build/html/_static/images, however, there is a warning:

WARNING: Path to light image logo does not exist: images/logo2.svg

and the build logo image source is now looking at: _static/logo2.svg.

If (after make clean) I change the conf.py to have "image_light":"_static/images/logo2.svg"
the files again are at _build/html/_static/images, but we get the similar warning:
WARNING: Path to light image logo does not exist: _static/images/logo2.svg
and the image source still says _static/logo2.svg.

Next debugging step was to move, in the theme, logo2.svg to static/logo2.svg. This copies over fine, and the site builds fine with "image_light":"_static/logo2.svg", but it still returns a Warning: WARNING: Path to light image logo does not exist: _static/logo2.svg. If I change to "image_light":"logo2.svg" it still complains that file doesn't exist though the site builds properly.

I assume what has happened here is that you are assuming that the local static is all that there is to static, but the theme can carry static info (https://www.sphinx-doc.org/en/master/development/theming.html#creating-themes) and you are making a Warning that is not warranted. Since many of us fail doc builds with warnings, maybe the Warning needs to go away, or be more robust.

Second you are stripping information from the theme options so that the subdirectory structure is being lost. I'm not sure if that is because of the Warning or if you are doing that on-purpose, however it seems we should be allowed to have subdirectories in the the static info of themes.

# else we need to calculate the relative path to a local file
if image_kind_logo:
if not isurl(image_kind_logo):
image_kind_name = Path(image_kind_logo).name
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is too restrictive, in that it doesn't allow paths relative to static. Is stripping the name needed at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

strip the name is essential if you use files from outside the doc folder (i.e. the root of the repo) which would have path like "../../../my_hidden_logo.png". This file needs to end up in the build _static directory eventually

Comment on lines +1148 to +1149
if not (Path(app.srcdir) / path_image).exists():
logger.warning(f"Path to {kind} image logo does not exist: {path_image}")
Copy link
Contributor

Choose a reason for hiding this comment

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

There probably is not a good way to check if the path exists in a theme-supplied static directory? If not, then maybe just skip this warning or demote to INFO or DEBUG?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, should this not continue at this point?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There probably is not a good way to check if the path exists in a theme-supplied static directory? If not, then maybe just skip this warning or demote to INFO or DEBUG?

I'm -1 on changing the warning, as you mentioned people are listening to warnings in their CI/CD it would mean that nobody would realize that the logos are not displayed anymore until someone check visually the logs/website.

Also, should this not continue at this point?

yes we should

jonathansick added a commit to lsst-sqre/documenteer that referenced this pull request Mar 1, 2023
The extra path checking involved in the light and dark logos in the
html_theme_options isn't compatible with images installed via
html_static_path.

See pydata/pydata-sphinx-theme#1132 (review)
jonathansick added a commit to lsst-sqre/documenteer that referenced this pull request Mar 1, 2023
The extra path checking involved in the light and dark logos in the
html_theme_options isn't compatible with images installed via
html_static_path.

See pydata/pydata-sphinx-theme#1132 (review)
12rambau added a commit to 12rambau/pydata-sphinx-theme that referenced this pull request Mar 2, 2023
* Fix extra whitespace in sidebars (pydata#1115)

* Fix extra whitespace in sidebars

* Searchbox

* Update src/pydata_sphinx_theme/__init__.py

Co-authored-by: Daniel McCloy <[email protected]>

* make test pass

* Fix template filter to remove empty files

* ABlog in template test

* Move clear search button to primary sidebar

* Move search clear button to top of article

Co-authored-by: Daniel McCloy <[email protected]>

* FIX: Use logo_url instead deprecated logo in theme (pydata#1094) (pydata#1097)

resolves pydata#1094

* ENH/MAINT: avoid overwriting the HtmlTranslator (pydata#1105)

Co-authored-by: Chris Holdgraf <[email protected]>
Fix pydata#143
Fix pydata#94

* fix: align sidebar sliding with the buttons (pydata#1123)

* fix: aline the sidebar sliding with the buttons

* build: force test to run on all platform
if one platform is failing we cannot see if it's platform related as the other were closed

* fix: use correct path for documentation logo

* MAINT: Improve font sizing (pydata#1129)

Fix pydata#1001

* MAINT: Refactor workflows to reduce test dependencies (pydata#1136)

* MAINT: update prerelease workflow (pydata#1140)

* ABlog: Updates for new HTML structure (pydata#1118)

* ABlog: Updates for new HTML structure

* Update templates for latest release

* Bump to dev0

* Standardize logo image behavior between Sphinx and this theme (pydata#1132)

Co-authored-by: Daniel McCloy <[email protected]>
Co-authored-by: Chris Holdgraf <[email protected]>
Co-authored-by: Chris Holdgraf <[email protected]>

* 0.13.0rc1

* Build(deps): Bump http-cache-semantics from 4.1.0 to 4.1.1 (pydata#1154)

* DOC: Use only shield.io for badges in README (pydata#1152)

* Copyright semicolon (pydata#1160)

* FIX: Flex behavior should shrink header items instead of brand (pydata#1158)

Co-authored-by: Chris Holdgraf <[email protected]>
Fixes pydata#1143

* STYLE: lint the documentation with Doc8 (pydata#1150)

Fix pydata#1139

* Add test for internationalization and translations (pydata#1138)

* FIX: Javascript incorrect check for variable (pydata#1166)

* MAINT: update pypi classifiers (pydata#1153)

Fix pydata#1106

* remove emoji from landing page (pydata#1151)

* add fa icons instead of emoji

* remove fix for emojis

* use markup for readme emojis

* use pst-color-primary instead of sd-text-primary

* make our semantic colors available as classes

* try again

---------

Co-authored-by: Daniel McCloy <[email protected]>

* FIX: Narrow scope of style rule for GitHub & GitLab link shortening (pydata#1167)

Fixes pydata#1156

* ENH: Add breadcrumbs to article header (pydata#1142)

* ENH: Add breadcrumbs to article header

* Update src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/breadcrumbs.html

Co-authored-by: Tania Allard <[email protected]>

* More fixes

* Improving nested page behavior

* Documenting breadcrumbs

* Update src/pydata_sphinx_theme/assets/styles/components/_breadcrumbs.scss

Co-authored-by: Rambaud Pierrick <[email protected]>

* Breacrumbs have link color

---------

Co-authored-by: Tania Allard <[email protected]>
Co-authored-by: Rambaud Pierrick <[email protected]>

* Degrade gracefully when JavaScript is disabled (pydata#1146)

* Fix header vertical spacing and jupyter-sphinx cells (pydata#1164)

Fixes undefined

* RLS: v0.13.0rc2 (pydata#1170)

* DOCS: admonition customization (pydata#1155)

* first draft of the admonition customization

* typo in doc link

* flesh out admon. customization example; DRY

* use :code:rst instead of :literal:

* Update docs/_static/custom.css

---------

Co-authored-by: Daniel McCloy <[email protected]>

* Fix article header CSS (pydata#1171)

* “Edit this page” → “Edit on GitHub/GitLab/Bitbucket” (pydata#1177)

* “Edit this page” → “Edit on GitHub/GitLab/Bitbucket”

Fixes pydata#1172

* Add tests

* Fix typo

* Properly handle default_mode=auto when writing logos (pydata#1183)

We used to only defaulting to the light version when `default_mode` was
undefined, not when it was explicitly set to `auto`. We also need to
handle the latter, as the new test shows.

Closes pydata#1180

Co-authored-by: Jérémy Bobbio (Lunar) <[email protected]>

* fix: correctly add DOM listeners (pydata#1179)

fix adding DOM listeners

* maint: update GitLab URL tests (pydata#1186)

Co-authored-by: JoerivanEngelen <[email protected]>

* Standardize template structure in more sections (pydata#1184)

* Standardize template structure in all sections

* Fixing footer behavior

* Update docs/user_guide/layout.rst

Co-authored-by: Daniel McCloy <[email protected]>

* Remove use of id= as much as possible

---------

Co-authored-by: Daniel McCloy <[email protected]>

* maint: remove sphinx-panels support; remove deprecated config shims (pydata#1188)

* Minor style improvements to ablog (pydata#1185)

* RLS: v0.13.0rc3

* dev0

* FIX: Some style bugs (pydata#1191)

* FIX: Some style bugs

* Move link word wrap to global rule

* DOCS: Add internationalization instructions (pydata#1178)

Co-authored-by: James McKinney <[email protected]>

* Refactor contributing docs to be more modular (pydata#1173)

* Dev0

* Fix github gitlab brand (pydata#1194)

* RLS: v0.13.0rc4

* FIX: Make wide equations scroll (pydata#1196)

* Fix math scrollbars for realz (pydata#1198)

* Fix math scrollbars for realz

* Update src/pydata_sphinx_theme/assets/styles/content/_math.scss

* Update src/pydata_sphinx_theme/assets/styles/content/_math.scss

* copy_logo_images: do not render dynamic Sphinx template content (pydata#1204)

* copy_logo_images: do not render dynamic Sphinx template content when copying logo image files

* Update src/pydata_sphinx_theme/__init__.py

---------

Co-authored-by: Chris Holdgraf <[email protected]>

* Add conditional check for last-updated template (pydata#1201)

* Add conditional check for last-updated template

* Whitespace

* Properly set configuration with app.builder.theme_options (pydata#1199)

* Properly set configuration

* Dict to values

* Making it explicit in a function

* Better name

* Fix test

* Foot

* Revert complex config set

* Clarify docs

* Use CSS transform for skip link (pydata#1206)

* feat: Add full i18n support (pydata#1192)

Co-authored-by: Daniel McCloy <[email protected]>
Co-authored-by: James McKinney <[email protected]>
Co-authored-by: Chris Holdgraf <[email protected]>
Co-authored-by: Chris Holdgraf <[email protected]>

* Dev0

* FIX: Remove icon links component when no icon links given (pydata#1209)

* RLS: 0.13.0rc5

* dev0

* FIX: Get theme options in a more robust way (pydata#1214)

* RLS: v0.13.0rc6

* Make heading-style use the font-weight-heading value (pydata#1213)

* Make heading-style use the font-weight-heading value

* Separate font-weight setting for content headers and admonitions

* Flip var to be consistent with --pst-font-weight-heading instead

* RLS: v0.13.0

* bump: dev0

* DOCS: Remove <p> from announcement sample text (pydata#1223)

---------

Co-authored-by: Chris Holdgraf <[email protected]>
Co-authored-by: Daniel McCloy <[email protected]>
Co-authored-by: Nico Albers <[email protected]>
Co-authored-by: Chris Holdgraf <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Brendan Heberlein <[email protected]>
Co-authored-by: Tania Allard <[email protected]>
Co-authored-by: Lunar <[email protected]>
Co-authored-by: Jean Abou-Samra <[email protected]>
Co-authored-by: Jérémy Bobbio (Lunar) <[email protected]>
Co-authored-by: JoerivanEngelen <[email protected]>
Co-authored-by: James McKinney <[email protected]>
Co-authored-by: James Addison <[email protected]>
Co-authored-by: Veronica Berglyd Olsen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants