File: drop-pkg-resources.patch

package info (click to toggle)
python-pybadges 3.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 576 kB
  • sloc: python: 864; sh: 13; makefile: 4
file content (83 lines) | stat: -rw-r--r-- 3,467 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
From: Colin Watson <cjwatson@debian.org>
Date: Mon, 9 Feb 2026 01:37:24 +0000
Subject: Port from pkg_resources to importlib.resources

Bug-Debian: https://bugs.debian.org/1125851
Last-Update: 2026-02-09
---
 build_golden_images.py                  |  8 +++-----
 pybadges/precalculated_text_measurer.py | 14 +++++++-------
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/build_golden_images.py b/build_golden_images.py
index 7ed730d..b59ce72 100644
--- a/build_golden_images.py
+++ b/build_golden_images.py
@@ -15,10 +15,10 @@
 # limitations under the License.
 
 import argparse
+import importlib.resources
 import json
 import os
 import os.path
-import pkg_resources
 
 import pybadges
 from tests import image_server
@@ -48,14 +48,12 @@ def main():
 
     parser.add_argument(
         '--source-path',
-        default=pkg_resources.resource_filename(__name__,
-                                                'tests/test-badges.json'),
+        default=importlib.resources.files(__name__) / 'tests/test-badges.json',
         help='the text to show on the left-hand-side of the badge')
 
     parser.add_argument(
         '--destination-dir',
-        default=pkg_resources.resource_filename(__name__,
-                                                'tests/golden-images'),
+        default=importlib.resources.files(__name__) / 'tests/golden-images',
         help='the text to show on the left-hand-side of the badge')
     args = parser.parse_args()
     generate_images(args.source_path, args.destination_dir)
diff --git a/pybadges/precalculated_text_measurer.py b/pybadges/precalculated_text_measurer.py
index 6e769af..82ac014 100644
--- a/pybadges/precalculated_text_measurer.py
+++ b/pybadges/precalculated_text_measurer.py
@@ -16,9 +16,9 @@
 Uses a precalculated set of metrics to calculate the string length.
 """
 
+import importlib.resources
 import io
 import json
-import pkg_resources
 from typing import cast, Mapping, TextIO, Type
 
 from pybadges import text_measurer
@@ -74,17 +74,17 @@ class PrecalculatedTextMeasurer(text_measurer.TextMeasurer):
         if cls._default_cache is not None:
             return cls._default_cache
 
-        if pkg_resources.resource_exists(__name__, 'default-widths.json.xz'):
+        if importlib.resources.is_resource(__name__, 'default-widths.json.xz'):
             import lzma
-            with pkg_resources.resource_stream(__name__,
-                                               'default-widths.json.xz') as f:
+            with importlib.resources.open_binary(__name__,
+                                                 'default-widths.json.xz') as f:
                 with lzma.open(f, "rt") as g:
                     cls._default_cache = PrecalculatedTextMeasurer.from_json(
                         cast(TextIO, g))
                     return cls._default_cache
-        elif pkg_resources.resource_exists(__name__, 'default-widths.json'):
-            with pkg_resources.resource_stream(__name__,
-                                               'default-widths.json') as f:
+        elif importlib.resources.is_resource(__name__, 'default-widths.json'):
+            with importlib.resources.open_binary(__name__,
+                                                 'default-widths.json') as f:
                 cls._default_cache = PrecalculatedTextMeasurer.from_json(
                     io.TextIOWrapper(f, encoding='utf-8'))
                 return cls._default_cache