from __future__ import annotations import argparse import importlib import shutil import subprocess import sys from dataclasses import dataclass from pathlib import Path @dataclass class Check: name: str ok: bool detail: str def check_package(pkg: str) -> Check: try: mod = importlib.import_module(pkg) ver = getattr(mod, "__version__", "unknown") return Check(pkg, True, f"version={ver}") except Exception as exc: return Check(pkg, False, str(exc)) def check_blender(blender_bin: str) -> Check: blender = shutil.which(blender_bin) if not Path(blender_bin).is_file() else blender_bin if blender is None: return Check("blender", False, "not found in PATH") try: proc = subprocess.run([blender, "--version"], capture_output=True, text=True, timeout=15) except Exception as exc: return Check("blender", False, str(exc)) first_line = proc.stdout.splitlines()[0] if proc.stdout else "unknown" return Check("blender", proc.returncode == 0, first_line) def check_torch_cuda() -> Check: try: import torch if torch.cuda.is_available(): return Check("torch.cuda", True, f"available, devices={torch.cuda.device_count()}") return Check("torch.cuda", True, "not available, CPU fallback is supported") except Exception as exc: return Check("torch.cuda", False, str(exc)) def check_clip_cache(model_name: str = "openai/clip-vit-base-patch32") -> Check: try: from transformers import CLIPModel CLIPModel.from_pretrained(model_name, local_files_only=True) return Check("clip.cache", True, f"cached model={model_name}") except Exception as exc: return Check("clip.cache", False, f"{model_name}: {exc}") def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--blender_bin", default="blender") parser.add_argument("--clip_model_path", default="openai/clip-vit-base-patch32") parser.add_argument("--skip_clip_cache", action="store_true") return parser.parse_args() def main() -> int: args = parse_args() checks = [ Check("python", True, sys.version.splitlines()[0]), check_package("numpy"), check_package("cv2"), check_package("PIL"), check_package("torch"), check_package("transformers"), check_package("safetensors"), check_package("ftfy"), check_package("regex"), check_package("scipy"), check_blender(args.blender_bin), check_torch_cuda(), ] if not args.skip_clip_cache: checks.append(check_clip_cache(args.clip_model_path)) failed = 0 for c in checks: status = "OK" if c.ok else "FAIL" print(f"[{status}] {c.name}: {c.detail}") if not c.ok: failed += 1 print(f"\nSummary: {len(checks) - failed}/{len(checks)} checks passed") return 1 if failed else 0 if __name__ == "__main__": raise SystemExit(main())