Skip to content

Commit 8699df9

Browse files
committed
let setup script automatically download Eigen
1 parent ff769b6 commit 8699df9

File tree

2 files changed

+54
-24
lines changed

2 files changed

+54
-24
lines changed

.gitignore

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
# R/RStudio config files
2-
.Rproj.user
3-
.Rhistory
4-
.RData
5-
.Ruserdata
1+
# Config files
62

73
# Binary files
84
*.o
@@ -12,12 +8,12 @@
128
*.csv
139

1410
# Python cache and build files
15-
python/benchmark/benchmark_FairSVM/__cache__/
16-
python/benchmark/benchmark_SVM/__cache__/
17-
python/benchmark/benchmark_QR/__cache__/
18-
python/benchmark/benchmark_Huber/__cache__/
11+
**/__pycache__/
12+
build/
13+
rehline.egg-info/
14+
*.log
15+
16+
# Files during package building
17+
eigen-3.4.0/
18+
eigen3.zip
1919

20-
__pycache__/
21-
python/build/
22-
python/ReHLine.egg-info/
23-
*.log

setup.py

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
2-
import sys
3-
4-
from pybind11 import get_cmake_dir
5-
# Available at setup time due to pyproject.toml
1+
import os
2+
from pathlib import Path
3+
import zipfile
4+
import requests
65
from pybind11.setup_helpers import Pybind11Extension, build_ext
76
from setuptools import setup
87

@@ -17,22 +16,57 @@
1716
# Sort input source files if you glob sources to ensure bit-for-bit
1817
# reproducible builds (https://github.com/pybind/python_example/pull/53)
1918

19+
# The directory that contains setup.py
20+
SETUP_DIRECTORY = Path(__file__).resolve().parent
21+
22+
# Download Eigen source files
23+
# Modified from https://github.com/tohtsky/irspack/blob/main/setup.py
24+
class get_eigen_include(object):
25+
EIGEN3_URL = "https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.zip"
26+
EIGEN3_DIRNAME = "eigen-3.4.0"
27+
28+
def __str__(self) -> str:
29+
# Test whether the environment variable EIGEN3_INCLUDE_DIR is set
30+
# If yes, directly return this directory
31+
eigen_include_dir = os.environ.get("EIGEN3_INCLUDE_DIR", None)
32+
if eigen_include_dir is not None:
33+
return eigen_include_dir
34+
35+
# If the directory already exists (e.g. from previous setup),
36+
# directly return it
37+
target_dir = SETUP_DIRECTORY / self.EIGEN3_DIRNAME
38+
if target_dir.exists():
39+
return target_dir.name
40+
41+
# Filename for the downloaded Eigen source package
42+
download_target_dir = SETUP_DIRECTORY / "eigen3.zip"
43+
response = requests.get(self.EIGEN3_URL, stream=True)
44+
with download_target_dir.open("wb") as ofs:
45+
for chunk in response.iter_content(chunk_size=1024):
46+
ofs.write(chunk)
47+
# Unzip package
48+
with zipfile.ZipFile(download_target_dir) as ifs:
49+
ifs.extractall()
50+
51+
return target_dir.name
52+
2053
ext_modules = [
21-
Pybind11Extension("rehline",
54+
Pybind11Extension("rehline._internal",
2255
["src/rehline.cpp"],
56+
include_dirs=[get_eigen_include()],
2357
# Example: passing in the version to the compiled code
24-
define_macros = [('VERSION_INFO', __version__)],
58+
define_macros=[('VERSION_INFO', __version__)],
2559
),
2660
]
2761

2862
setup(
29-
name="ReHLine",
63+
name="rehline",
3064
version=__version__,
3165
author=["Ben Dai", "Yixuan Qiu"],
3266
author_email="[email protected]",
33-
url="https://github.com/softmin/ReHLine",
34-
description=" Minimizing Regularized Composite ReHU/ReLU Losses with Linear Computational Complexity ",
35-
long_description="https://github.com/softmin/ReHLine",
67+
url="https://github.com/softmin/ReHLine-python",
68+
description="Regularized Composite ReLU-ReHU Loss Minimization with Linear Computation and Linear Convergence",
69+
packages=["rehline"],
3670
ext_modules=ext_modules,
3771
# extras_require={"test": "pytest"},
3872
# Currently, build_ext only provides an optional "highest supported C++

0 commit comments

Comments
 (0)