forked from DiamondLightSource/python-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
34 lines (29 loc) · 976 Bytes
/
Copy path__init__.py
File metadata and controls
34 lines (29 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from __future__ import annotations
import pkg_resources
def lookup(service: str):
"""Find a service class based on a name.
:param service: Name of the service
:return: A service class
"""
service_factory = get_known_services().get(service)
if service_factory:
return service_factory()
else:
return None
def get_known_services():
"""Return a dictionary of all known services.
:return: A dictionary containing entries { service name : service class factory }
A factory is a function that takes no arguments and returns an
uninstantiated service class.
"""
if not hasattr(get_known_services, "cache"):
setattr(
get_known_services,
"cache",
{
e.name: e.load
for e in pkg_resources.iter_entry_points("workflows.services")
},
)
register = get_known_services.cache.copy()
return register