add linux compile
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
def install_nuitka():
|
||||
print("Checking Nuitka installation...")
|
||||
try:
|
||||
import nuitka
|
||||
print("Nuitka is installed.")
|
||||
except ImportError:
|
||||
print("Installing Nuitka...")
|
||||
subprocess.check_call([sys.executable, "-m", "pip", "install", "nuitka", "ordered-set", "zstandard"])
|
||||
|
||||
def build():
|
||||
install_nuitka()
|
||||
|
||||
version = "0.2.0"
|
||||
src_dir = Path("src/orisys")
|
||||
output_dir = Path("build_nuitka")
|
||||
dist_dir = Path("dist_nuitka")
|
||||
|
||||
# Clean previous builds
|
||||
if output_dir.exists(): shutil.rmtree(output_dir)
|
||||
if dist_dir.exists(): shutil.rmtree(dist_dir)
|
||||
output_dir.mkdir()
|
||||
dist_dir.mkdir()
|
||||
|
||||
print("\n=== Compiling with Nuitka ===")
|
||||
# Set PYTHONPATH to include src so nuitka finds the package
|
||||
env = os.environ.copy()
|
||||
env["PYTHONPATH"] = "src" + os.pathsep + env.get("PYTHONPATH", "")
|
||||
|
||||
# Nuitka arguments
|
||||
# --module: compile as module/package
|
||||
# --include-package=orisys: include the whole package
|
||||
# --output-dir: where to put result
|
||||
# src/orisys: the target directory
|
||||
cmd = [
|
||||
sys.executable, "-m", "nuitka",
|
||||
"--module",
|
||||
"--include-package=orisys",
|
||||
"--output-dir=" + str(output_dir),
|
||||
"--remove-output",
|
||||
"--no-pyi-file",
|
||||
"src/orisys"
|
||||
]
|
||||
|
||||
print(f"Running: {' '.join(cmd)}")
|
||||
subprocess.check_call(cmd, env=env)
|
||||
|
||||
# Find the generated .so file
|
||||
# It should be something like orisys.cpython-310-x86_64-linux-gnu.so
|
||||
so_files = list(output_dir.glob("*.so"))
|
||||
if not so_files:
|
||||
raise RuntimeError("Nuitka did not produce a .so file!")
|
||||
|
||||
so_file = so_files[0]
|
||||
print(f"Generated compiled extension: {so_file}")
|
||||
|
||||
print("\n=== Preparing Wheel Structure ===")
|
||||
# We want the structure:
|
||||
# orisys/
|
||||
# __init__.so <-- renamed from orisys.so
|
||||
# configs/
|
||||
# *.json
|
||||
|
||||
wheel_root = dist_dir / "wheel_root"
|
||||
pkg_dir = wheel_root / "orisys"
|
||||
pkg_dir.mkdir(parents=True)
|
||||
|
||||
# Move and rename so
|
||||
dest_so = pkg_dir / "__init__.so"
|
||||
shutil.copy(so_file, dest_so)
|
||||
print(f"Copied to {dest_so}")
|
||||
|
||||
# Copy JSON configs
|
||||
configs_src = src_dir / "configs"
|
||||
configs_dst = pkg_dir / "configs"
|
||||
configs_dst.mkdir()
|
||||
|
||||
json_count = 0
|
||||
for json_file in configs_src.glob("*.json"):
|
||||
shutil.copy(json_file, configs_dst)
|
||||
json_count += 1
|
||||
print(f"Copied {json_count} JSON config files")
|
||||
|
||||
# Create setup.py for packaging
|
||||
setup_py_path = dist_dir / "setup.py"
|
||||
setup_content = f"""
|
||||
from setuptools import setup, Distribution, find_packages
|
||||
|
||||
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'],
|
||||
package_dir={{'': 'wheel_root'}},
|
||||
package_data={{
|
||||
'orisys': ['*.so', 'configs/*.json'],
|
||||
}},
|
||||
include_package_data=True,
|
||||
distclass=BinaryDistribution,
|
||||
zip_safe=False,
|
||||
)
|
||||
"""
|
||||
with open(setup_py_path, "w") as f:
|
||||
f.write(setup_content)
|
||||
|
||||
print("\n=== Building Wheel ===")
|
||||
subprocess.check_call([sys.executable, "setup.py", "bdist_wheel"], cwd=dist_dir)
|
||||
|
||||
# Find the wheel
|
||||
dist_output = dist_dir / "dist"
|
||||
wheels = list(dist_output.glob("*.whl"))
|
||||
if wheels:
|
||||
print(f"\n[SUCCESS] Wheel created: {wheels[0]}")
|
||||
else:
|
||||
print("\n[ERROR] Wheel not found.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
build()
|
||||
|
||||
@@ -19,7 +19,7 @@ def main():
|
||||
# 步骤1:创建传感器对象 (必要步骤),config_name为配置文件名(内置配置文件名)或路径(自定义配置文件路径)
|
||||
|
||||
# 方式1: 从视频文件读取
|
||||
sensor = orisys.Sensor("./ov2710_uv_2.mp4", isstitch=True, cuda=True, verbose=True,config_name="./config/lens_test.json")
|
||||
sensor = orisys.Sensor("s1.mp4", isstitch=True, cuda=True, verbose=True,config_name="prototype")
|
||||
|
||||
|
||||
# 方式2: 从摄像头读取(取消注释使用)
|
||||
|
||||
Reference in New Issue
Block a user