Blame 132.patch

f025681
From 8f68aaf020fab4c53c2bc7849ba1d89a0f811bea Mon Sep 17 00:00:00 2001
f025681
From: Manuel Kaufmann <humitos@gmail.com>
f025681
Date: Mon, 5 Jul 2021 10:54:28 +0200
f025681
Subject: [PATCH 1/3] :ok_hand: IMPROVE: Use Sphinx HTML assets policy to
f025681
 decide whether include assets
f025681
f025681
Sphinx v4.1.0 will include `Sphinx.registry.html_assets_policy` that defines the
f025681
policy to whether include or not HTML assets in pages where the extension is not
f025681
used.
f025681
f025681
This PR makes usage of this policy to decide if sphinx-tabs assets should be
f025681
included or not in the page that's being rendered.
f025681
f025681
Reference: https://github.com/sphinx-doc/sphinx/issues/9115
f025681
---
f025681
 sphinx_tabs/tabs.py | 8 +++++++-
f025681
 tests/test_build.py | 9 +++++++++
f025681
 2 files changed, 16 insertions(+), 1 deletion(-)
f025681
f025681
diff --git a/sphinx_tabs/tabs.py b/sphinx_tabs/tabs.py
f025681
index 93742ca..33090af 100644
f025681
--- a/sphinx_tabs/tabs.py
f025681
+++ b/sphinx_tabs/tabs.py
f025681
@@ -1,6 +1,7 @@
f025681
 """ Tabbed views for Sphinx, with HTML builder """
f025681
 
f025681
 import base64
f025681
+import sphinx
f025681
 from pathlib import Path
f025681
 from functools import partial
f025681
 
f025681
@@ -313,7 +314,12 @@ def update_context(app, pagename, templatename, context, doctree):
f025681
         return
f025681
     visitor = _FindTabsDirectiveVisitor(doctree)
f025681
     doctree.walk(visitor)
f025681
-    if not visitor.found_tabs_directive:
f025681
+
f025681
+    include_assets_in_all_pages = False
f025681
+    if sphinx.version_info >= (4, 1, 0):
f025681
+        include_assets_in_all_pages = app.registry.html_assets_policy == 'always'
f025681
+
f025681
+    if not visitor.found_tabs_directive and not include_assets_in_all_pages:
f025681
         paths = [Path("_static") / f for f in FILES]
f025681
         if "css_files" in context:
f025681
             context["css_files"] = context["css_files"][:]
f025681
diff --git a/tests/test_build.py b/tests/test_build.py
f025681
index 5f1d3f9..ed8331e 100644
f025681
--- a/tests/test_build.py
f025681
+++ b/tests/test_build.py
f025681
@@ -25,6 +25,15 @@ def test_conditional_assets(app, docname, check_asset_links):
f025681
         )
f025681
 
f025681
 
f025681
+@pytest.mark.parametrize("docname", ["index", "no_tabs1", "no_tabs2"])
f025681
+@pytest.mark.sphinx(testroot="conditionalassets")
f025681
+@pytest.mark.skipif(
f025681
+    sphinx.version_info[:2] >= (4, 1), reason="Test uses Sphinx 4.1 config"
f025681
+)
f025681
+def test_conditional_assets(app, docname, check_asset_links):
f025681
+    check_asset_links(app, filename=docname + ".html")
f025681
+
f025681
+
f025681
 @pytest.mark.sphinx(testroot="linenos")
