Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Backport PR #23790 on branch v3.6.x (DOC: Add cache busting to all static assets) #23799

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 50 additions & 15 deletions 65 doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import shutil
import subprocess
import sys
from urllib.parse import urlsplit, urlunsplit
import warnings

import matplotlib
Expand Down Expand Up @@ -248,10 +249,6 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
except (subprocess.CalledProcessError, FileNotFoundError):
SHA = matplotlib.__version__

html_context = {
"sha": SHA,
}

project = 'Matplotlib'
copyright = (
'2002–2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom '
Expand Down Expand Up @@ -312,16 +309,50 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,

github_project_url = "https://github.com/matplotlib/matplotlib/"


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

def add_html_cache_busting(app, pagename, templatename, context, doctree):
"""
Add cache busting query on CSS and JavaScript assets.

This adds the Matplotlib version as a query to the link reference in the
HTML, if the path is not absolute (i.e., it comes from the `_static`
directory) and doesn't already have a query.
"""
from sphinx.builders.html import Stylesheet, JavaScript

css_tag = context['css_tag']
js_tag = context['js_tag']

def css_tag_with_cache_busting(css):
if isinstance(css, Stylesheet) and css.filename is not None:
url = urlsplit(css.filename)
if not url.netloc and not url.query:
url = url._replace(query=SHA)
css = Stylesheet(urlunsplit(url), priority=css.priority,
**css.attributes)
return css_tag(css)

def js_tag_with_cache_busting(js):
if isinstance(js, JavaScript) and js.filename is not None:
url = urlsplit(js.filename)
if not url.netloc and not url.query:
url = url._replace(query=SHA)
js = JavaScript(urlunsplit(url), priority=js.priority,
**js.attributes)
return js_tag(js)

context['css_tag'] = css_tag_with_cache_busting
context['js_tag'] = js_tag_with_cache_busting


# The style sheet to use for HTML and HTML Help pages. A file of that name
# must exist either in Sphinx' static/ path, or in one of the custom paths
# given in html_static_path.
# html_style = 'matplotlib.css'
# html_style = f"mpl.css?{SHA}"
html_css_files = [
f"mpl.css?{SHA}",
"mpl.css",
]

html_theme = "mpl_sphinx_theme"
Expand Down Expand Up @@ -574,14 +605,6 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
# https://github.com/sphinx-doc/sphinx/issues/3176
# graphviz_output_format = 'svg'


def setup(app):
if any(st in version for st in ('post', 'alpha', 'beta')):
bld_type = 'dev'
else:
bld_type = 'rel'
app.add_config_value('releaselevel', bld_type, 'env')

# -----------------------------------------------------------------------------
# Source code links
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -649,3 +672,15 @@ def linkcode_resolve(domain, info):
f"/{tag}/lib/{fn}{linespec}")
else:
extensions.append('sphinx.ext.viewcode')


# -----------------------------------------------------------------------------
# Sphinx setup
# -----------------------------------------------------------------------------
def setup(app):
if any(st in version for st in ('post', 'dev', 'alpha', 'beta')):
bld_type = 'dev'
else:
bld_type = 'rel'
app.add_config_value('releaselevel', bld_type, 'env')
app.connect('html-page-context', add_html_cache_busting, priority=1000)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.