pydata / pydata-sphinx-theme

A clean, three-column Sphinx theme with Bootstrap for the PyData community
https://pydata-sphinx-theme.readthedocs.io
BSD 3-Clause "New" or "Revised" License
557 stars 299 forks source link

Version switcher displays Choose version instead of actual version #1829

Closed hcording closed 3 weeks ago

hcording commented 1 month ago

Related to: #1681, #1500, #1512

When opening any built page on RTD with this theme, the switcher menu shows "Choose version" instead of the selected version. I largely followed the conf.py for this repo, especially after reading #1512. From what I can see, my tags and settings are fairly standard, the only difference is that I dynamically load name, author, copyright, release and version from .pyproject.toml and .bump_my_version.toml. But I added print statements and the build log shows these values are initialized correctly (version == release == 0.0.7 on stable, for example).

My versioning scheme follows semver, and works as follows: x.y.z-alphaN, x.y.z-betaN, x.y.z-rcN, x.y.z

conf.py

# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
import datetime
import os
import sys
from pathlib import Path

import toml

sys.path.insert(0, os.path.abspath('../'))

# -- Project information -----------------------------------------------------

pyproject_toml_dict: dict = toml.load(
    Path(__file__).parents[1] / "pyproject.toml")
project_dict: dict = pyproject_toml_dict["project"]
project = project_dict["name"]
_authors: list[dict] = project_dict["authors"]
author: str = ", ".join([f"{a['name']} <{a['email']}>" for a in _authors])
copyright: str = f'{datetime.datetime.now().year}, {author}'

bumpversion_toml = toml.load(Path(__file__).parents[1] / ".bumpversion.toml")
release: str = bumpversion_toml["tool"]["bumpversion"]["current_version"] # e.g., this becomes 0.0.7 on stable
version: str = release

print(version)

# -- General configuration ---------------------------------------------------

extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.viewcode',
    'sphinx.ext.coverage',
    'sphinx.ext.doctest',
    'sphinx.ext.mathjax',
]

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# -- Options for HTML output -------------------------------------------------

version_match = os.environ.get("READTHEDOCS_VERSION")
if not version_match or version_match.isdigit() or version_match == "latest":
    # For local development, infer the version to match from the package.
    if '-' in release:
        version_match = "dev"
        json_url = "_static/switcher.json"
    else:
        version_match = release
elif version_match == "stable":
    version_match = release

html_theme = 'pydata_sphinx_theme'
html_static_path = ['_static']
json_url = "https://impart.readthedocs.io/en/latest/_static/switcher.json"

html_theme_options = {
    "switcher": {
        "version_match": version_match,
        "json_url": json_url,
    },
    "footer_start": [
        "version-switcher"
    ],
    "show_version_warning_banner": True,
}
html_show_sourcelink = False
html_title = f"{project} {release}"

And this is my switcher.json, located in docs/_static/:

[
    {
        "name": "dev",
        "version": "dev",
        "url": "https://impart.readthedocs.io/en/latest/"
    },
    {
        "name": "0.0.7 (stable)",
        "version": "0.0.7",
        "url": "https://impart.readthedocs.io/en/stable/",
        "preferred": true
    },
    {
        "name": "0.0.6",
        "version": "0.0.6",
        "url": "https://impart.readthedocs.io/en/0.0.6/"
    },
    {
        "name": "0.0.5",
        "version": "0.0.5",
        "url": "https://impart.readthedocs.io/en/0.0.5/"
    }
]

I see the following when opening the stable page the first time after building:

image

After reloading the page, or clicking on 0.0.7 (stable), it looks like this (and remains like this for consecutive page visits):

image

Any help is appreciated!

drammock commented 4 weeks ago

If I load https://impart.readthedocs.io/en/stable/ and view the browser devtools console, I see

Uncaught (in promise) TypeError: document.querySelector(...) is null
    T pydata-sphinx-theme.js:569
    r mixin.js:11
    937 pydata-sphinx-theme.js:584

I see your site was built with version 0.15.2 of the theme. I think this problem was fixed as a side-effect of #1780

Can you see if it still happens when building the docs with the current version of the theme (0.15.3)?

hcording commented 3 weeks ago

I've gone ahead and updated to 0.15.3, which fixed the issue! :partying_face: The switcher now shows the correct version in the preview.

As a side note, the vertical cyan bar to indicate the currently selected version when the switcher is expanded seems to work only sometimes. For me, it will often disappear after reloading the page. But that's another issue.

Anyways, thanks for the update! Closing as resolved.