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