Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate away from deprecated pkg_resources #1533

Merged
merged 1 commit into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pyocd/core/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pyOCD debugger
# Copyright (c) 2020 Arm Limited
# Copyright (c) 2021 Chris Reed
# Copyright (c) 2021-2023 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -15,8 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pkg_resources
import logging
from importlib_metadata import entry_points
from typing import (
Any,
Dict,
Expand Down Expand Up @@ -92,7 +92,7 @@ class must be derived from `base_class`.
@param plugin_dict Dictionary to fill with loaded plugin classes.
@param base_class The required superclass for plugin implementation classes.
"""
for entry_point in pkg_resources.iter_entry_points(plugin_group):
for entry_point in entry_points(group=plugin_group):
# Instantiate the plugin class.
plugin = entry_point.load()()
if not isinstance(plugin, Plugin):
Expand Down
7 changes: 4 additions & 3 deletions pyocd/debug/svd/loader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pyOCD debugger
# Copyright (c) 2015-2020 Arm Limited
# Copyright (c) 2021 Chris Reed
# Copyright (c) 2021-2023 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,7 +17,7 @@

import threading
import logging
import pkg_resources
import importlib_resources
import zipfile

from .parser import SVDParser
Expand All @@ -31,7 +31,8 @@ class SVDFile(object):
@classmethod
def from_builtin(cls, svd_name):
try:
zip_stream = pkg_resources.resource_stream("pyocd", BUILTIN_SVD_DATA_PATH)
zip_ref = importlib_resources.files("pyocd").joinpath(BUILTIN_SVD_DATA_PATH)
zip_stream = zip_ref.open('rb')
zip = zipfile.ZipFile(zip_stream, 'r')
return SVDFile(zip.open(svd_name))
except (KeyError, FileNotFoundError, zipfile.BadZipFile) as err:
Expand Down
6 changes: 3 additions & 3 deletions pyocd/tools/lists.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pyOCD debugger
# Copyright (c) 2018-2020 Arm Limited
# Copyright (c) 2021-2022 Chris Reed
# Copyright (c) 2021-2023 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,7 +16,7 @@
# limitations under the License.

import os
import pkg_resources
from importlib_metadata import entry_points

from .. import __version__
from ..core.session import Session
Expand Down Expand Up @@ -235,7 +235,7 @@ def list_plugins():
'plugins': plugin_list,
}

for entry_point in pkg_resources.iter_entry_points(group_name):
for entry_point in entry_points(group=group_name):
klass = entry_point.load()
plugin = klass()
info = {
Expand Down
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ include_package_data = True
packages = find:
python_requires = >=3.7.0
# Use hidapi on macOS and Windows, not needed on Linux.
#
# importlib_resources is used instead of stdlib importlib.resources because we
# want the selectable entry_points API, which is not present until Python 3.10.
install_requires =
capstone>=4.0,<5.0
cmsis-pack-manager>=0.5.2,<1.0
colorama<1.0
hidapi>=0.10.1,<1.0; platform_system != "Linux"
importlib_metadata>=3.6
importlib_resources
intelhex>=2.0,<3.0
intervaltree>=3.0.2,<4.0
libusb-package>=1.0,<2.0
Expand Down
34 changes: 34 additions & 0 deletions test/unit/test_svd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# pyOCD debugger
# Copyright (c) 2023 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from pyocd.debug.svd.loader import (
SVDFile,
SVDLoader,
)

class TestIntervalSvdAccess:
def builtin_svd(self, name: str) -> SVDLoader:
def completion(dev):
pass
loader = SVDLoader(SVDFile.from_builtin(name), completion)
loader.run()
return loader

def test_load(self):
loader = self.builtin_svd('Musca_B1.svd')
assert loader.device
assert [p for p in loader.device.peripherals if p.name == 'UART0']