feat: Add Python packaging infrastructure and comprehensive bindings for math and vector types.
This commit is contained in:
52
setup.py
Normal file
52
setup.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from setuptools import Extension, setup
|
||||
from setuptools.command.build_ext import build_ext
|
||||
|
||||
class CMakeExtension(Extension):
|
||||
def __init__(self, name, sourcedir=""):
|
||||
Extension.__init__(self, name, sources=[])
|
||||
self.sourcedir = os.path.abspath(sourcedir)
|
||||
|
||||
class CMakeBuild(build_ext):
|
||||
def build_extension(self, ext):
|
||||
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
|
||||
|
||||
if not extdir.endswith(os.path.sep):
|
||||
extdir += os.path.sep
|
||||
|
||||
debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug
|
||||
cfg = "Debug" if debug else "Release"
|
||||
|
||||
cmake_args = [
|
||||
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}",
|
||||
f"-DPYTHON_EXECUTABLE={sys.executable}",
|
||||
f"-DCMAKE_BUILD_TYPE={cfg}",
|
||||
f"-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE",
|
||||
f"-DCMAKE_INSTALL_RPATH=$ORIGIN",
|
||||
"-DUSE_CUDA=OFF",
|
||||
"-G", "Unix Makefiles",
|
||||
]
|
||||
build_args = []
|
||||
|
||||
build_temp = os.path.join(self.build_temp, ext.name)
|
||||
if not os.path.exists(build_temp):
|
||||
os.makedirs(build_temp)
|
||||
|
||||
subprocess.check_call(["cmake", ext.sourcedir] + cmake_args, cwd=build_temp)
|
||||
subprocess.check_call(["cmake", "--build", ".", "--target", "uLib_python"] + build_args, cwd=build_temp)
|
||||
|
||||
setup(
|
||||
name="ulib",
|
||||
version="0.6.0",
|
||||
author="Andrea Rigoni Garola",
|
||||
author_email="andrea.rigoni@pd.infn.it",
|
||||
description="CMT Cosmic Muon Tomography project uLib python bindings",
|
||||
ext_modules=[CMakeExtension("uLib_python")],
|
||||
cmdclass={"build_ext": CMakeBuild},
|
||||
zip_safe=False,
|
||||
python_requires=">=3.6",
|
||||
)
|
||||
Reference in New Issue
Block a user