import zipfile import os import re PURE_TAGS = {"py2", "py3", "py2.py3", "none", "any"} def detect_wheel_type(wheel_path: str) -> dict: if not os.path.isfile(wheel_path): return {"error": f"File not found: {wheel_path}"} if not wheel_path.endswith(".whl"): return {"error": "Not a .whl file"} basename = os.path.basename(wheel_path) parts = basename.split("-") platform_tag = parts[-1].replace(".whl", "") if len(parts) >= 4 else "unknown" abi_tag = parts[-2] if len(parts) >= 4 else "unknown" has_native = False native_detail = "" if platform_tag not in PURE_TAGS or abi_tag != "none": has_native = True native_detail = f"platform={platform_tag}, abi={abi_tag}" if not has_native: try: with zipfile.ZipFile(wheel_path) as zf: for name in zf.namelist(): if name.endswith((".so", ".pyd", ".dll", ".dylib")): has_native = True native_detail = f"contains native extension: {name}" break except zipfile.BadZipFile: return {"error": "Corrupt or invalid zip file"} return { "wheel": basename, "pure_python": not has_native, "native": has_native, "detail": native_detail or "tag=any/none, no native binaries found", }