
import os
import sys
import importlib.util
import platform


def _load_binary():
    py_version = f"{sys.version_info.major}{sys.version_info.minor}"
    os_name = platform.system().lower()
    dir_path = os.path.dirname(__file__)
    ext = "pyd" if os_name == "windows" else "so"
    filename = f"upseeker.cpython-{py_version}-{os_name}.{ext}"
    binary_path = os.path.join(dir_path, filename)

    if not os.path.exists(binary_path):
        raise ImportError(f"Binary file {filename} not found")

    # The first argument MUST be "seeker" to match the PyInit_seeker entry point
    spec = importlib.util.spec_from_file_location("upseeker", binary_path)
    mylib = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(mylib)

    # Inject into this package's namespace
    globals().update(mylib.__dict__)


_load_binary()

try:
    from .upseeker import configure_distributed_run_directory
except (ImportError, AttributeError):
    pass


