-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
38 lines (29 loc) · 930 Bytes
/
__init__.py
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
35
36
37
38
# Copyright (c) 2025 Marcin Zdun
# This code is licensed under MIT license (see LICENSE for details)
"""
The **proj_flow.base** contains low-level tools for higher-level parts of the
library.
"""
import typing
from . import cmd, matrix, plugins, registry, uname
__all__ = ["cmd", "matrix", "plugins", "registry", "uname"]
def path_get(
structure: typing.Union[dict, list], dotted_path: str, default: typing.Any = None
):
ctx: typing.Any = structure
for name in dotted_path.split("."):
if isinstance(ctx, dict):
try:
ctx = ctx[name]
continue
except KeyError:
return default
if isinstance(ctx, (list, tuple)):
try:
index = int(name)
except ValueError:
return default
except IndexError:
return default
return default
return ctx