Skip to content

Commit

Permalink
Use importlib_metadata if importlib.metadata is not available.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehpor committed Oct 16, 2024
1 parent 7f75832 commit c401c75
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions catkit2/testbed/service_proxy.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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?")
Expand Down
7 changes: 6 additions & 1 deletion catkit2/testbed/testbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies:
- networkx
- pytest
- flake8
- importlib_metadata
- pip:
- dcps
- zwoasi>=0.0.21
Expand Down

0 comments on commit c401c75

Please sign in to comment.