@@ -26,6 +26,7 @@ def setup(app):
26
26
27
27
app .add_config_value ("is_pallets_theme" , None , "html" )
28
28
app .add_config_value ("rtd_canonical_path" , "/en/stable/" , "html" )
29
+ app .add_config_value ("version_banner" , True , "html" )
29
30
30
31
# Use the sphinx-notfound-page extension to generate a 404 page with valid
31
32
# URLs. Only configure it if it's not already configured.
@@ -82,16 +83,25 @@ def find_base_canonical_url(app: Sphinx) -> None:
82
83
83
84
@only_pallets_theme ()
84
85
def add_theme_files (app : Sphinx ) -> None :
85
- # Add the JavaScript for the version warning banner. Include the project and
86
- # version as data attributes that the script will access. The project name
87
- # is assumed to be the PyPI name, and is normalized to avoid a redirect.
88
- app .add_js_file (
89
- "describe_version.js" ,
90
- ** {
91
- "data-project" : re .sub (r"[-_.]+" , "-" , app .config .project ).lower (),
92
- "data-version" : app .config .version ,
93
- },
94
- )
86
+ # Add the JavaScript for the version warning banner if ``version_banner`` is
87
+ # enabled. On Read the Docs, don't include it for stable or PR builds.
88
+ # Include the project and version as data attributes that the script will
89
+ # access. The project name is assumed to be the PyPI name, and is normalized
90
+ # to avoid a redirect.
91
+ rtd_version = os .environ .get ("READTHEDOCS_VERSION" )
92
+ rtd_version_type = os .environ .get ("READTHEDOCS_VERSION_TYPE" )
93
+
94
+ if app .config .version_banner and (
95
+ rtd_version is None # not on read the docs
96
+ or (rtd_version != "stable" and rtd_version_type in {"branch" , "tag" })
97
+ ):
98
+ app .add_js_file (
99
+ "describe_version.js" ,
100
+ ** {
101
+ "data-project" : re .sub (r"[-_.]+" , "-" , app .config .project ).lower (),
102
+ "data-version" : app .config .version ,
103
+ },
104
+ )
95
105
96
106
97
107
@only_pallets_theme ()
0 commit comments