45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
from pathlib import Path
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
if str(ROOT) not in sys.path:
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
MODELS_DIR = ROOT / "src" / "models"
|
|
|
|
|
|
def main(env=None) -> int:
|
|
env = os.environ if env is None else env
|
|
output_json = _get_bool(env, "SHOW_MODELS_OUTPUT_JSON", False)
|
|
model_files = sorted(
|
|
path.stem
|
|
for path in MODELS_DIR.glob("*.py")
|
|
if path.is_file() and path.stem != "__init__"
|
|
)
|
|
if output_json:
|
|
print(
|
|
json.dumps(
|
|
{"passed": True, "model_count": len(model_files), "models": model_files},
|
|
ensure_ascii=False,
|
|
sort_keys=True,
|
|
)
|
|
)
|
|
return 0
|
|
print(f"model exports: {len(model_files)}")
|
|
for name in model_files:
|
|
print(name)
|
|
return 0
|
|
|
|
|
|
def _get_bool(env, key: str, default: bool) -> bool:
|
|
value = env.get(key)
|
|
if value is None or value == "":
|
|
return default
|
|
return str(value).strip().lower() in {"1", "true", "yes", "on"}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|