Skip to content

Commit bf379a6

Browse files
add eigen package (#9)
Header-only Eigen 3.4.0 C++ linear algebra library, downloaded from GitLab release. Exposes INCLUDE_DIR for scons integration. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fcd4d49 commit bf379a6

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed

eigen/build.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
5+
cd "$DIR"
6+
7+
VERSION="3.4.0"
8+
INSTALL_DIR="$DIR/eigen/install"
9+
10+
# Idempotent: skip if already present
11+
if [ -d "$INSTALL_DIR/eigen3/Eigen" ]; then
12+
echo "eigen already present, skipping download."
13+
exit 0
14+
fi
15+
16+
TARBALL="eigen-${VERSION}.tar.gz"
17+
URL="https://gitlab.com/libeigen/eigen/-/archive/${VERSION}/${TARBALL}"
18+
19+
echo "Downloading Eigen ${VERSION} ..."
20+
curl -fSL -o "$TARBALL" "$URL"
21+
22+
echo "Extracting headers ..."
23+
rm -rf "$INSTALL_DIR"
24+
mkdir -p "$INSTALL_DIR/eigen3"
25+
26+
# Extract only the Eigen/ and unsupported/Eigen/ header directories
27+
tar --strip-components=1 -xzf "$TARBALL" -C "$INSTALL_DIR/eigen3" \
28+
"eigen-${VERSION}/Eigen" \
29+
"eigen-${VERSION}/unsupported"
30+
31+
rm -f "$TARBALL"
32+
33+
echo "Installed eigen to $INSTALL_DIR"
34+
du -sh "$INSTALL_DIR"

eigen/eigen/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import os
2+
3+
DIR = os.path.join(os.path.dirname(__file__), "install")
4+
INCLUDE_DIR = DIR
5+
LIB_DIR = DIR # header-only; no libraries
6+
7+
8+
def smoketest():
9+
assert os.path.isdir(os.path.join(DIR, "eigen3", "Eigen")), "Eigen headers not found"

eigen/pyproject.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[build-system]
2+
requires = ["setuptools>=64", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "eigen"
7+
version = "3.4.0"
8+
description = "Eigen C++ linear algebra headers"
9+
requires-python = ">=3.8"
10+
11+
[tool.setuptools.packages.find]
12+
include = ["eigen*"]
13+
14+
[tool.setuptools.package-data]
15+
eigen = ["install/**/*"]

eigen/setup.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import os
2+
import platform
3+
import subprocess
4+
5+
from setuptools.command.build_py import build_py
6+
7+
try:
8+
from wheel.bdist_wheel import bdist_wheel
9+
except ImportError:
10+
bdist_wheel = None
11+
12+
13+
class BuildEigen(build_py):
14+
"""Run build.sh to download Eigen headers before collecting package data."""
15+
16+
def run(self):
17+
pkg_dir = os.path.dirname(os.path.abspath(__file__))
18+
marker = os.path.join(pkg_dir, "eigen", "install", "eigen3", "Eigen")
19+
20+
if not os.path.isdir(marker):
21+
build_script = os.path.join(pkg_dir, "build.sh")
22+
subprocess.check_call(["bash", build_script], cwd=pkg_dir)
23+
24+
super().run()
25+
26+
27+
cmdclass = {"build_py": BuildEigen}
28+
29+
if bdist_wheel is not None:
30+
31+
class PlatformWheel(bdist_wheel):
32+
"""Produce a platform-specific, Python-version-agnostic wheel."""
33+
34+
def finalize_options(self):
35+
super().finalize_options()
36+
self.root_is_pure = False
37+
38+
def get_tag(self):
39+
system = platform.system()
40+
machine = platform.machine()
41+
42+
if system == "Linux":
43+
plat = f"linux_{machine}"
44+
elif system == "Darwin":
45+
plat = "macosx_11_0_arm64"
46+
else:
47+
plat = f"{system.lower()}_{machine}"
48+
49+
return "py3", "none", plat
50+
51+
cmdclass["bdist_wheel"] = PlatformWheel
52+
53+
54+
def setup():
55+
from setuptools import setup as _setup
56+
57+
_setup(cmdclass=cmdclass)
58+
59+
60+
if __name__ == "__main__":
61+
setup()

0 commit comments

Comments
 (0)