Spaces:
Sleeping
Sleeping
File size: 1,926 Bytes
ef78361 | 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | """Feature μλ νμ + λ±λ‘.
features/ νμ λλ ν 리λ₯Ό μ€μΊνμ¬ FEATURE_CONFIGκ° μλ λͺ¨λμ μμ§νκ³ orderλ‘ μ λ ¬.
"""
import importlib
from pathlib import Path
_REQUIRED_CONFIG_FIELDS = {"name", "icon", "order"}
def discover_features() -> list[dict]:
"""features/ νμ λλ ν 리λ₯Ό μ€μΊ, FEATURE_CONFIG μλ λͺ¨λ μμ§, order μ λ ¬.
Returns:
List of dicts with 'config' and 'module' keys, sorted by order.
"""
features_dir = Path(__file__).parent / "features"
if not features_dir.exists():
return []
results = []
for child in sorted(features_dir.iterdir()):
if not child.is_dir() or child.name.startswith("_"):
continue
init_file = child / "__init__.py"
if not init_file.exists():
continue
try:
module = importlib.import_module(f"features.{child.name}")
config = getattr(module, "FEATURE_CONFIG", None)
if not config or not isinstance(config, dict):
continue
missing = _REQUIRED_CONFIG_FIELDS - set(config.keys())
if missing:
import streamlit as st
st.warning(f"Feature '{child.name}': νμ νλ λλ½ {missing}")
continue
if not hasattr(module, "render") or not callable(module.render):
import streamlit as st
st.warning(f"Feature '{child.name}': render() ν¨μ μμ")
continue
results.append({
"config": config,
"module": module,
})
except Exception as e:
import streamlit as st
st.warning(
f"Feature '{child.name}' λ‘λ μ€ν¨: "
f"{type(e).__name__}: {e}"
)
results.sort(key=lambda x: x["config"].get("order", 99))
return results
|