Skip to content

Commit 4b30eb5

Browse files
committed
@sanderegg review: services constants
1 parent a713ee8 commit 4b30eb5

File tree

3 files changed

+39
-30
lines changed

3 files changed

+39
-30
lines changed

packages/models-library/src/models_library/function_services_catalog/_key_labels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Final
22

33
from ..services import ServiceKey
4-
from ..services_regex import FRONTEND_SERVICE_KEY_PREFIX
4+
from ..services_constants import FRONTEND_SERVICE_KEY_PREFIX
55

66
# NOTE: due to legacy reasons, the name remains with 'frontend' in it but
77
# it now refers to a more general group: function sections that contains front-end services as well
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
1+
from types import MappingProxyType
12
from typing import Final
23

3-
LATEST_INTEGRATION_VERSION: Final[str] = "1.0.0"
4+
from .services_enums import ServiceType
45

6+
LATEST_INTEGRATION_VERSION: Final[str] = "1.0.0"
57

68
ANY_FILETYPE: Final[str] = "data:*/*"
9+
10+
SERVICE_TYPE_TO_NAME_MAP = MappingProxyType(
11+
{
12+
ServiceType.COMPUTATIONAL: "comp",
13+
ServiceType.DYNAMIC: "dynamic",
14+
ServiceType.FRONTEND: "frontend",
15+
}
16+
)
17+
18+
19+
def _create_key_prefix(service_type: ServiceType) -> str:
20+
return f"simcore/services/{SERVICE_TYPE_TO_NAME_MAP[service_type]}"
21+
22+
23+
COMPUTATIONAL_SERVICE_KEY_PREFIX: Final[str] = _create_key_prefix(
24+
ServiceType.COMPUTATIONAL
25+
)
26+
DYNAMIC_SERVICE_KEY_PREFIX: Final[str] = _create_key_prefix(ServiceType.DYNAMIC)
27+
FRONTEND_SERVICE_KEY_PREFIX: Final[str] = _create_key_prefix(ServiceType.FRONTEND)

packages/models-library/src/models_library/services_regex.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
from types import MappingProxyType
33
from typing import Final
44

5+
from .services_constants import (
6+
COMPUTATIONAL_SERVICE_KEY_PREFIX,
7+
DYNAMIC_SERVICE_KEY_PREFIX,
8+
FRONTEND_SERVICE_KEY_PREFIX,
9+
SERVICE_TYPE_TO_NAME_MAP,
10+
)
511
from .services_enums import ServiceType
612

713
PROPERTY_TYPE_RE = r"^(number|integer|boolean|string|ref_contentSchema|data:([^/\s,]+/[^/\s,]+|\[[^/\s,]+/[^/\s,]+(,[^/\s]+/[^/,\s]+)*\]))$"
@@ -14,15 +20,6 @@
1420

1521
FILENAME_RE = r".+"
1622

17-
18-
SERVICE_TYPE_TO_NAME_MAP = MappingProxyType(
19-
{
20-
ServiceType.COMPUTATIONAL: "comp",
21-
ServiceType.DYNAMIC: "dynamic",
22-
ServiceType.FRONTEND: "frontend",
23-
}
24-
)
25-
2623
# e.g. simcore/services/comp/opencor
2724
SERVICE_KEY_RE: Final[re.Pattern[str]] = re.compile(
2825
r"^simcore/services/"
@@ -40,41 +37,32 @@
4037
)
4138

4239

43-
def create_key_prefix(service_type: ServiceType) -> str:
44-
return f"simcore/services/{SERVICE_TYPE_TO_NAME_MAP[service_type]}"
45-
46-
47-
COMPUTATIONAL_SERVICE_KEY_PREFIX: Final[str] = create_key_prefix(
48-
ServiceType.COMPUTATIONAL
49-
)
50-
DYNAMIC_SERVICE_KEY_PREFIX: Final[str] = create_key_prefix(ServiceType.DYNAMIC)
51-
FRONTEND_SERVICE_KEY_PREFIX: Final[str] = create_key_prefix(ServiceType.FRONTEND)
52-
53-
54-
def create_key_regex(service_type: ServiceType) -> re.Pattern[str]:
40+
def _create_key_regex(service_type: ServiceType) -> re.Pattern[str]:
5541
return re.compile(
5642
rf"^simcore/services/{SERVICE_TYPE_TO_NAME_MAP[service_type]}/"
5743
r"(?P<subdir>[a-z0-9][a-z0-9_.-]*/)*"
5844
r"(?P<name>[a-z0-9-_]+[a-z0-9])$"
5945
)
6046

6147

62-
def create_key_format(service_type: ServiceType) -> str:
48+
def _create_key_format(service_type: ServiceType) -> str:
6349
return f"simcore/services/{SERVICE_TYPE_TO_NAME_MAP[service_type]}/{{service_name}}"
6450

6551

66-
COMPUTATIONAL_SERVICE_KEY_RE: Final[re.Pattern[str]] = create_key_regex(
52+
COMPUTATIONAL_SERVICE_KEY_RE: Final[re.Pattern[str]] = _create_key_regex(
6753
ServiceType.COMPUTATIONAL
6854
)
69-
COMPUTATIONAL_SERVICE_KEY_FORMAT: Final[str] = create_key_format(
55+
COMPUTATIONAL_SERVICE_KEY_FORMAT: Final[str] = _create_key_format(
7056
ServiceType.COMPUTATIONAL
7157
)
7258

73-
DYNAMIC_SERVICE_KEY_RE: Final[re.Pattern[str]] = create_key_regex(ServiceType.DYNAMIC)
74-
DYNAMIC_SERVICE_KEY_FORMAT: Final[str] = create_key_format(ServiceType.DYNAMIC)
59+
DYNAMIC_SERVICE_KEY_RE: Final[re.Pattern[str]] = _create_key_regex(ServiceType.DYNAMIC)
60+
DYNAMIC_SERVICE_KEY_FORMAT: Final[str] = _create_key_format(ServiceType.DYNAMIC)
7561

76-
FRONTEND_SERVICE_KEY_RE: Final[re.Pattern[str]] = create_key_regex(ServiceType.FRONTEND)
77-
FRONTEND_SERVICE_KEY_FORMAT: Final[str] = create_key_format(ServiceType.FRONTEND)
62+
FRONTEND_SERVICE_KEY_RE: Final[re.Pattern[str]] = _create_key_regex(
63+
ServiceType.FRONTEND
64+
)
65+
FRONTEND_SERVICE_KEY_FORMAT: Final[str] = _create_key_format(ServiceType.FRONTEND)
7866

7967

8068
SERVICE_TYPE_TO_PREFIX_MAP = MappingProxyType(

0 commit comments

Comments
 (0)