36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
import os
|
|
import sys
|
|
import yaml
|
|
|
|
|
|
def _get_base_dir():
|
|
"""exe 실행 시 exe 옆, 개발 시 스크립트 옆에서 config.yaml을 찾는다."""
|
|
if getattr(sys, 'frozen', False):
|
|
# PyInstaller exe
|
|
return os.path.dirname(sys.executable)
|
|
else:
|
|
return os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
def load_config():
|
|
base_dir = _get_base_dir()
|
|
config_path = os.path.join(base_dir, 'config.yaml')
|
|
|
|
if not os.path.exists(config_path):
|
|
raise FileNotFoundError(f"config.yaml을 찾을 수 없습니다: {config_path}")
|
|
|
|
with open(config_path, 'r', encoding='utf-8') as f:
|
|
return yaml.safe_load(f)
|
|
|
|
|
|
def get_weights_dir():
|
|
"""weights 폴더 경로. exe 내부 번들 또는 exe 옆 폴더."""
|
|
if getattr(sys, 'frozen', False):
|
|
# PyInstaller 번들 내부 (--add-data로 포함된 경우)
|
|
return os.path.join(sys._MEIPASS, 'weights')
|
|
else:
|
|
return os.path.join(os.path.dirname(os.path.abspath(__file__)), 'weights')
|
|
|
|
|
|
CFG = load_config()
|