-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup.py
160 lines (141 loc) · 5.09 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import os
import sys
from subprocess import check_output
if len(os.environ.get('COVERAGE', '')) > 0:
MACROS = [("CYTHON_TRACE", "1"), ("CYTHON_TRACE_NOGIL", "1")]
COMPILER_DIRECTIVES = {"linetrace": True}
print("-" * 80)
print("Enabling linetracing for cython and setting CYTHON_TRACE = 1")
print("-" * 80)
else:
MACROS = []
COMPILER_DIRECTIVES = {}
MODE = 'normal'
if len(sys.argv) >= 2 and \
('--help' in sys.argv[1:] or
sys.argv[1] in ('--help-commands', 'egg_info', '--version',
'clean', 'sdist')):
MODE = 'info'
def get_basic_extensions():
if MODE == 'info':
try:
from Cython.Distutils import Extension
except ImportError:
from distutils.core import Extension
try:
import numpy
except ImportError:
include_dirs = []
else:
include_dirs = [numpy.get_include()]
else:
from Cython.Distutils import Extension
import numpy
include_dirs = [numpy.get_include()]
ext_modules = [
Extension(
name="cyarray.carray",
sources=["cyarray/carray.pyx"],
include_dirs=include_dirs,
),
]
return ext_modules
def create_sources():
argv = sys.argv
if 'build_ext' in argv or 'develop' in sys.argv or 'install' in argv:
generator = os.path.join('cyarray', 'generator.py')
cmd = [sys.executable, generator, os.path.abspath('cyarray')]
print(check_output(cmd).decode())
def _is_cythonize_default():
import warnings
result = True
with warnings.catch_warnings():
warnings.simplefilter("ignore")
try:
# old_build_ext was introduced in Cython 0.25 and this is when
# cythonize was made the default.
from Cython.Distutils import old_build_ext # noqa: F401
except ImportError:
result = False
return result
def setup_package():
from setuptools import find_packages, setup
if MODE == 'info':
cmdclass = {}
else:
from Cython.Distutils import build_ext
cmdclass = {'build_ext': build_ext}
create_sources()
# Extract the version information from pysph/__init__.py
info = {}
module = os.path.join('cyarray', '__init__.py')
exec(compile(open(module).read(), module, 'exec'), info)
# The requirements.
install_requires = [
'numpy', 'mako', 'Cython', 'setuptools>=6.0'
]
tests_require = ["pytest", "pytest-benchmark[histogram]"]
docs_require = ["sphinx"]
ext_modules = get_basic_extensions()
if MODE != 'info' and _is_cythonize_default():
# Cython >= 0.25 uses cythonize to compile the extensions. This
# requires the compile_time_env to be set explicitly to work.
compile_env = {}
include_path = set()
for mod in ext_modules:
compile_env.update(mod.cython_compile_time_env or {})
include_path.update(mod.include_dirs)
from Cython.Build import cythonize
ext_modules = cythonize(
ext_modules, compile_time_env=compile_env,
include_path=list(include_path),
compiler_directives=COMPILER_DIRECTIVES,
)
setup(name='cyarray',
version=info['__version__'],
author='Cyarray Developers',
author_email='[email protected]',
description='A fast, typed, resizable, Cython array.',
long_description=open('README.rst').read(),
url='http://github.com/pypr/cyarray',
license="BSD",
keywords="Cython array resizable",
packages=find_packages(),
package_data={
'': ['*.pxd', '*.mako', '*.rst']
},
# exclude package data in installation.
exclude_package_data={
'': ['Makefile', '*.bat', '*.cfg', '*.rst', '*.sh', '*.yml'],
},
ext_modules=ext_modules,
include_package_data=True,
cmdclass=cmdclass,
install_requires=install_requires,
extras_require={
"docs": docs_require,
"tests": tests_require,
"dev": docs_require + tests_require,
},
zip_safe=False,
platforms=['Linux', 'Mac OS-X', 'Unix', 'Windows'],
classifiers=[c.strip() for c in """\
Development Status :: 5 - Production/Stable
Environment :: Console
Intended Audience :: Developers
Intended Audience :: Science/Research
License :: OSI Approved :: BSD License
Natural Language :: English
Operating System :: MacOS :: MacOS X
Operating System :: Microsoft :: Windows
Operating System :: POSIX
Operating System :: Unix
Programming Language :: Python
Programming Language :: Python :: 3
Topic :: Scientific/Engineering
Topic :: Scientific/Engineering :: Physics
Topic :: Software Development :: Libraries
""".splitlines() if len(c.split()) > 0],
)
if __name__ == '__main__':
setup_package()