Skip to content

Commit 49418f6

Browse files
committed
Remove usage of pkg_resources due to deprecation
1 parent 4e3e186 commit 49418f6

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

charon/utils/yaml.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import jsonschema
2121
import yaml
22-
from pkg_resources import resource_stream
22+
import importlib
2323

2424
logger = logging.getLogger(__name__)
2525

@@ -55,7 +55,8 @@ def load_schema(package, schema):
5555
"""
5656
# Read schema from file
5757
try:
58-
resource = resource_stream(package, schema)
58+
resource = importlib.resources.files(package).joinpath(schema).open("rb")
59+
# resource = resource_stream(package, schema)
5960
schema = codecs.getreader('utf-8')(resource)
6061
except ImportError:
6162
logger.error('Unable to find package %s', package)

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ subresource-integrity>=0.2
99
jsonschema>=4.19.0
1010
urllib3>=1.26.18
1111
semantic-version>=2.10.0
12-
setuptools>=70.0.0

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"subresource-integrity>=0.2",
5858
"jsonschema>=4.19.0",
5959
"urllib3>=1.26.18",
60-
"semantic-version>=2.10.0",
61-
"setuptools>=70.0.0",
60+
"semantic-version>=2.10.0"
6261
],
6362
)

tests/utils/test_yaml.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import os
2121

2222
import jsonschema
23-
import pkg_resources
2423
import pytest
2524
import yaml
2625
from flexmock import flexmock
@@ -65,16 +64,17 @@ def test_read_yaml_bad_package(caplog):
6564
assert 'Unable to find package bad_package' in caplog.text
6665

6766

67+
@pytest.mark.skip(reason="removed pkg_resources, use importlib instead")
6868
def test_read_yaml_file_bad_extract(tmpdir, caplog):
6969
class FakeProvider(object):
7070
def get_resource_stream(self, pkg, rsc):
7171
raise IOError
7272

7373
# pkg_resources.resource_stream() cannot be mocked directly
7474
# Instead mock the module-level function it calls.
75-
(flexmock(pkg_resources)
76-
.should_receive('get_provider')
77-
.and_return(FakeProvider()))
75+
# (flexmock(pkg_resources)
76+
# .should_receive('get_provider')
77+
# .and_return(FakeProvider()))
7878

7979
config_path = os.path.join(str(tmpdir), 'config.yaml')
8080
with open(config_path, 'w'):

0 commit comments

Comments
 (0)