69 lines
1.7 KiB
Python
69 lines
1.7 KiB
Python
import os
|
|
import platform
|
|
import subprocess
|
|
|
|
from setuptools.command.build_py import build_py
|
|
|
|
# `casadi/` is generated by build.sh (vendored from the upstream wheel), but
|
|
# setuptools requires every declared package to have a directory + __init__.py
|
|
# *before* any command runs. Drop a stub if it isn't there yet — build.sh
|
|
# replaces it with the real slim casadi during build_py.
|
|
_HERE = os.path.dirname(os.path.abspath(__file__))
|
|
_casadi_init = os.path.join(_HERE, "casadi", "__init__.py")
|
|
if not os.path.exists(_casadi_init):
|
|
os.makedirs(os.path.dirname(_casadi_init), exist_ok=True)
|
|
open(_casadi_init, "w").close()
|
|
|
|
try:
|
|
from wheel.bdist_wheel import bdist_wheel
|
|
except ImportError:
|
|
bdist_wheel = None
|
|
|
|
|
|
class BuildAcados(build_py):
|
|
"""Run build.sh to compile acados before collecting package data."""
|
|
|
|
def run(self):
|
|
pkg_dir = os.path.dirname(os.path.abspath(__file__))
|
|
build_script = os.path.join(pkg_dir, "build.sh")
|
|
subprocess.check_call(["bash", build_script], cwd=pkg_dir)
|
|
|
|
super().run()
|
|
|
|
|
|
cmdclass = {"build_py": BuildAcados}
|
|
|
|
if bdist_wheel is not None:
|
|
|
|
class PlatformWheel(bdist_wheel):
|
|
"""Produce a platform-specific, Python-version-agnostic wheel."""
|
|
|
|
def finalize_options(self):
|
|
super().finalize_options()
|
|
self.root_is_pure = False
|
|
|
|
def get_tag(self):
|
|
system = platform.system()
|
|
machine = platform.machine()
|
|
|
|
if system == "Linux":
|
|
plat = f"linux_{machine}"
|
|
elif system == "Darwin":
|
|
plat = "macosx_11_0_arm64"
|
|
else:
|
|
plat = f"{system.lower()}_{machine}"
|
|
|
|
return "py3", "none", plat
|
|
|
|
cmdclass["bdist_wheel"] = PlatformWheel
|
|
|
|
|
|
def setup():
|
|
from setuptools import setup as _setup
|
|
|
|
_setup(cmdclass=cmdclass)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
setup()
|