Skip to content

Commit 8af3942

Browse files
committed
cmdebug: LoadSVD: Use importlib_resources
This addresses the following warning: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
1 parent ce37150 commit 8af3942

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

cmdebug/svd_gdb.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import math
2121
import sys
2222
import struct
23-
import pkg_resources
23+
import importlib_resources
2424

2525
sys.path.append('.')
2626
from cmdebug.svd import SVDFile
@@ -40,10 +40,10 @@ class LoadSVD(gdb.Command):
4040
def __init__(self):
4141
self.vendors = {}
4242
try:
43-
vendor_names = pkg_resources.resource_listdir("cmsis_svd", "data")
44-
for vendor in vendor_names:
45-
fnames = pkg_resources.resource_listdir("cmsis_svd", "data/{}".format(vendor))
46-
self.vendors[vendor] = [fname for fname in fnames if fname.lower().endswith(".svd")]
43+
for vendor_path in importlib_resources.files("cmsis_svd.data").iterdir():
44+
vendor =vendor_path.name
45+
files = importlib_resources.files(f"cmsis_svd.data.{vendor}").iterdir()
46+
self.vendors[vendor] = [file.name for file in files if file.name.lower().endswith(".svd")]
4747
except:
4848
pass
4949

@@ -80,7 +80,7 @@ def invoke(args, from_tty):
8080
f = args[0]
8181
elif argc == 2:
8282
gdb.write("Loading SVD file {}/{}...\n".format(args[0], args[1]))
83-
f = pkg_resources.resource_filename("cmsis_svd", "data/{}/{}".format(args[0], args[1]))
83+
f = str(importlib_resources.files("cmsis_svd.data") / f"{args[0]}" / f"{args[1]}")
8484
else:
8585
raise gdb.GdbError("Usage: svd_load <vendor> <device.svd> or svd_load <path/to/filename.svd>\n")
8686
try:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
keywords='arm gdb cortex cortex-m svd trace microcontroller',
2828
license='GPL',
2929
install_requires=[
30-
'setuptools',
30+
'importlib-resources',
3131
'lxml',
3232
],
3333
)

0 commit comments

Comments
 (0)