feat(v3.2): CI/CD config + Python bindings setup
- Add .gitea/workflows/build.yml (build, test, docs, python binding CI) - Add root pyproject.toml + setup.py (CMake-based pip install) - Add root vde/__init__.py (Python package entry point) - Update README: CI badge, version 3.2.0, Python install instructions - Bump project version to 3.2.0 across CMakeLists.txt, python/setup.py, python/vde/__init__.py - Add build_py/ to .gitignore
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
"""
|
||||
ViewDesignEngine — CMake-based Python bindings.
|
||||
|
||||
Build & install:
|
||||
pip install -e . # editable install
|
||||
pip install . # regular install
|
||||
|
||||
Requires: CMake ≥ 3.16, C++17, Eigen3 (auto-fetched), pybind11.
|
||||
"""
|
||||
from setuptools import setup
|
||||
from setuptools.command.build_ext import build_ext
|
||||
from setuptools.command.build_py import build_py
|
||||
import subprocess
|
||||
import sys
|
||||
import shutil
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).parent.resolve()
|
||||
PKG_DIR = ROOT / "vde"
|
||||
|
||||
|
||||
class CMakeBuildExt(build_ext):
|
||||
"""Build the native _vde module via CMake."""
|
||||
|
||||
def run(self):
|
||||
build_dir = ROOT / "build_py"
|
||||
build_dir.mkdir(exist_ok=True)
|
||||
|
||||
# ── Configure ──
|
||||
subprocess.check_call(
|
||||
[
|
||||
"cmake",
|
||||
"-B", str(build_dir),
|
||||
"-DVDE_BUILD_PYTHON=ON",
|
||||
"-DCMAKE_BUILD_TYPE=Release",
|
||||
"-DBUILD_TESTS=OFF",
|
||||
"-DBUILD_BENCHMARKS=OFF",
|
||||
"-DBUILD_EXAMPLES=OFF",
|
||||
],
|
||||
cwd=str(ROOT),
|
||||
)
|
||||
|
||||
# ── Build ──
|
||||
parallel = str(os.cpu_count() or 4)
|
||||
subprocess.check_call(
|
||||
["cmake", "--build", str(build_dir), "-j", parallel],
|
||||
cwd=str(ROOT),
|
||||
)
|
||||
|
||||
# ── Copy .so / .pyd to package dir ──
|
||||
so_suffix = ".cpython-*-linux-gnu.so" if sys.platform == "linux" else "*.so"
|
||||
so_glob = "*.pyd" if sys.platform == "win32" else so_suffix
|
||||
|
||||
so_files = list(build_dir.glob(f"python/{so_glob}"))
|
||||
so_files += list(build_dir.glob(f"python/**/{so_glob}"))
|
||||
|
||||
if not so_files:
|
||||
# fallback: search whole build tree
|
||||
so_files = list(build_dir.rglob(f"_vde{so_glob}"))
|
||||
so_files += list(build_dir.rglob(f"_vde*.so"))
|
||||
|
||||
for so in so_files:
|
||||
dest = PKG_DIR / so.name
|
||||
print(f"Installing {so.name} → {dest}")
|
||||
shutil.copy2(str(so), str(dest))
|
||||
break # copy first match
|
||||
|
||||
|
||||
class CMakeBuildPy(build_py):
|
||||
"""Ensure native build runs before packaging."""
|
||||
|
||||
def run(self):
|
||||
self.run_command("build_ext")
|
||||
super().run()
|
||||
|
||||
|
||||
setup(
|
||||
name="vde",
|
||||
version="3.2.0",
|
||||
description="High-performance C++ CAD geometry engine",
|
||||
long_description=(ROOT / "README.md").read_text(encoding="utf-8")
|
||||
if (ROOT / "README.md").exists()
|
||||
else "",
|
||||
long_description_content_type="text/markdown",
|
||||
url="https://github.com/ViewDesignEngine/ViewDesignEngine",
|
||||
packages=["vde"],
|
||||
package_dir={"vde": "vde"},
|
||||
cmdclass={
|
||||
"build_ext": CMakeBuildExt,
|
||||
"build_py": CMakeBuildPy,
|
||||
},
|
||||
python_requires=">=3.8",
|
||||
zip_safe=False,
|
||||
)
|
||||
Reference in New Issue
Block a user