From c401c7589a4ff0175e38fde353b226e5fa84286f Mon Sep 17 00:00:00 2001 From: Emiel Por Date: Tue, 15 Oct 2024 22:16:35 -0700 Subject: [PATCH] Use importlib_metadata if importlib.metadata is not available. --- catkit2/testbed/service_proxy.py | 8 ++++++-- catkit2/testbed/testbed.py | 7 ++++++- environment.yml | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/catkit2/testbed/service_proxy.py b/catkit2/testbed/service_proxy.py index d3b1fd07..3df5626e 100644 --- a/catkit2/testbed/service_proxy.py +++ b/catkit2/testbed/service_proxy.py @@ -1,6 +1,10 @@ from .. import catkit_bindings -import importlib.metadata +try: + import importlib.metadata as importlib_metadata +except ImportError: + import importlib_metadata + class ServiceProxy(catkit_bindings.ServiceProxy): '''A proxy for a service connected to a server. @@ -103,7 +107,7 @@ def get_service_interface(cls, interface_name): if interface_name is None: return ServiceProxy - entry_point = importlib.metadata.entry_points(group='catkit2.proxies', name=interface_name) + entry_point = importlib_metadata.entry_points(group='catkit2.proxies', name=interface_name) if not entry_point: raise AttributeError(f"Service proxy class with interface name '{interface_name}' not found. Did you set it as an entry point?") diff --git a/catkit2/testbed/testbed.py b/catkit2/testbed/testbed.py index 2ed89f46..cb4f1de1 100644 --- a/catkit2/testbed/testbed.py +++ b/catkit2/testbed/testbed.py @@ -19,6 +19,11 @@ from ..proto import testbed_pb2 as testbed_proto from ..proto import service_pb2 as service_proto +try: + import importlib.metadata as importlib_metadata +except ImportError: + import importlib_metadata + SERVICE_LIVELINESS = 5 @@ -273,7 +278,7 @@ def __init__(self, port, is_simulated, config): # Read in service types. self.service_type_paths = {} - for entry_point in importlib.metadata.entry_points(group="catkit2.services"): + for entry_point in importlib_metadata.entry_points(group="catkit2.services"): module = entry_point.module spec = importlib.util.find_spec(module) path = os.path.abspath(spec.origin) diff --git a/environment.yml b/environment.yml index c15841e3..0342dc08 100644 --- a/environment.yml +++ b/environment.yml @@ -37,6 +37,7 @@ dependencies: - networkx - pytest - flake8 + - importlib_metadata - pip: - dcps - zwoasi>=0.0.21