Skip to content

Commit

Permalink
Merge branch 'release/0.1.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-grant-hendry committed Apr 10, 2022
2 parents cd85340 + 210a65a commit 2f194be
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 170 deletions.
4 changes: 1 addition & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
include *.h *.pxd *.dll
recursive-include embree2 *.h *.isph
recursive-include embree2/lib *.lib
recursive-include pyembree *.pyd *.so
89 changes: 89 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import os
import shutil
from importlib import metadata
from typing import Any, Dict, List

import numpy as np

# setuptools must be imported before cython. setuptools overrides the
# distutils.extension.Extension class. If imported after, the isinstance check in
# distutils.command.check_extensions_list fails and setuptools gives the erroneous
# error:
#
# "error: each element of 'ext_modules' option must be an Extension instance or 2-tuple"
#
# ref: https://github.com/cython/cython/issues/4724
from setuptools import find_packages # isort: skip
from setuptools.command.build_ext import build_ext # isort: skip
from setuptools.extension import Extension # isort: skip
from Cython.Build import cythonize # isort: skip

includes: List[str] = [
np.get_include(),
]

libs: List[str] = [
"embree",
"tbb",
"tbbmalloc",
]

if os.name == "nt":
root = "C:/Program Files/Intel/Embree v2.17.7 x64"
cwd = os.path.abspath(os.path.expanduser(os.path.dirname(__file__)))
ext = ".dll"
else:
root = "/opt/local"
cwd = os.path.expanduser("~")
ext = ".so"

if os.path.exists(root):
# header files
shutil.copytree(
os.path.join(root, "include/embree2"),
os.path.join(cwd, "pyembree/embree2"),
dirs_exist_ok=True,
)

# static libraries
shutil.copytree(
os.path.join(root, "lib"),
os.path.join(cwd, "pyembree/embree2/lib"),
dirs_exist_ok=True,
)

# dynamic libraries
for lib in libs:
shutil.copy(
os.path.join(root, "bin", lib + ext),
os.path.join(cwd, "pyembree"),
)


includes.extend(os.path.join(cwd, "pyembree/embree2"))

static_libdirs: List[str] = [os.path.join(cwd, "pyembree/embree2/lib")]


def build(setup_kwargs: Dict[str, Any]) -> None:
ext_modules: List[Extension] = cythonize(
module_list="pyembree/*.pyx",
language_level=3,
include_path=includes,
)

for ext in ext_modules:
ext.include_dirs = includes
ext.libraries = libs
ext.library_dirs = static_libdirs

setup_kwargs.update(
{
"name": "pyembree",
"version": metadata.version("pyembree"),
"ext_modules": ext_modules,
"cmdclass": {"build_ext": build_ext},
"zip_safe": False,
"packages": find_packages(),
}
)
Loading

0 comments on commit 2f194be

Please sign in to comment.