diff --git a/autobahn/xbr/_abi.py b/autobahn/xbr/_abi.py index 513a40f61..e2e861aa4 100644 --- a/autobahn/xbr/_abi.py +++ b/autobahn/xbr/_abi.py @@ -27,7 +27,7 @@ import os import json import binascii -import pkg_resources +import importlib.resources os.environ['ETH_HASH_BACKEND'] = 'pycryptodome' @@ -128,7 +128,7 @@ def _load_json(contract_name): - fn = pkg_resources.resource_filename('xbr', 'abi/{}.json'.format(contract_name)) + fn = importlib.resources.files('xbr.abi') / f'{contract_name}.json' with open(fn) as f: data = json.loads(f.read()) return data @@ -137,12 +137,12 @@ def _load_json(contract_name): # # XBR contract ABI file names # -XBR_TOKEN_FN = pkg_resources.resource_filename('xbr', 'abi/XBRToken.json') -XBR_NETWORK_FN = pkg_resources.resource_filename('xbr', 'abi/XBRNetwork.json') -XBR_DOMAIN_FN = pkg_resources.resource_filename('xbr', 'abi/XBRDomain.json') -XBR_CATALOG_FN = pkg_resources.resource_filename('xbr', 'abi/XBRCatalog.json') -XBR_MARKET_FN = pkg_resources.resource_filename('xbr', 'abi/XBRMarket.json') -XBR_CHANNEL_FN = pkg_resources.resource_filename('xbr', 'abi/XBRChannel.json') +XBR_TOKEN_FN = importlib.resources.files('xbr.abi') / 'XBRToken.json' +XBR_NETWORK_FN = importlib.resources.files('xbr.abi') / 'XBRNetwork.json' +XBR_DOMAIN_FN = importlib.resources.files('xbr.abi') / 'XBRDomain.json' +XBR_CATALOG_FN = importlib.resources.files('xbr.abi') / 'XBRCatalog.json' +XBR_MARKET_FN = importlib.resources.files('xbr.abi') / 'XBRMarket.json' +XBR_CHANNEL_FN = importlib.resources.files('xbr.abi') / 'XBRChannel.json' # diff --git a/autobahn/xbr/_cli.py b/autobahn/xbr/_cli.py index 0fcb86930..e35567f4a 100644 --- a/autobahn/xbr/_cli.py +++ b/autobahn/xbr/_cli.py @@ -26,7 +26,7 @@ import os import sys -import pkg_resources +import importlib.resources from jinja2 import Environment, FileSystemLoader @@ -1026,7 +1026,7 @@ def _main(): print(repo.summary(keys=True)) # folder with jinja2 templates for python code sections - templates = pkg_resources.resource_filename('autobahn', 'xbr/templates') + templates = importlib.resources.files('autobahn.xbr') / 'templates' # jinja2 template engine loader and environment loader = FileSystemLoader(templates, encoding='utf-8', followlinks=False) diff --git a/autobahn/xbr/_gui.py b/autobahn/xbr/_gui.py index 6ca565bda..7673a546e 100644 --- a/autobahn/xbr/_gui.py +++ b/autobahn/xbr/_gui.py @@ -28,8 +28,8 @@ import argparse import uuid import binascii +import importlib.resources import random -import pkg_resources from pprint import pprint from time import time_ns @@ -65,7 +65,7 @@ from autobahn.xbr._cli import Client from autobahn.xbr._config import UserConfig, Profile -LOGO_RESOURCE = pkg_resources.resource_filename('autobahn', 'asset/xbr_gray.svg') +LOGO_RESOURCE = importlib.resources.files('autobahn.asset') / 'xbr_gray.svg' print(LOGO_RESOURCE, os.path.isfile(LOGO_RESOURCE)) diff --git a/autobahn/xbr/test/test_xbr_schema_demo.py b/autobahn/xbr/test/test_xbr_schema_demo.py index 13a9419f3..8cbf4d473 100644 --- a/autobahn/xbr/test/test_xbr_schema_demo.py +++ b/autobahn/xbr/test/test_xbr_schema_demo.py @@ -1,6 +1,6 @@ import os import copy -import pkg_resources +import importlib.resources from random import randint, random import txaio from unittest import skipIf @@ -31,7 +31,7 @@ def setUp(self): self.repo = FbsRepository('autobahn') self.archives = [] for fbs_file in ['demo.bfbs', 'wamp-control.bfbs']: - archive = pkg_resources.resource_filename('autobahn', 'xbr/test/catalog/schema/{}'.format(fbs_file)) + archive = importlib.resources.files('autobahn.xbr.test.catalog.schema') / fbs_file self.repo.load(archive) self.archives.append(archive) diff --git a/autobahn/xbr/test/test_xbr_schema_wamp.py b/autobahn/xbr/test/test_xbr_schema_wamp.py index cf15b5040..147e25d81 100644 --- a/autobahn/xbr/test/test_xbr_schema_wamp.py +++ b/autobahn/xbr/test/test_xbr_schema_wamp.py @@ -1,5 +1,5 @@ import os -import pkg_resources +import importlib.resources from binascii import a2b_hex import txaio from unittest import skipIf @@ -78,7 +78,7 @@ def setUp(self): self.repo = FbsRepository('autobahn') self.archives = [] for fbs_file in ['wamp.bfbs', 'testsvc1.bfbs']: - archive = pkg_resources.resource_filename('autobahn', 'xbr/test/catalog/schema/{}'.format(fbs_file)) + archive = importlib.resources.files('autobahn.xbr.test.catalog.schema') / fbs_file self.repo.load(archive) self.archives.append(archive) @@ -99,7 +99,7 @@ def test_create_from_archive(self): self.assertIsInstance(self.repo.services['testsvc1.ITestService1'], FbsService) def test_loaded_schema(self): - schema_fn = pkg_resources.resource_filename('autobahn', 'xbr/test/catalog/schema/testsvc1.bfbs') + schema_fn = importlib.resources.files('autobahn.xbr.test.catalog.schema') / 'testsvc1.bfbs' # get reflection schema loaded schema: FbsSchema = self.repo.schemas[schema_fn] diff --git a/autobahn/xbr/test/test_xbr_schema_wamp_control.py b/autobahn/xbr/test/test_xbr_schema_wamp_control.py index 948b503bb..f4c4b09bb 100644 --- a/autobahn/xbr/test/test_xbr_schema_wamp_control.py +++ b/autobahn/xbr/test/test_xbr_schema_wamp_control.py @@ -1,6 +1,6 @@ import os import copy -import pkg_resources +import importlib.resources import txaio from unittest import skipIf @@ -30,7 +30,7 @@ def setUp(self): self.repo = FbsRepository('autobahn') self.archives = [] for fbs_file in ['wamp-control.bfbs']: - archive = pkg_resources.resource_filename('autobahn', 'xbr/test/catalog/schema/{}'.format(fbs_file)) + archive = importlib.resources.files('autobahn.xbr.test.catalog.schema') / fbs_file self.repo.load(archive) self.archives.append(archive) diff --git a/autobahn/xbr/test/test_xbr_secmod.py b/autobahn/xbr/test/test_xbr_secmod.py index 0676e3804..4176f8046 100644 --- a/autobahn/xbr/test/test_xbr_secmod.py +++ b/autobahn/xbr/test/test_xbr_secmod.py @@ -26,7 +26,7 @@ import os import sys -import pkg_resources +import importlib.resources from random import randint, random from binascii import a2b_hex from typing import List @@ -418,7 +418,7 @@ def test_secmod_from_seedphrase(self): @inlineCallbacks def test_secmod_from_config(self): - config = pkg_resources.resource_filename('autobahn', 'xbr/test/profile/config.ini') + config = importlib.resources.files('autobahn.xbr.test.profile') / 'config.ini' sm = SecurityModuleMemory.from_config(config) yield sm.open() @@ -439,7 +439,7 @@ def test_secmod_from_config(self): @inlineCallbacks def test_secmod_from_keyfile(self): - keyfile = pkg_resources.resource_filename('autobahn', 'xbr/test/profile/default.priv') + keyfile = importlib.resources.files('autobahn.xbr.test.profile') / 'default.priv' sm = SecurityModuleMemory.from_keyfile(keyfile) yield sm.open() diff --git a/docker/print-versions.py b/docker/print-versions.py index 9ae0262b3..d0d5c10ff 100644 --- a/docker/print-versions.py +++ b/docker/print-versions.py @@ -2,7 +2,7 @@ import sys import platform import importlib -import pkg_resources +import importlib.metadata import txaio txaio.use_twisted() # noqa @@ -28,7 +28,7 @@ def _get_version(name_or_module): v = name_or_module.version else: try: - v = pkg_resources.get_distribution(name_or_module.__name__).version + v = importlib.metadata.version(name_or_module.__name__) except: # eg flatbuffers when run from single file EXE (pyinstaller): https://github.com/google/flatbuffers/issues/5299 v = '?.?.?' diff --git a/docs/xbr.rst b/docs/xbr.rst index 72a4d4849..9564bf09f 100644 --- a/docs/xbr.rst +++ b/docs/xbr.rst @@ -95,13 +95,13 @@ To directly use the embedded ABI files: .. code-block:: python import json - import pkg_resources + import importlib.resources from pprint import pprint - with open(pkg_resources.resource_filename('xbr', 'contracts/XBRToken.json')) as f: - data = json.loads(f.read()) - abi = data['abi'] - pprint(abi) + text = (importlib.resources.files('xbr.abi') / 'XBRToken.json').read_text() + data = json.loads(text) + abi = data['abi'] + pprint(abi) Data stored on-chain diff --git a/setup.py b/setup.py index c2a463295..7752e7b28 100644 --- a/setup.py +++ b/setup.py @@ -235,7 +235,6 @@ 'txaio>=21.2.1', # MIT license (https://github.com/crossbario/txaio) 'cryptography>=3.4.6', # BSD *or* Apache license (https://github.com/pyca/cryptography) 'hyperlink>=21.0.0', # MIT license (https://github.com/python-hyper/hyperlink) - 'setuptools', # MIT license (https://github.com/pypa/setuptools) ], extras_require={ 'all': extras_require_all,