Skip to content

Commit b5b1cbe

Browse files
authored
pathlib.Path support in Config.get_config (#357)
1 parent aa9ee35 commit b5b1cbe

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

luxonis_ml/utils/config.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import ast
2-
from pathlib import PurePath
2+
from pathlib import Path, PurePath
33
from typing import Any, TypeVar
44

55
import yaml
@@ -19,7 +19,7 @@ class LuxonisConfig(BaseModelExtraForbid):
1919
@classmethod
2020
def get_config(
2121
cls,
22-
cfg: str | Params | None = None,
22+
cfg: PathType | Params | None = None,
2323
overrides: Params | list[str] | tuple[str, ...] | None = None,
2424
) -> Self:
2525
"""Loads config from a yaml file or a dictionary.
@@ -50,7 +50,9 @@ def get_config(
5050
overrides = overrides or {}
5151
cfg = cfg or {}
5252

53-
if isinstance(cfg, str):
53+
if isinstance(cfg, Path):
54+
data = yaml.safe_load(cfg.read_text(encoding="utf-8"))
55+
elif isinstance(cfg, str):
5456
fs = LuxonisFileSystem(cfg)
5557
buffer = fs.read_to_byte_buffer()
5658
data = yaml.safe_load(buffer)

tests/test_utils/test_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_invalid_config_path():
8282

8383

8484
def test_config_simple(config_file: str):
85-
cfg = Config.get_config(config_file)
85+
cfg = Config.get_config(Path(config_file))
8686
assert (
8787
cfg.sub_config.str_sub_param
8888
== CONFIG_DATA["sub_config"]["str_sub_param"]

0 commit comments

Comments
 (0)