Skip to content

Conversation

@mhughes2012
Copy link

Purpose

This PR fixes a bug where HTML themes that inherit from a parent theme would accidentally overwrite the parent's stylesheet list instead of extending it. This was particularly problematic for themes like agogo or traditional that inherit from the basic theme; they would lose the core basic.css styles if they defined their own stylesheets.

Changes:

  • Updated Theme initialization in sphinx/theming.py to merge stylesheet lists from the entire inheritance chain.
  • Implemented deduplication to prevent the same stylesheet from being loaded multiple times (e.g., if both parent and child explicitly list basic.css) while preserving the correct loading order.
  • Updated existing tests in tests/test_theming/test_theming.py that were previously asserting the "replacement" behavior.

I have verified this fix using a reproduction script that builds a project with the agogo theme and confirms that basic.css is correctly included in the final HTML output.

References

Previously, if a theme defined a stylesheet, it would completely
overwrite the stylesheet list of any parent themes. This caused
inherited themes (like 'agogo' or 'traditional') to lose the
foundation 'basic.css' from the 'basic' theme.

This change:
1.  Modifies Theme initialization to append inherited stylesheets
    rather than replacing them.
2.  Ensures stylesheets are deduplicated while preserving order.
3.  Updates existing tests that relied on the previous replacement
    behavior to expect the full inheritance chain.
Python 3.15's argparse is stricter with '%' sequences in version and
help strings. Switching to an f-string for the version argument avoids
the ValueError caused by the previous manual string formatting.
@mhughes2012 mhughes2012 marked this pull request as draft January 15, 2026 22:05
@mhughes2012 mhughes2012 marked this pull request as ready for review January 16, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some themes do not import CSS from basic

1 participant