1
1
import datetime
2
2
import subprocess
3
- from urllib .parse import urlsplit , urlunsplit
4
3
5
4
# -- Project information -----------------------------------------------------
6
5
32
31
# This pattern also affects html_static_path and html_extra_path.
33
32
exclude_patterns = ["_build" , "Thumbs.db" , ".DS_Store" ]
34
33
35
- # General substitutions.
36
- try :
37
- SHA = subprocess .check_output (
38
- ['git' , 'rev-parse' , 'HEAD' ]).decode ('utf-8' ).strip ()
39
- # Catch the case where git is not installed locally, and use the setuptools_scm
40
- # version number instead.
41
- except (subprocess .CalledProcessError , FileNotFoundError ):
42
- import hashlib
43
- import matplotlib
44
- import mpl_sphinx_theme
45
- import pydata_sphinx_theme
46
- SHA = hashlib .sha256 (
47
- (f'{ matplotlib .__version__ } '
48
- f'{ mpl_sphinx_theme .__version__ } '
49
- f'{ pydata_sphinx_theme .__version__ } ' ).encode ('utf-8' )).hexdigest ()
50
- SHA = SHA [:20 ]
51
-
52
-
53
34
# -- Options for HTML output -------------------------------------------------
54
35
55
- def add_html_cache_busting (app , pagename , templatename , context , doctree ):
56
- """
57
- Add cache busting query on CSS and JavaScript assets.
58
-
59
- This adds the Matplotlib version as a query to the link reference in the
60
- HTML, if the path is not absolute (i.e., it comes from the `_static`
61
- directory) and doesn't already have a query.
62
- """
63
- from sphinx .builders .html import Stylesheet , JavaScript
64
-
65
- css_tag = context ['css_tag' ]
66
- js_tag = context ['js_tag' ]
67
-
68
- def css_tag_with_cache_busting (css ):
69
- if isinstance (css , Stylesheet ) and css .filename is not None :
70
- url = urlsplit (css .filename )
71
- if not url .netloc and not url .query :
72
- url = url ._replace (query = SHA )
73
- css = Stylesheet (urlunsplit (url ), priority = css .priority ,
74
- ** css .attributes )
75
- return css_tag (css )
76
-
77
- def js_tag_with_cache_busting (js ):
78
- if isinstance (js , JavaScript ) and js .filename is not None :
79
- url = urlsplit (js .filename )
80
- if not url .netloc and not url .query :
81
- url = url ._replace (query = SHA )
82
- js = JavaScript (urlunsplit (url ), priority = js .priority ,
83
- ** js .attributes )
84
- return js_tag (js )
85
-
86
- context ['css_tag' ] = css_tag_with_cache_busting
87
- context ['js_tag' ] = js_tag_with_cache_busting
88
-
89
-
90
36
html_css_files = ['css/normalize.css' , 'css/landing.css' ]
91
37
html_theme = "mpl_sphinx_theme"
92
38
html_favicon = "_static/favicon.ico"
@@ -103,10 +49,3 @@ def js_tag_with_cache_busting(js):
103
49
104
50
# Prefix added to all the URLs generated in the 404 page.
105
51
notfound_urls_prefix = '/'
106
-
107
-
108
- # -----------------------------------------------------------------------------
109
- # Sphinx setup
110
- # -----------------------------------------------------------------------------
111
- def setup (app ):
112
- app .connect ('html-page-context' , add_html_cache_busting , priority = 1000 )
0 commit comments