mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2026-06-13 15:03:58 +03:00
binman: migrate from pkg_resources to importlib
pkg_resources is deprecated, use migration guide in [1] to migrate to importlib.resources. Keep the Python 3.6 backwards compatibility. This also fixes the binman version test which failed for setuptools versions that print the deprecation warning. Change from __name__ to __package__ as with the transition from pkg_resources to importlib_resources using __name__ results in TypeErrors [2]. [1] https://importlib-resources.readthedocs.io/en/latest/migration.html [2] https://github.com/python/importlib_resources/issues/60 Reviewed-by: Bryan Brattlof <bb@ti.com> Signed-off-by: Yannic Moog <y.moog@phytec.de>
This commit is contained in:
@@ -8,12 +8,11 @@
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
import glob
|
import glob
|
||||||
try:
|
try:
|
||||||
import importlib.resources
|
import importlib.resources as importlib_resources
|
||||||
except ImportError: # pragma: no cover
|
except ImportError: # pragma: no cover
|
||||||
# for Python 3.6
|
# for Python 3.6
|
||||||
import importlib_resources
|
import importlib_resources
|
||||||
import os
|
import os
|
||||||
import pkg_resources
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@@ -96,7 +95,7 @@ def _ReadMissingBlobHelp():
|
|||||||
msg = ''
|
msg = ''
|
||||||
return tag, msg
|
return tag, msg
|
||||||
|
|
||||||
my_data = pkg_resources.resource_string(__name__, 'missing-blob-help')
|
my_data = importlib_resources.files(__package__).joinpath('missing-blob-help').read_bytes()
|
||||||
re_tag = re.compile(r"^([-\.a-z0-9]+):$")
|
re_tag = re.compile(r"^([-\.a-z0-9]+):$")
|
||||||
result = {}
|
result = {}
|
||||||
tag = None
|
tag = None
|
||||||
@@ -151,8 +150,9 @@ def GetEntryModules(include_testing=True):
|
|||||||
Returns:
|
Returns:
|
||||||
Set of paths to entry class filenames
|
Set of paths to entry class filenames
|
||||||
"""
|
"""
|
||||||
glob_list = pkg_resources.resource_listdir(__name__, 'etype')
|
entries = importlib_resources.files(__package__).joinpath('etype')
|
||||||
glob_list = [fname for fname in glob_list if fname.endswith('.py')]
|
glob_list = [entry.name for entry in entries.iterdir()
|
||||||
|
if entry.name.endswith('.py') and entry.is_file()]
|
||||||
return set([os.path.splitext(os.path.basename(item))[0]
|
return set([os.path.splitext(os.path.basename(item))[0]
|
||||||
for item in glob_list
|
for item in glob_list
|
||||||
if include_testing or '_testing' not in item])
|
if include_testing or '_testing' not in item])
|
||||||
@@ -831,7 +831,7 @@ def Binman(args):
|
|||||||
global state
|
global state
|
||||||
|
|
||||||
if args.full_help:
|
if args.full_help:
|
||||||
with importlib.resources.path('binman', 'README.rst') as readme:
|
with importlib_resources.path('binman', 'README.rst') as readme:
|
||||||
tools.print_full_help(str(readme))
|
tools.print_full_help(str(readme))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user