#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
"""tune-moe-cli console entry shim.

Supports two layouts:
1) wheel install: import from ``aiter.fused_moe_autotune``.
2) setup.py develop source tree: fallback to ``op_tests...`` module path.
"""

from __future__ import annotations

import importlib
import sys


def _try_import_main(module_name: str):
    module = importlib.import_module(module_name)
    return getattr(module, "main")


def main() -> int:
    try:
        target = _try_import_main("aiter.fused_moe_autotune.tune_moe_cli")
    except ModuleNotFoundError as exc:
        # develop mode fallback: keep source tree simple without creating
        # a physical aiter/fused_moe_autotune directory.
        missing = exc.name or ""
        if not missing.startswith("aiter.fused_moe_autotune"):
            raise
        try:
            target = _try_import_main("op_tests.triton_autotune.fused_moe.tune_moe_cli")
        except ModuleNotFoundError:
            print(
                "错误: 无法导入 tune_moe_cli 模块。\n"
                "请确认当前环境为以下之一：\n"
                "  1) 已正确安装 aiter wheel；\n"
                "  2) 在 aiter 源码目录执行过 `python setup.py develop`。",
                file=sys.stderr,
            )
            return 1
    return int(target())


if __name__ == "__main__":
    raise SystemExit(main())
