QPromaQ's picture
Reset repository and upload final project (part 29)
24f6204 verified
Raw
History Blame Contribute Delete
3.06 kB
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())