ci-net / code /labeling /src /config_utils.py
lsh9034's picture
Add files using upload-large-folder tool
7da2ecb verified
Raw History Blame Contribute Delete
1.39 kB
"""
file: config.py
date: 2026/02/15
brief: JSON 기반 μ„€μ • 파일 λ‘œλ” μœ ν‹Έλ¦¬ν‹°
λ³Έ λͺ¨λ“ˆμ€ ν”„λ‘œμ νŠΈ μ „λ°˜μ—μ„œ μ‚¬μš©λ˜λŠ” μ„€μ •(JSON) νŒŒμΌμ„
파이썬 λ”•μ…”λ„ˆλ¦¬ ν˜•νƒœλ‘œ λ‘œλ“œν•˜κΈ° μœ„ν•œ 곡톡 μœ ν‹Έ ν•¨μˆ˜λ“€μ„ μ œκ³΅ν•œλ‹€.
νŠΉμ§•:
- UTF-8 인코딩을 λͺ…μ‹œμ μœΌλ‘œ μ‚¬μš©
- μ„€μ • 파일의 κ΅¬μ‘°λ‚˜ 킀에 λŒ€ν•œ 검증은 μˆ˜ν–‰ν•˜μ§€ μ•ŠμŒ
- 각 step(step1/2/3) μŠ€ν¬λ¦½νŠΈμ—μ„œ λ™μΌν•œ λ°©μ‹μœΌλ‘œ μž¬μ‚¬μš©λ¨
----------------------------------------------------------------------
Version Date Comment
--------- ---------- ----------------------------------------------
"""
import json
from typing import Any, Dict
def load_config(path: str) -> Dict[str, Any]:
"""
JSON ν˜•μ‹μ˜ μ„€μ • νŒŒμΌμ„ λ‘œλ“œν•˜μ—¬ λ”•μ…”λ„ˆλ¦¬λ‘œ λ°˜ν™˜ν•œλ‹€.
Parameters
----------
path : str
λ‘œλ“œν•  μ„€μ • 파일(JSON)의 경둜
Returns
-------
dict[str, Any]
JSON 파일 λ‚΄μš©μ„ κ·ΈλŒ€λ‘œ 담은 μ„€μ • λ”•μ…”λ„ˆλ¦¬
Raises
------
FileNotFoundError
μ§€μ •ν•œ κ²½λ‘œμ— 파일이 μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” 경우
json.JSONDecodeError
JSON ν˜•μ‹μ΄ μ˜¬λ°”λ₯΄μ§€ μ•Šμ€ 경우
UnicodeDecodeError
파일 인코딩이 UTF-8이 μ•„λ‹Œ 경우
"""
with open(path, "r", encoding="utf-8") as f:
cfg = json.load(f)
return cfg