Spaces:
Running on Zero
Running on Zero
File size: 5,521 Bytes
75b4f2e | 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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | # scripts/check_environment.py
# G-MASS environment validation script
#
# Run this to verify the project environment is ready for use.
#
# Usage:
# python scripts/check_environment.py
import importlib.util
import os
import shutil
import subprocess
import sys
import sysconfig
def module_available(module_name):
try:
return importlib.util.find_spec(module_name) is not None
except ModuleNotFoundError:
return False
print("\n" + "=" * 60)
print(" G-MASS Project - Environment Setup Check")
print("=" * 60 + "\n")
errors = []
print("Checking Python version...")
major, minor = sys.version_info.major, sys.version_info.minor
if major == 3 and minor >= 10:
print(f" OK Python {major}.{minor}\n")
else:
print(f" FAIL Python {major}.{minor} - Need Python 3.10 or higher")
print(" Download from: python.org\n")
errors.append("Python version too old")
print("Checking installed packages...")
packages = {
"openai": "pip install -r requirements.txt",
"google.genai": "pip install -r requirements.txt",
"huggingface_hub": "pip install -r requirements.txt",
"requests": "pip install -r requirements.txt",
"dotenv": "pip install -r requirements.txt",
"yaml": "pip install -r requirements.txt",
"numpy": "pip install -r requirements.txt",
"fasttext": "pip install -r requirements.txt",
"openpyxl": "pip install -r requirements.txt",
"pandas": "pip install -r requirements.txt",
"jsonlines": "pip install -r requirements.txt",
}
for pkg, install_cmd in packages.items():
if module_available(pkg):
print(f" OK {pkg}")
else:
print(f" FAIL {pkg} - Run: {install_cmd}")
errors.append(f"Missing package: {pkg}")
print()
print("Checking installed G-MASS CLI...")
scripts_dir = sysconfig.get_path("scripts")
gmass_exe = "gmass.exe" if os.name == "nt" else "gmass"
gmass_script = os.path.join(scripts_dir, gmass_exe) if scripts_dir else ""
gmass_cmd = (gmass_script if gmass_script and os.path.exists(gmass_script) else None) or shutil.which("gmass")
if gmass_cmd:
result = subprocess.run(
[gmass_cmd, "--help"],
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
text=True,
timeout=15,
)
if result.returncode == 0:
print(" OK gmass CLI found")
else:
print(" WARN gmass CLI file found, but its launcher did not run")
print(" Fallback: python -m run_bilingual_eval --help")
print(" If this virtualenv was copied or moved, recreate it and rerun setup.sh.")
else:
print(" FAIL gmass CLI not found - Run: python -m pip install -e .")
errors.append("gmass CLI missing")
print()
print("Checking .env file...")
if not os.path.exists(".env"):
print(" FAIL .env file not found in current directory")
if os.path.exists(".env.example"):
print(" Run setup.sh to generate a local .env from .env.example, then fill in your API keys.\n")
else:
print(" Create .env from your own environment or add .env.example to the repo.\n")
errors.append(".env file missing")
else:
if module_available("dotenv"):
from dotenv import load_dotenv
load_dotenv()
else:
print(" FAIL python-dotenv is not installed")
errors.append("Missing package: dotenv")
keys = {
"HF_TOKEN": "huggingface.co -> Settings -> Access Tokens",
"OPENAI_API_KEY": "platform.openai.com/api-keys",
"GEMINI_API_KEY": "aistudio.google.com -> Get API Key",
}
for key, source in keys.items():
value = os.getenv(key)
if not value or "your_" in value.lower() or value.strip() == "" or value.lower() in {"changeme", "replace-me"}:
print(f" FAIL {key} - not set or is a placeholder")
print(f" Get it from: {source}")
errors.append(f"Missing key: {key}")
else:
print(f" OK {key} is set")
print()
if os.getenv("SCORER_BACKEND", "").lower() == "transformers" or any(
os.getenv(key, "").lower() == "transformers"
for key in ("PHI3_BACKEND", "BIOMISTRAL_BACKEND", "LOCAL_MODEL_BACKEND")
):
print("Checking local Transformers packages...")
local_packages = {
"torch": "pip install -r requirements-local.txt",
"transformers": "pip install -r requirements-local.txt",
"accelerate": "pip install -r requirements-local.txt",
"safetensors": "pip install -r requirements-local.txt",
"sentencepiece": "pip install -r requirements-local.txt",
}
for pkg, install_cmd in local_packages.items():
if module_available(pkg):
print(f" OK {pkg}")
else:
print(f" FAIL {pkg} - Run: {install_cmd}")
errors.append(f"Missing local package: {pkg}")
print()
print("Checking folder structure...")
folders = ["models", "scorer", "probes", "outputs", "tests", "configs"]
for folder in folders:
if os.path.isdir(folder):
print(f" OK {folder}/")
else:
os.makedirs(folder, exist_ok=True)
print(f" OK {folder}/ - created")
print()
print("=" * 60)
if not errors:
print(" Environment ready. Run: gmass --help")
else:
print(f" {len(errors)} issue(s) to fix before running tests:\n")
for i, err in enumerate(errors, 1):
print(f" {i}. {err}")
print("\n Fix these, then run: python scripts/check_environment.py again")
print("=" * 60 + "\n")
|