Skip to content

Commit 5a27695

Browse files
committed
Move parse_human_friendly_id into parsers.py
1 parent aa8c792 commit 5a27695

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

infrahub_sdk/node/__init__.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
SAFE_VALUE,
1212
)
1313
from .node import InfrahubNode, InfrahubNodeBase, InfrahubNodeSync
14+
from .parsers import parse_human_friendly_id
1415
from .property import NodeProperty
1516
from .related_node import RelatedNode, RelatedNodeBase, RelatedNodeSync
1617
from .relationship import RelationshipManager, RelationshipManagerBase, RelationshipManagerSync
@@ -19,6 +20,7 @@
1920
"ARTIFACT_DEFINITION_GENERATE_FEATURE_NOT_SUPPORTED_MESSAGE",
2021
"ARTIFACT_FETCH_FEATURE_NOT_SUPPORTED_MESSAGE",
2122
"ARTIFACT_GENERATE_FEATURE_NOT_SUPPORTED_MESSAGE",
23+
"HFID_STR_SEPARATOR",
2224
"IP_TYPES",
2325
"PROPERTIES_FLAG",
2426
"PROPERTIES_OBJECT",
@@ -33,16 +35,5 @@
3335
"RelationshipManager",
3436
"RelationshipManagerBase",
3537
"RelationshipManagerSync",
38+
"parse_human_friendly_id",
3639
]
37-
38-
39-
def parse_human_friendly_id(hfid: str | list[str]) -> tuple[str | None, list[str]]:
40-
"""Parse a human friendly ID into a kind and an identifier."""
41-
if isinstance(hfid, str):
42-
hfid_parts = hfid.split(HFID_STR_SEPARATOR)
43-
if len(hfid_parts) == 1:
44-
return None, hfid_parts
45-
return hfid_parts[0], hfid_parts[1:]
46-
if isinstance(hfid, list):
47-
return None, hfid
48-
raise ValueError(f"Invalid human friendly ID: {hfid}")

infrahub_sdk/node/parsers.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from __future__ import annotations
2+
3+
from .constants import HFID_STR_SEPARATOR
4+
5+
6+
def parse_human_friendly_id(hfid: str | list[str]) -> tuple[str | None, list[str]]:
7+
"""Parse a human friendly ID into a kind and an identifier."""
8+
if isinstance(hfid, str):
9+
hfid_parts = hfid.split(HFID_STR_SEPARATOR)
10+
if len(hfid_parts) == 1:
11+
return None, hfid_parts
12+
return hfid_parts[0], hfid_parts[1:]
13+
if isinstance(hfid, list):
14+
return None, hfid
15+
raise ValueError(f"Invalid human friendly ID: {hfid}")

infrahub_sdk/store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import TYPE_CHECKING, Literal, overload
55

66
from .exceptions import NodeInvalidError, NodeNotFoundError
7-
from .node import parse_human_friendly_id
7+
from .node.parsers import parse_human_friendly_id
88

99
if TYPE_CHECKING:
1010
from .client import SchemaType, SchemaTypeSync

0 commit comments

Comments
 (0)