1(Patch from https://lists.denx.de/pipermail/u-boot/2024-July/559077.html)
2
3
4pkg_resources is deprecated long ago and being removed in python 3.12.
5
6Reimplement functions with importlib.resources.
7
8Link: https://docs.python.org/3/library/importlib.resources.html
9Signed-off-by: Jiaxun Yang <jiaxun.yang at flygoat.com>
10---
11 tools/binman/control.py | 18 +++++++++---------
12 1 file changed, 9 insertions(+), 9 deletions(-)
13
14diff --git a/tools/binman/control.py b/tools/binman/control.py
15index 2f00279232b8..5549b0ad2185 100644
16--- a/tools/binman/control.py
17+++ b/tools/binman/control.py
18@@ -8,12 +8,11 @@
19 from collections import OrderedDict
20 import glob
21 try:
22- import importlib.resources
23-except ImportError: # pragma: no cover
24+ from importlib import resources
25+except ImportError:
26 # for Python 3.6
27- import importlib_resources
28+ import importlib_resources as resources
29 import os
30-import pkg_resources
31 import re
32
33 import sys
34@@ -96,12 +95,12 @@ def _ReadMissingBlobHelp():
35 msg = ''
36 return tag, msg
37
38- my_data = pkg_resources.resource_string(__name__, 'missing-blob-help')
39+ my_data = resources.files(__package__).joinpath('missing-blob-help').read_text()
40 re_tag = re.compile('^([-a-z0-9]+):$')
41 result = {}
42 tag = None
43 msg = ''
44- for line in my_data.decode('utf-8').splitlines():
45+ for line in my_data.splitlines():
46 if not line.startswith('#'):
47 m_tag = re_tag.match(line)
48 if m_tag:
49@@ -151,8 +150,9 @@ def GetEntryModules(include_testing=True):
50 Returns:
51 Set of paths to entry class filenames
52 """
53- glob_list = pkg_resources.resource_listdir(__name__, 'etype')
54- glob_list = [fname for fname in glob_list if fname.endswith('.py')]
55+ directory = resources.files("binman.etype")
56+ glob_list = [entry.name for entry in directory.iterdir()
57+ if entry.name.endswith('.py')]
58 return set([os.path.splitext(os.path.basename(item))[0]
59 for item in glob_list
60 if include_testing or '_testing' not in item])
61@@ -735,7 +735,7 @@ def Binman(args):
62 global state
63
64 if args.full_help:
65- with importlib.resources.path('binman', 'README.rst') as readme:
66+ with resources.path('binman', 'README.rst') as readme:
67 tools.print_full_help(str(readme))
68 return 0
69
70
71--
722.45.2