-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.py
93 lines (82 loc) · 2.77 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
from setuptools.extension import Extension
import numpy as np
from setuptools import setup, find_packages
import os.path as op
from os import getcwd
import sys
import glob
_numpy_abs = np.get_include() # get the numpy include path
def get_file_list(path, ext):
all_files = glob.glob(op.join(path, f"*{ext}"))
for file in all_files:
elem = op.split(file)
name = op.splitext(".".join(elem))[0]
yield name, [file]
npymath_path = op.normpath(op.join(_numpy_abs, '..', 'lib'))
npyrandom_path = op.normpath(op.join(_numpy_abs, '..', '..', 'random', 'lib'))
lib_path = [npymath_path, npyrandom_path]
if sys.platform == 'win32':
compile_args = ["/O2"]
elif sys.platform == 'linux':
compile_args = ["-O3"]
elif sys.platform == 'darwin':
compile_args = ["-O3"]
else:
raise NotImplementedError(f"Platform {sys.platform} not supported.")
try:
_numpy_abs = op.relpath(_numpy_abs, getcwd())
except ValueError:
pass
kwargs = dict(include_dirs=[_numpy_abs],
# includes for numpy
library_dirs=lib_path, # libraries to link
libraries=["npyrandom", "npymath"], # math library
extra_compile_args=compile_args, # compile optimization flag
language="c", # can be "c" or "c++"
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_22_API_VERSION")]
)
try:
from Cython.Build import cythonize
if not op.exists("ieeg/timefreq/hilbert.pyx"):
raise ImportError("Cython file not found.")
extensions = [
Extension(
"ieeg.calc._fast.*", # the module name exposed to python
['ieeg/calc/_fast/*.pyx'], # the Cython source file
**kwargs
),
Extension(
"ieeg.timefreq.hilbert", # the module name exposed to python
['ieeg/timefreq/hilbert.pyx'], # the Cython source file
**kwargs
)]
extensions = cythonize(extensions)
except ImportError:
USE_CYTHON = False
print("Cython not found. Using C files.")
if not op.exists("ieeg/timefreq/hilbert.c"):
ValueError("C file not found.")
extensions = [
Extension(name, source, **kwargs) for (name, source) in
get_file_list("ieeg/calc/_fast", ".c")]
extensions += [
Extension(
"ieeg.timefreq.hilbert", # the module name exposed to python
['ieeg/timefreq/hilbert.c'], # the Cython source file
**kwargs
),
]
setup(
name='ieeg',
version='0.6.0',
packages=find_packages(
where='.',
include=['ieeg*'],
),
package_dir={"": "."},
description='A Python package for iEEG data processing.',
author='Aaron Earle-Richardson',
author_email='ae166@duke.edu',
url='https://github.com/coganlab/IEEG_Pipelines',
ext_modules=extensions,
)