"""Dependency management and bootstrapping."""
import os
def ensure_deps_once():
"""Attempt to install requirements.txt once if critical imports fail."""
import sys
import subprocess
if getattr(ensure_deps_once, "_done", False):
return
req_path_candidates = [
os.path.join(os.path.dirname(__file__), "..", "requirements.txt"),
os.path.abspath("requirements.txt"),
]
req_path = next((p for p in req_path_candidates if os.path.exists(p)), None)
if not req_path:
ensure_deps_once._done = True
return
try:
print(f"Dependencies missing. Attempting to install from: {req_path}")
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", req_path])
except Exception as e:
print(f"Warning: failed to install requirements automatically: {e}")
finally:
ensure_deps_once._done = True