Skip to content

Commit 79d92d9

Browse files
committed
remove setuptools dependency
replace deprecated pkg_resources methods with importlib.resources and importlib.metadata
1 parent 7bc85b3 commit 79d92d9

10 files changed

+29
-30
lines changed

autobahn/xbr/_abi.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import os
2828
import json
2929
import binascii
30-
import pkg_resources
30+
import importlib.resources
3131

3232
os.environ['ETH_HASH_BACKEND'] = 'pycryptodome'
3333

@@ -128,7 +128,7 @@
128128

129129

130130
def _load_json(contract_name):
131-
fn = pkg_resources.resource_filename('xbr', 'abi/{}.json'.format(contract_name))
131+
fn = importlib.resources.files('xbr.abi') / f'{contract_name}.json'
132132
with open(fn) as f:
133133
data = json.loads(f.read())
134134
return data
@@ -137,12 +137,12 @@ def _load_json(contract_name):
137137
#
138138
# XBR contract ABI file names
139139
#
140-
XBR_TOKEN_FN = pkg_resources.resource_filename('xbr', 'abi/XBRToken.json')
141-
XBR_NETWORK_FN = pkg_resources.resource_filename('xbr', 'abi/XBRNetwork.json')
142-
XBR_DOMAIN_FN = pkg_resources.resource_filename('xbr', 'abi/XBRDomain.json')
143-
XBR_CATALOG_FN = pkg_resources.resource_filename('xbr', 'abi/XBRCatalog.json')
144-
XBR_MARKET_FN = pkg_resources.resource_filename('xbr', 'abi/XBRMarket.json')
145-
XBR_CHANNEL_FN = pkg_resources.resource_filename('xbr', 'abi/XBRChannel.json')
140+
XBR_TOKEN_FN = importlib.resources.files('xbr.abi') / 'XBRToken.json')
141+
XBR_NETWORK_FN = importlib.resources.files('xbr.abi') / 'XBRNetwork.json')
142+
XBR_DOMAIN_FN = importlib.resources.files('xbr.abi') / 'XBRDomain.json')
143+
XBR_CATALOG_FN = importlib.resources.files('xbr.abi') / 'XBRCatalog.json')
144+
XBR_MARKET_FN = importlib.resources.files('xbr.abi') / 'XBRMarket.json')
145+
XBR_CHANNEL_FN = importlib.resources.files('xbr.abi') / 'XBRChannel.json')
146146

147147

148148
#

autobahn/xbr/_cli.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import os
2828
import sys
29-
import pkg_resources
29+
import importlib.resources
3030

3131
from jinja2 import Environment, FileSystemLoader
3232

@@ -1026,7 +1026,7 @@ def _main():
10261026
print(repo.summary(keys=True))
10271027

10281028
# folder with jinja2 templates for python code sections
1029-
templates = pkg_resources.resource_filename('autobahn', 'xbr/templates')
1029+
templates = importlib_resources.files('autobahn.xbr.templates')
10301030

10311031
# jinja2 template engine loader and environment
10321032
loader = FileSystemLoader(templates, encoding='utf-8', followlinks=False)

autobahn/xbr/_gui.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import argparse
2929
import uuid
3030
import binascii
31+
import importlib.resources
3132
import random
32-
import pkg_resources
3333
from pprint import pprint
3434
from time import time_ns
3535

@@ -65,7 +65,7 @@
6565
from autobahn.xbr._cli import Client
6666
from autobahn.xbr._config import UserConfig, Profile
6767

68-
LOGO_RESOURCE = pkg_resources.resource_filename('autobahn', 'asset/xbr_gray.svg')
68+
LOGO_RESOURCE = importlib.resources.files('autobahn.asset') / 'xbr_gray.svg'
6969
print(LOGO_RESOURCE, os.path.isfile(LOGO_RESOURCE))
7070

7171

autobahn/xbr/test/test_xbr_schema_demo.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import copy
3-
import pkg_resources
3+
import importlib.resources
44
from random import randint, random
55
import txaio
66
from unittest import skipIf
@@ -31,7 +31,7 @@ def setUp(self):
3131
self.repo = FbsRepository('autobahn')
3232
self.archives = []
3333
for fbs_file in ['demo.bfbs', 'wamp-control.bfbs']:
34-
archive = pkg_resources.resource_filename('autobahn', 'xbr/test/catalog/schema/{}'.format(fbs_file))
34+
archive = importlib.resources.files('autobahn.xbr.test.catalog.schema') / fbs_file
3535
self.repo.load(archive)
3636
self.archives.append(archive)
3737

