dev-python/jinja: Enable py3.13

Signed-off-by: Michał Górny <mgorny@gentoo.org>
This commit is contained in:
Michał Górny
2024-05-14 11:43:37 +02:00
parent af5ea045bd
commit 17d621befb
2 changed files with 73 additions and 1 deletions

View File

@@ -0,0 +1,67 @@
From 679af7f816ced8941ed5cf9b151a0cac543d0336 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
---
src/jinja2/loaders.py | 32 ++++++++++++++++++++++++++------
tests/test_loader.py | 2 +-
2 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/src/jinja2/loaders.py b/src/jinja2/loaders.py
index 9eaf647ba..8c2c86cd0 100644
--- a/src/jinja2/loaders.py
+++ b/src/jinja2/loaders.py
@@ -238,6 +238,30 @@ def list_templates(self) -> t.List[str]:
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 @@ def list_templates(self) -> t.List[str]:
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 @@ def list_templates(self) -> t.List[str]:
)
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, "/"))

View File

@@ -5,7 +5,7 @@ EAPI=8
DISTUTILS_USE_PEP517=flit
PYPI_PN=jinja2
PYTHON_COMPAT=( python3_{10..12} pypy3 )
PYTHON_COMPAT=( python3_{10..13} pypy3 )
PYTHON_REQ_USE="threads(+)"
inherit distutils-r1 pypi
@@ -33,6 +33,11 @@ distutils_enable_tests pytest
# XXX: handle Babel better?
src_prepare() {
local PATCHES=(
# https://github.com/pallets/jinja/pull/1979
"${FILESDIR}/${P}-py313.patch"
)
# avoid unnecessary dep on extra sphinxcontrib modules
sed -i '/sphinxcontrib.log_cabinet/ d' docs/conf.py || die