Sphinx themes for Pallets and related projects with specialized documentation directives
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Five pre-configured Sphinx themes providing consistent visual styling for Pallets projects. All themes inherit from the base pocoo theme and include project-specific stylesheets, Pygments syntax highlighting, and customized layouts.
Five themes are automatically registered when the extension loads, each designed for specific Pallets projects.
# Theme configuration in conf.py
html_theme = "pocoo" # Base theme with pocoo styling
html_theme = "flask" # Flask project theme
html_theme = "jinja" # Jinja project theme
html_theme = "werkzeug" # Werkzeug project theme
html_theme = "click" # Click project themeAutomatic detection of whether the current theme is a Pallets theme, enabling theme-specific functionality.
def set_is_pallets_theme(app):
"""
Set the is_pallets_theme config value based on current theme.
Detects if the current theme inherits from the pocoo theme by
checking theme directory hierarchy. Sets is_pallets_theme config
to True/False accordingly.
Parameters:
- app: Sphinx application instance
"""Decorator factory for creating functions that only execute when using a Pallets theme.
def only_pallets_theme(default=None):
"""
Create decorator that executes function only with Pallets themes.
Used to prevent Sphinx event callbacks from running when Pallets
themes are installed but not active.
Parameters:
- default: Value to return if not using a Pallets theme
Returns:
function: Decorator that wraps the target function
"""The foundational theme that all other Pallets themes inherit from.
Configuration:
basic themepocoo.csspocoolocaltoc.html, relations.html, searchbox.html, ethicalads.htmlindex_sidebar_logo = TrueTemplates included:
layout.html - Main page layoutlocaltoc.html - Local table of contentsrelations.html - Previous/next navigationproject.html - Project informationethicalads.html - Ethical advertising integrationJavaScript:
describe_version.js - Version warning banner functionalityCustomized theme for Flask project documentation.
Configuration:
pocooflask.cssCustomized theme for Jinja project documentation with specialized syntax highlighting.
Configuration:
pocoojinja.cssjinja (custom JinjaStyle class)Customized theme for Click project documentation.
Configuration:
pocooclick.csstangoCustomized theme for Werkzeug project documentation.
Configuration:
pocoowerkzeug.cssConfigure your theme in conf.py:
# Select a theme
html_theme = "flask"
# Optional: Override theme-specific settings
html_theme_options = {
"index_sidebar_logo": False # For pocoo-based themes
}Create functions that only run with Pallets themes:
from pallets_sphinx_themes.theme_check import only_pallets_theme
@only_pallets_theme()
def add_custom_css(app):
"""Add custom CSS only when using Pallets themes."""
app.add_css_file("custom-pallets.css")
@only_pallets_theme(default="Not using Pallets theme")
def get_theme_status(app):
"""Return theme-specific message."""
return f"Using Pallets theme: {app.builder.theme.name}"
def setup(app):
app.connect("builder-inited", add_custom_css)Configure different behavior based on theme detection:
# conf.py
extensions = ["pallets_sphinx_themes"]
html_theme = "flask"
# This will be auto-set to True after theme detection
if html_theme in ["pocoo", "flask", "jinja", "werkzeug", "click"]:
# Pallets-specific configuration
version_banner = True
rtd_canonical_path = "/en/stable/"
else:
# Non-Pallets theme configuration
version_banner = FalseThe themes automatically set appropriate Pygments styles, but you can override:
# Automatic (recommended):
html_theme = "jinja" # Automatically uses "jinja" pygments style
html_theme = "click" # Automatically uses "tango" pygments style
# Manual override:
html_theme = "flask"
pygments_style = "pocoo" # Override to use pocoo style insteadTheme-related configuration values available in conf.py:
# Theme selection
html_theme = "flask" # str: Theme name ("pocoo", "flask", "jinja", "werkzeug", "click")
# Auto-detected theme status (set by extension)
is_pallets_theme = None # bool or None: True when using any Pallets theme
# Theme-specific options (pocoo base theme)
html_theme_options = {
"index_sidebar_logo": True # bool: Show logo in index sidebar
}
# Version banner (theme-aware)
version_banner = True # bool: Enable version warning banner
# Canonical path for Read the Docs (theme-aware)
rtd_canonical_path = "/en/stable/" # str: Default canonical pathInstall with Tessl CLI
npx tessl i tessl/pypi-pallets-sphinx-themes