|
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 |
6 | 5 | from pybind11.setup_helpers import Pybind11Extension, build_ext |
7 | 6 | from setuptools import setup |
8 | 7 |
|
|
17 | 16 | # Sort input source files if you glob sources to ensure bit-for-bit |
18 | 17 | # reproducible builds (https://github.com/pybind/python_example/pull/53) |
19 | 18 |
|
| 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 | + |
20 | 53 | ext_modules = [ |
21 | | - Pybind11Extension("rehline", |
| 54 | + Pybind11Extension("rehline._internal", |
22 | 55 | ["src/rehline.cpp"], |
| 56 | + include_dirs=[get_eigen_include()], |
23 | 57 | # Example: passing in the version to the compiled code |
24 | | - define_macros = [('VERSION_INFO', __version__)], |
| 58 | + define_macros=[('VERSION_INFO', __version__)], |
25 | 59 | ), |
26 | 60 | ] |
27 | 61 |
|
28 | 62 | setup( |
29 | | - name="ReHLine", |
| 63 | + name="rehline", |
30 | 64 | version=__version__, |
31 | 65 | author=["Ben Dai", "Yixuan Qiu"], |
32 | 66 | |
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"], |
36 | 70 | ext_modules=ext_modules, |
37 | 71 | # extras_require={"test": "pytest"}, |
38 | 72 | # Currently, build_ext only provides an optional "highest supported C++ |
|
0 commit comments