File size: 3,059 Bytes
24f6204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from __future__ import annotations

import importlib
import platform
import shutil
import subprocess
import sys
from dataclasses import dataclass
from typing import Dict, List


REQUIRED_IMPORTS = [
    "numpy",
    "pandas",
    "scipy",
    "sklearn",
    "xgboost",
    "yaml",
    "pydantic",
    "rich",
    "typer",
    "pyarrow",
    "joblib",
    "Bio",
    "rdkit",
    "networkx",
    "matplotlib",
    "tqdm",
    "requests",
]


@dataclass
class CapabilityReport:
    python_ok: bool
    imports_ok: Dict[str, bool]
    rdock_execs: Dict[str, bool]
    gcc_available: bool
    popt_available: bool

    @property
    def all_required_ok(self) -> bool:
        return self.python_ok and all(self.imports_ok.values())


def _check_python() -> bool:
    return sys.version_info.major == 3 and sys.version_info.minor >= 11


def _check_imports() -> Dict[str, bool]:
    out: Dict[str, bool] = {}
    for module in REQUIRED_IMPORTS:
        try:
            importlib.import_module(module)
            out[module] = True
        except Exception:
            out[module] = False
    return out


def _check_rdock() -> Dict[str, bool]:
    binaries = ["rbdock", "rbcavity", "sdtether"]
    return {binary: shutil.which(binary) is not None for binary in binaries}


def _check_gcc() -> bool:
    return shutil.which("gcc") is not None or any(shutil.which(f"gcc-{v}") for v in ("14", "13", "12"))


def _check_popt() -> bool:
    if shutil.which("popt-config"):
        return True
    if shutil.which("brew"):
        proc = subprocess.run(
            ["brew", "list", "--versions", "popt"],
            check=False,
            capture_output=True,
            text=True,
        )
        return proc.returncode == 0 and bool(proc.stdout.strip())
    return False


def run_doctor() -> CapabilityReport:
    return CapabilityReport(
        python_ok=_check_python(),
        imports_ok=_check_imports(),
        rdock_execs=_check_rdock(),
        gcc_available=_check_gcc(),
        popt_available=_check_popt(),
    )


def _fmt_missing(mods: Dict[str, bool]) -> List[str]:
    return [name for name, ok in mods.items() if not ok]


def main() -> int:
    report = run_doctor()
    print("=== Capability Report ===")
    print(f"Platform: {platform.platform()}")
    print(f"Python: {sys.version.split()[0]} (>=3.11 required) -> {'OK' if report.python_ok else 'FAIL'}")

    missing = _fmt_missing(report.imports_ok)
    print(f"Imports: {'OK' if not missing else 'MISSING'}")
    if missing:
        print("  Missing modules:", ", ".join(missing))

    print("rDock executables:")
    for name, ok in report.rdock_execs.items():
        print(f"  - {name}: {'FOUND' if ok else 'NOT FOUND'}")

    print(f"GCC available: {'YES' if report.gcc_available else 'NO'}")
    print(f"popt available: {'YES' if report.popt_available else 'NO'}")

    overall = report.all_required_ok
    print(f"Overall required Python stack: {'READY' if overall else 'NOT READY'}")
    return 0 if overall else 1


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