-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
144 lines (127 loc) · 3.97 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from glob import glob
from setuptools import setup, find_namespace_packages
from distutils.dir_util import copy_tree
from pybind11.setup_helpers import Pybind11Extension
from pybind11.setup_helpers import ParallelCompile
import os
import pathlib
import platform
import shutil
import subprocess
import sysconfig
def run_cmd(cmd):
try:
output = subprocess.check_output(
cmd.split(" "), stderr=subprocess.STDOUT
).decode()
except subprocess.CalledProcessError as e:
output = e.output.decode()
raise RuntimeError(output)
return output.rstrip()
# Optional multithreaded build
ParallelCompile("NPY_NUM_BUILD_JOBS").install()
__version__ = open("VERSION", "r").read().strip()
extra_compile_args = sysconfig.get_config_var('CFLAGS').split()
extra_compile_args += [
"-g0",
"-Wall",
"-Wextra",
"-Werror",
"-DNDEBUG",
"-O3",
]
include_dirs = [
"adelie/src",
"adelie/src/include",
]
libraries = []
library_dirs = []
runtime_library_dirs = []
# check if conda environment activated
if "CONDA_PREFIX" in os.environ:
conda_prefix = os.environ["CONDA_PREFIX"]
# check if micromamba environment activated (CI)
elif "MAMBA_ROOT_PREFIX" in os.environ:
conda_prefix = os.path.join(os.environ["MAMBA_ROOT_PREFIX"], "envs/adelie")
else:
conda_prefix = None
# add include and include/eigen3
if not (conda_prefix is None):
conda_include_path = os.path.join(conda_prefix, "include")
eigen_include_path = os.path.join(conda_include_path, "eigen3")
include_dirs += [
conda_include_path,
eigen_include_path,
]
system_name = platform.system()
if system_name == "Darwin":
# if user provides OpenMP install prefix (containing include/ and lib/)
if "OPENMP_PREFIX" in os.environ and os.environ["OPENMP_PREFIX"] != "":
omp_prefix = os.environ["OPENMP_PREFIX"]
# else if conda environment is activated
elif not (conda_prefix is None):
omp_prefix = conda_prefix
# otherwise check brew installation
else:
# check if OpenMP is installed
no_omp_msg = (
"OpenMP is not detected. "
"MacOS users should either provide the OpenMP path via the environment variable OPENMP_PREFIX, "
"create a conda environment containing llvm-openmp, "
"or install Homebrew and run 'brew install libomp'. "
)
try:
libomp_info = run_cmd("brew info libomp")
except:
raise RuntimeError(no_omp_msg)
if "Not installed" in libomp_info:
raise RuntimeError(no_omp_msg)
# grab include and lib directory
omp_prefix = run_cmd("brew --prefix libomp")
omp_include = os.path.join(omp_prefix, "include")
omp_lib = os.path.join(omp_prefix, "lib")
# augment arguments
include_dirs += [omp_include]
extra_compile_args += [
"-Xpreprocessor",
"-fopenmp",
]
runtime_library_dirs += [omp_lib]
library_dirs += [omp_lib]
libraries += ['omp']
elif system_name == "Linux":
extra_compile_args += [
"-fopenmp",
"-march=native",
]
libraries += ['gomp']
ext_modules = [
Pybind11Extension(
"adelie.adelie_core",
sorted(glob("adelie/src/*.cpp")), # Sort source files for reproducibility
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
runtime_library_dirs=runtime_library_dirs,
libraries=libraries,
library_dirs=library_dirs,
cxx_std=17,
),
]
setup(
name='adelie',
version=__version__,
description='A fast, flexible package for group elastic net.',
long_description='',
author='James Yang',
author_email='jamesyang916@gmail.com',
maintainer='James Yang',
maintainer_email='jamesyang916@gmail.com',
packages=find_namespace_packages(include=["adelie.*"]),
package_data={
"adelie": [
"adelie_core.cpython*",
],
},
ext_modules=ext_modules,
zip_safe=False,
)