"""Assemble and build the Nuitka wheel with setuptools.""" from __future__ import annotations import shutil import subprocess import sys from pathlib import Path from paths import sdk_dir def write_wheel_setup( wheel_dir: Path, *, version: str, package_data: dict[str, list[str]], install_requires: list[str], extras_require: dict[str, list[str]], ) -> Path: setup_py_path = wheel_dir / "setup.py" setup_content = f""" from setuptools import setup, Distribution class BinaryDistribution(Distribution): def has_ext_modules(self): return True setup( name="orisys", version="{version}", description="Orisys - Optical Tactile Sensor SDK (Nuitka Compiled)", author="Orisys", packages=['orisys', 'orisys.examples'], package_dir={{'': 'wheel_root'}}, package_data={package_data}, include_package_data=True, install_requires={install_requires!r}, extras_require={extras_require!r}, distclass=BinaryDistribution, zip_safe=False, ) """ setup_py_path.write_text(setup_content, encoding="utf-8") return setup_py_path def run_bdist_wheel(wheel_dir: Path) -> Path | None: print("\n=== Building Wheel ===") subprocess.check_call([sys.executable, "setup.py", "bdist_wheel"], cwd=wheel_dir) wheels = sorted((wheel_dir / "dist").glob("*.whl")) return wheels[0] if wheels else None def publish_wheel_to_sdk(wheel_path: Path, version: str) -> Path: sdk_version_dir = sdk_dir(version) sdk_version_dir.mkdir(parents=True, exist_ok=True) dest_wheel = sdk_version_dir / wheel_path.name if dest_wheel.exists(): dest_wheel.unlink() shutil.move(str(wheel_path), str(dest_wheel)) return dest_wheel