f025681
 @pytest.mark.skipif(
f025681
     sphinx.version_info[:2] >= (4, 0), reason="Test uses Sphinx 3 code blocks"
f025681
f025681
From 33e8075ffa0105b6e789037aa701d29149c5465a Mon Sep 17 00:00:00 2001
f025681
From: Manuel Kaufmann <humitos@gmail.com>
f025681
Date: Mon, 26 Jul 2021 11:38:58 +0200
f025681
Subject: [PATCH 2/3] Update test for conditional assets
f025681
f025681
---
f025681
 tests/test_build.py | 24 ++++++++++++++++++++++--
f025681
 1 file changed, 22 insertions(+), 2 deletions(-)
f025681
f025681
diff --git a/tests/test_build.py b/tests/test_build.py
f025681
index ed8331e..ee01aa9 100644
f025681
--- a/tests/test_build.py
f025681
+++ b/tests/test_build.py
f025681
@@ -25,12 +25,32 @@ def test_conditional_assets(app, docname, check_asset_links):
f025681
         )
f025681
 
f025681
 
f025681
+@pytest.mark.noautobuild
f025681
 @pytest.mark.parametrize("docname", ["index", "no_tabs1", "no_tabs2"])
f025681
 @pytest.mark.sphinx(testroot="conditionalassets")
f025681
 @pytest.mark.skipif(
f025681
-    sphinx.version_info[:2] >= (4, 1), reason="Test uses Sphinx 4.1 config"
f025681
+    sphinx.version_info[:2] < (4, 1), reason="Test uses Sphinx 4.1 config"
f025681
 )
f025681
-def test_conditional_assets(app, docname, check_asset_links):
f025681
+def test_conditional_assets_html_assets_policy(
f025681
+    app,
f025681
+    docname,
f025681
+    status,
f025681
+    warning,
f025681
+    check_build_success,
f025681
+    get_sphinx_app_doctree,
f025681
+    regress_sphinx_app_output,
f025681
+    check_asset_links,
f025681
+):
f025681
+    app.set_html_assets_policy("always")
f025681
+
f025681
+    # Following lines are copied from ``auto_build_and_check`` since we need to
f025681
+    # set a config in the build object before auto build. Because of this, we
f025681
+    # need to use ``noautobuild``.
f025681
+    app.build()
f025681
+    check_build_success(status, warning)
f025681
+    get_sphinx_app_doctree(app, regress=True)
f025681
+    regress_sphinx_app_output(app)
f025681
+
f025681
     check_asset_links(app, filename=docname + ".html")
f025681
 
f025681
 
f025681
f025681
From a97fee53cdfa7abbead9404383b9d42e9adeb4a5 Mon Sep 17 00:00:00 2001
f025681
From: foster999 <foster.dev999@gmail.com>
f025681
Date: Wed, 4 Aug 2021 22:56:19 +0100
f025681
Subject: [PATCH 3/3] Run pre-commit
f025681
f025681
---
f025681
 sphinx_tabs/tabs.py | 5 +++--
f025681
 1 file changed, 3 insertions(+), 2 deletions(-)
f025681
f025681
diff --git a/sphinx_tabs/tabs.py b/sphinx_tabs/tabs.py
f025681
index 33090af..3852b7d 100644
f025681
--- a/sphinx_tabs/tabs.py
f025681
+++ b/sphinx_tabs/tabs.py
f025681
@@ -1,9 +1,10 @@
f025681
 """ Tabbed views for Sphinx, with HTML builder """
f025681
 
f025681
 import base64
f025681
-import sphinx
f025681
 from pathlib import Path
f025681
 from functools import partial
f025681
+import sphinx
f025681
+
f025681
 
f025681
 from docutils import nodes
f025681
 from docutils.parsers.rst import directives
f025681
@@ -317,7 +318,7 @@ def update_context(app, pagename, templatename, context, doctree):
f025681
 
f025681
     include_assets_in_all_pages = False
f025681
     if sphinx.version_info >= (4, 1, 0):
f025681
-        include_assets_in_all_pages = app.registry.html_assets_policy == 'always'
f025681
+        include_assets_in_all_pages = app.registry.html_assets_policy == "always"
f025681
 
f025681
     if not visitor.found_tabs_directive and not include_assets_in_all_pages:
f025681
         paths = [Path("_static") / f for f in FILES]