autobahn/xbr/test/test_xbr_schema_wamp.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
import pkg_resources
2+
import importlib.resources
33
from binascii import a2b_hex
44
import txaio
55
from unittest import skipIf
@@ -78,7 +78,7 @@ def setUp(self):
7878
self.repo = FbsRepository('autobahn')
7979
self.archives = []
8080
for fbs_file in ['wamp.bfbs', 'testsvc1.bfbs']:
81-
archive = pkg_resources.resource_filename('autobahn', 'xbr/test/catalog/schema/{}'.format(fbs_file))
81+
archive = importlib.resources.files('autobahn.xbr.test.catalog.schema') / fbs_file
8282
self.repo.load(archive)
8383
self.archives.append(archive)
8484

@@ -99,7 +99,7 @@ def test_create_from_archive(self):
9999
self.assertIsInstance(self.repo.services['testsvc1.ITestService1'], FbsService)
100100

101101
def test_loaded_schema(self):
102-
schema_fn = pkg_resources.resource_filename('autobahn', 'xbr/test/catalog/schema/testsvc1.bfbs')
102+
schema_fn = importlib.resources.files('autobahn.xbr.test.catalog.schema') / 'testsvc1.bfbs'
103103

104104
# get reflection schema loaded
105105
schema: FbsSchema = self.repo.schemas[schema_fn]

autobahn/xbr/test/test_xbr_schema_wamp_control.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import copy
3-
import pkg_resources
3+
import importlib.resources
44
import txaio
55
from unittest import skipIf
66

@@ -30,7 +30,7 @@ def setUp(self):
3030
self.repo = FbsRepository('autobahn')
3131
self.archives = []
3232
for fbs_file in ['wamp-control.bfbs']:
33-
archive = pkg_resources.resource_filename('autobahn', 'xbr/test/catalog/schema/{}'.format(fbs_file))
33+
archive = importlib.resources.files('autobahn.xbr.test.catalog.schema') / fbs_file
3434
self.repo.load(archive)
3535
self.archives.append(archive)
3636

autobahn/xbr/test/test_xbr_secmod.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import os
2828
import sys
29-
import pkg_resources
29+
import importlib.resources
3030
from random import randint, random
3131
from binascii import a2b_hex
3232
from typing import List
@@ -418,7 +418,7 @@ def test_secmod_from_seedphrase(self):
418418

419419
@inlineCallbacks
420420
def test_secmod_from_config(self):
421-
config = pkg_resources.resource_filename('autobahn', 'xbr/test/profile/config.ini')
421+
config = importlib.resources.files('autobahn.xbr.test.profile') / 'config.ini'
422422

423423
sm = SecurityModuleMemory.from_config(config)
424424
yield sm.open()
@@ -439,7 +439,7 @@ def test_secmod_from_config(self):
439439

440440
@inlineCallbacks
441441
def test_secmod_from_keyfile(self):
442-
keyfile = pkg_resources.resource_filename('autobahn', 'xbr/test/profile/default.priv')
442+
keyfile = importlib.resources.files('autobahn.xbr.test.profile') / 'default.priv'
443443

444444
sm = SecurityModuleMemory.from_keyfile(keyfile)
445445
yield sm.open()

docker/print-versions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33
import platform
44
import importlib
5-
import pkg_resources
5+
import importlib.metadata
66

77
import txaio
88
txaio.use_twisted() # noqa
@@ -28,7 +28,7 @@ def _get_version(name_or_module):
2828
v = name_or_module.version
2929
else:
3030
try:
31-
v = pkg_resources.get_distribution(name_or_module.__name__).version
31+
v = importlib.metadata.version(name_or_module.__name__)
3232
except:
3333
# eg flatbuffers when run from single file EXE (pyinstaller): https://github.com/google/flatbuffers/issues/5299
3434
v = '?.?.?'

docs/xbr.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ To directly use the embedded ABI files:
9595
.. code-block:: python
9696
9797
import json
98-
import pkg_resources
98+
import importlib.resources
9999
from pprint import pprint
100100
101-
with open(pkg_resources.resource_filename('xbr', 'contracts/XBRToken.json')) as f:
102-
data = json.loads(f.read())
103-
abi = data['abi']
104-
pprint(abi)
101+
text = (importlib.resources.files('xbr.abi') / 'XBRToken.json').read_text()
102+
data = json.loads(text)
103+
abi = data['abi']
104+
pprint(abi)
105105
106106
107107
Data stored on-chain

setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@
235235
'txaio>=21.2.1', # MIT license (https://github.com/crossbario/txaio)
236236
'cryptography>=3.4.6', # BSD *or* Apache license (https://github.com/pyca/cryptography)
237237
'hyperlink>=21.0.0', # MIT license (https://github.com/python-hyper/hyperlink)
238-
'setuptools', # MIT license (https://github.com/pypa/setuptools)
239238
],
240239
extras_require={
241240
'all': extras_require_all,

0 commit comments

Comments
 (0)