Skip to content

Commit

Permalink
Support use of system eigen
Browse files Browse the repository at this point in the history
  • Loading branch information
fbordeu committed Dec 2, 2024
1 parent d369b46 commit a11ef24
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
8 changes: 6 additions & 2 deletions eigency/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import os.path
from importlib.resources import as_file, files

import numpy as np

__eigen_dir__ = (files(__name__) / "eigen").__str__()

def get_eigency_eigen_dir():
from importlib.resources import files

return (files(__name__) / "eigen").__str__()


def get_includes(include_eigen=True):
root = os.path.dirname(__file__)
path = [root, np.get_include()]
if include_eigen:
__eigen_dir__ = get_eigency_eigen_dir()
path.append(os.path.join(root, __eigen_dir__))
return path
35 changes: 23 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@

sys.path.append(".")

import eigency # noqa: E402

__package_name__ = "eigency"
__eigen_dir__ = eigency.__eigen_dir__
__eigen_lib_dir__ = join(basename(__eigen_dir__), "Eigen")
include_dirs = [np.get_include()]
if "EIGEN_INC" in os.environ:
useSystemEigen = True
include_dirs.append(os.environ["EIGEN_INC"])
else:
useSystemEigen = False
import eigency # noqa: E402

__eigen_dir__ = eigency.get_eigency_eigen_dir()
__eigen_lib_dir__ = join(basename(__eigen_dir__), "Eigen")
include_dirs.append(__eigen_dir__)
# Not all users may have cython installed. If they only want this as a means
# to access the Eigen header files to compile their own C++ code, then they
# may not have cython already installed. Therefore, only require cython
Expand All @@ -37,14 +43,14 @@
Extension(
"eigency.conversions",
["eigency/conversions" + ext],
include_dirs=[np.get_include(), __eigen_dir__],
include_dirs=include_dirs,
language="c++",
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
),
Extension(
"eigency.core",
["eigency/core" + ext],
include_dirs=[np.get_include(), __eigen_dir__],
include_dirs=include_dirs,
language="c++",
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
),
Expand All @@ -61,10 +67,15 @@
long_description = open("README.md").read()

eigen_data_files = []
for root, dirs, files in os.walk(join(__eigen_dir__, "Eigen")):
for f in files:
if f.endswith(".h"):
eigen_data_files.append(join(root, f))

exclude_package_data = {}
if not useSystemEigen:
for root, dirs, files in os.walk(join(__eigen_dir__, "Eigen")):
for f in files:
if f.endswith(".h"):
eigen_data_files.append(join(root, f))
eigen_data_files.append(join(__eigen_lib_dir__, "*"))
exclude_package_data = {__package_name__: [join(__eigen_lib_dir__, "CMakeLists.txt")]}

setup(
name=__package_name__,
Expand All @@ -79,6 +90,6 @@
],
),
include_package_data=True,
package_data={__package_name__: ["*.h", "*.pxd", "*.pyx", join(__eigen_lib_dir__, "*")] + eigen_data_files},
exclude_package_data={__package_name__: [join(__eigen_lib_dir__, "CMakeLists.txt")]},
package_data={__package_name__: ["*.h", "*.pxd", "*.pyx"] + eigen_data_files},
exclude_package_data=exclude_package_data,
)

0 comments on commit a11ef24

Please sign in to comment.