File: importlib-metadata.patch

package info (click to toggle)
beaker 1.13.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 716 kB
  • sloc: python: 6,036; makefile: 62
file content (114 lines) | stat: -rw-r--r-- 4,824 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
From: Wolfgang Schnerring <wosc@wosc.de>
Date: Wed, 3 Dec 2025 19:25:50 +0100
Subject: Load entry points with importlib.metadata instead of deprecated
 pkg_resources (#249)

* Select exception class via `except Type:` instead of manual `isinstance`

* Load entry points with importlib.metadata instead of deprecated pkg_resources

I'm not sure in which circumstance DistributionNotFound may have been
raised here previously, why it has been desireable to suppress that,
and what the current machinery would raise instead, but if in doubt
I'd rather have a warning than things silently not working.

* Remove pkg_resources import guard, importlib is part of the stdlib, so always present

* Remove long-obsolete python-2 compatibility code

It especially makes no sense now anymore, since importlib is python-3 only.

* Use importlib.metatdata API that's backward-compatible with Python<3.10

Origin: backport, https://github.com/bbangert/beaker/commit/96283fe89240040bf979e8555ba73571876e837c
Bug-Debian: https://bugs.debian.org/1125832
Last-Update: 2026-01-25
---
 beaker/cache.py | 66 ++++++++++++++++++++++++++-------------------------------
 1 file changed, 30 insertions(+), 36 deletions(-)

diff --git a/beaker/cache.py b/beaker/cache.py
index 61b8e4e..03987b1 100644
--- a/beaker/cache.py
+++ b/beaker/cache.py
@@ -6,7 +6,11 @@ as well as the function decorators :func:`.region_decorate`,
 :func:`.region_invalidate`.
 
 """
+import importlib.metadata
+import sys
+import traceback
 import warnings
+from io import StringIO
 from itertools import chain
 
 from beaker._compat import u_, unicode_text, func_signature, bindfuncargs
@@ -80,42 +84,32 @@ class _backends(object):
             raise e
 
     def _init(self):
-        try:
-            import pkg_resources
-
-            # Load up the additional entry point defined backends
-            for entry_point in pkg_resources.iter_entry_points('beaker.backends'):
-                try:
-                    namespace_manager = entry_point.load()
-                    name = entry_point.name
-                    if name in self._clsmap:
-                        raise BeakerException("NamespaceManager name conflict,'%s' "
-                                              "already loaded" % name)
-                    self._clsmap[name] = namespace_manager
-                except (InvalidCacheBackendError, SyntaxError):
-                    # Ignore invalid backends
-                    pass
-                except:
-                    import sys
-                    from pkg_resources import DistributionNotFound
-                    # Warn when there's a problem loading a NamespaceManager
-                    if not isinstance(sys.exc_info()[1], DistributionNotFound):
-                        import traceback
-                        try:
-                            from StringIO import StringIO  # Python2
-                        except ImportError:
-                            from io import StringIO        # Python3
-
-                        tb = StringIO()
-                        traceback.print_exc(file=tb)
-                        warnings.warn(
-                            "Unable to load NamespaceManager "
-                            "entry point: '%s': %s" % (
-                                        entry_point,
-                                        tb.getvalue()),
-                                        RuntimeWarning, 2)
-        except ImportError:
-            pass
+        # Load up the additional entry point defined backends
+        if sys.version_info < (3, 10):
+            entry_points = importlib.metadata.entry_points()['beaker.backends']
+        else:
+            entry_points = importlib.metadata.entry_points(group='beaker.backends')
+        for entry_point in entry_points:
+            try:
+                namespace_manager = entry_point.load()
+                name = entry_point.name
+                if name in self._clsmap:
+                    raise BeakerException("NamespaceManager name conflict,'%s' "
+                                          "already loaded" % name)
+                self._clsmap[name] = namespace_manager
+            except (InvalidCacheBackendError, SyntaxError):
+                # Ignore invalid backends
+                pass
+            except Exception:
+                # Warn when there's a problem loading a NamespaceManager
+                tb = StringIO()
+                traceback.print_exc(file=tb)
+                warnings.warn(
+                    "Unable to load NamespaceManager "
+                    "entry point: '%s': %s" % (
+                                entry_point,
+                                tb.getvalue()),
+                                RuntimeWarning, 2)
 
 # Initialize the basic available backends
 clsmap = _backends({