]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
python3-jinja2: backport a patch to address python 3.13 ptest fails
authorAlexander Kanavin <alex@linutronix.de>
Wed, 16 Oct 2024 19:36:05 +0000 (21:36 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 22 Oct 2024 11:26:25 +0000 (12:26 +0100)
Signed-off-by: Alexander Kanavin <alex@linutronix.de>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/recipes-devtools/python/python3-jinja2/fix-3.13.patch [new file with mode: 0644]
meta/recipes-devtools/python/python3-jinja2_3.1.4.bb

diff --git a/meta/recipes-devtools/python/python3-jinja2/fix-3.13.patch b/meta/recipes-devtools/python/python3-jinja2/fix-3.13.patch
new file mode 100644 (file)
index 0000000..34ecd15
--- /dev/null
@@ -0,0 +1,87 @@
+From cf6ba7732b49ab4637aa747186cf1d1572688584 Mon Sep 17 00:00:00 2001
+From: Thomas Grainger <tagrain@gmail.com>
+Date: Mon, 13 May 2024 18:02:35 +0100
+Subject: [PATCH] fix test_package_zip_list on 3.13
+
+Upstream-Status: Backport [https://github.com/pallets/jinja/pull/1979]
+Signed-off-by: Alexander Kanavin <alex@linutronix.de>
+---
+ src/jinja2/loaders.py | 32 ++++++++++++++++++++++++++------
+ tests/test_loader.py  |  4 ++--
+ 2 files changed, 28 insertions(+), 8 deletions(-)
+
+diff --git a/src/jinja2/loaders.py b/src/jinja2/loaders.py
+index 9eaf647..8c2c86c 100644
+--- a/src/jinja2/loaders.py
++++ b/src/jinja2/loaders.py
+@@ -238,6 +238,30 @@ class FileSystemLoader(BaseLoader):
+         return sorted(found)
++if sys.version_info >= (3, 13):
++
++    def _get_zipimporter_files(z: t.Any) -> t.Dict[str, object]:
++        try:
++            get_files = z._get_files
++        except AttributeError as e:
++            raise TypeError(
++                "This zip import does not have the required"
++                " metadata to list templates."
++            ) from e
++        return get_files()
++else:
++
++    def _get_zipimporter_files(z: t.Any) -> t.Dict[str, object]:
++        try:
++            files = z._files
++        except AttributeError as e:
++            raise TypeError(
++                "This zip import does not have the required"
++                " metadata to list templates."
++            ) from e
++        return files  # type: ignore[no-any-return]
++
++
+ class PackageLoader(BaseLoader):
+     """Load templates from a directory in a Python package.
+@@ -382,11 +406,7 @@ class PackageLoader(BaseLoader):
+                     for name in filenames
+                 )
+         else:
+-            if not hasattr(self._loader, "_files"):
+-                raise TypeError(
+-                    "This zip import does not have the required"
+-                    " metadata to list templates."
+-                )
++            files = _get_zipimporter_files(self._loader)
+             # Package is a zip file.
+             prefix = (
+@@ -395,7 +415,7 @@ class PackageLoader(BaseLoader):
+             )
+             offset = len(prefix)
+-            for name in self._loader._files.keys():
++            for name in files:
+                 # Find names under the templates directory that aren't directories.
+                 if name.startswith(prefix) and name[-1] != os.path.sep:
+                     results.append(name[offset:].replace(os.path.sep, "/"))
+diff --git a/tests/test_loader.py b/tests/test_loader.py
+index 77d686e..e0683e4 100644
+--- a/tests/test_loader.py
++++ b/tests/test_loader.py
+@@ -364,8 +364,8 @@ def test_package_zip_source(package_zip_loader, template, expect):
+ @pytest.mark.xfail(
+-    platform.python_implementation() == "PyPy",
+-    reason="PyPy's zipimporter doesn't have a '_files' attribute.",
++    sys.implementation.name == "pypy",
++    reason="zipimporter doesn't have a '_files' attribute",
+     raises=TypeError,
+ )
+ def test_package_zip_list(package_zip_loader):
+-- 
+2.39.5
+
index f2de1983ced508fc13df6403bb6439356b08e457..a11878496c60aa8afa10078964655ae84b4272b6 100644 (file)
@@ -17,6 +17,7 @@ UPSTREAM_CHECK_PYPI_PACKAGE = "Jinja2"
 
 SRC_URI += " \
        file://run-ptest \
+       file://fix-3.13.patch \
 "
 
 do_install_ptest() {