import os
import platform
import shutil
import subprocess
from pathlib import Path
FRAMEWORK_DIR = Path(__file__).parent
IMPLEMENTATIONS_DIR = FRAMEWORK_DIR / "implementations"
RESULTS_DIR = FRAMEWORK_DIR / "results"
FIGURES_DIR = Path(__file__).parent.parent.parent / "docs" / "figures"
RUST_BINARY = IMPLEMENTATIONS_DIR / "rust" / "target" / "release" / "bench_comparative"
NYX_BINARY = IMPLEMENTATIONS_DIR / "nyx" / "target" / "release" / "bench_nyx"
JAVA_PROJECT_DIR = IMPLEMENTATIONS_DIR / "java"
REPO_ROOT = FRAMEWORK_DIR.parent.parent
BRAHE_GRAVITY_FILE = REPO_ROOT / "data" / "gravity_models" / "EGM2008_360.gfc"
if BRAHE_GRAVITY_FILE.exists() and "BRAHE_GRAVITY_FILE" not in os.environ:
os.environ["BRAHE_GRAVITY_FILE"] = str(BRAHE_GRAVITY_FILE)
DEFAULT_ITERATIONS = 100
DEFAULT_SEED = 42
def _read_lockfile_version(lock_path: Path, pkg: str) -> str:
if not lock_path.exists():
return "not installed"
text = lock_path.read_text()
needle = f'name = "{pkg}"'
idx = text.find(needle)
if idx < 0:
return "unknown"
tail = text[idx:]
v_idx = tail.find('version = "')
if v_idx < 0:
return "unknown"
v_start = v_idx + len('version = "')
v_end = tail[v_start:].find('"')
if v_end < 0:
return "unknown"
return tail[v_start : v_start + v_end]
def collect_system_info() -> dict:
info = {
"platform": platform.platform(),
"processor": platform.processor(),
"cpu_count": platform.os.cpu_count(),
"python_version": platform.python_version(),
"machine": platform.machine(),
}
info["nyx_version"] = _read_lockfile_version(
IMPLEMENTATIONS_DIR / "nyx" / "Cargo.lock", "nyx-space"
)
info["anise_version"] = _read_lockfile_version(
IMPLEMENTATIONS_DIR / "nyx" / "Cargo.lock", "anise"
)
if shutil.which("rustc"):
try:
result = subprocess.run(
["rustc", "--version"], capture_output=True, text=True, timeout=5
)
info["rust_version"] = result.stdout.strip()
except (subprocess.TimeoutExpired, FileNotFoundError):
info["rust_version"] = "unknown"
if shutil.which("java"):
try:
result = subprocess.run(
["java", "--version"], capture_output=True, text=True, timeout=5
)
info["java_version"] = result.stdout.strip().split("\n")[0]
except (subprocess.TimeoutExpired, FileNotFoundError):
info["java_version"] = "unknown"
try:
import brahe
info["brahe_version"] = getattr(brahe, "__version__", "unknown")
except ImportError:
info["brahe_version"] = "not installed"
return info