forked from anyoptimization/pymoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
191 lines (149 loc) · 5.88 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import distutils
import os
import sys
import traceback
from distutils.errors import CCompilerError, DistutilsExecError, DistutilsPlatformError
import setuptools
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
from pymoo.version import __version__
# ---------------------------------------------------------------------------------------------------------
# SETUP
# ---------------------------------------------------------------------------------------------------------
__name__ = "pymoo"
__author__ = "Julian Blank"
__url__ = "https://pymoo.org"
kwargs = dict(
name=__name__,
version=__version__,
author=__author__,
url=__url__,
python_requires='>=3.6',
author_email="[email protected]",
description="Multi-Objective Optimization in Python",
license='Apache License 2.0',
keywords="optimization",
install_requires=['numpy>=1.15', 'scipy>=1.1', 'matplotlib>=3', 'autograd>=1.3'],
packages=["pymoo"] + ["pymoo." + e for e in setuptools.find_packages(where='pymoo')],
platforms='any',
classifiers=[
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'Operating System :: OS Independent',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
'Topic :: Scientific/Engineering :: Mathematics'
]
)
# update the readme.rst to be part of setup
def readme():
with open('README.rst') as f:
return f.read()
kwargs['long_description'] = readme()
# ---------------------------------------------------------------------------------------------------------
# Extensions
# ---------------------------------------------------------------------------------------------------------
ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError, IOError)
def is_new_osx():
name = distutils.util.get_platform()
if sys.platform != "darwin":
return False
elif name.startswith("macosx-10"):
minor_version = int(name.split("-")[1].split(".")[1])
if minor_version >= 7:
return True
else:
return False
else:
return False
# fix compiling for new macosx!
if is_new_osx():
os.environ['CFLAGS'] = '-stdlib=libc++'
class BuildFailed(Exception):
pass
# try to compile, if not possible throw exception
def construct_build_ext(build_ext):
class WrappedBuildExt(build_ext):
def run(self):
try:
build_ext.run(self)
except DistutilsPlatformError as x:
raise BuildFailed(x)
def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except ext_errors as x:
raise BuildFailed(x)
return WrappedBuildExt
def run_setup(setup_args):
# try to add compilation to the setup - if fails just do default
try:
do_cythonize = False
if "--cythonize" in sys.argv:
do_cythonize = True
sys.argv.remove("--cythonize")
# copy the kwargs
kwargs = dict(setup_args)
kwargs['cmdclass'] = {}
try:
import numpy as np
kwargs['include_dirs'] = [np.get_include()]
except:
raise BuildFailed("NumPy libraries must be installed for compiled extensions! Speedups are not enabled.")
# return the object for building which allows installation with no compilation
kwargs['cmdclass']['build_ext'] = construct_build_ext(build_ext)
# all the modules must be finally added here
kwargs['ext_modules'] = []
cython_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "pymoo", "cython")
files = os.listdir(cython_folder)
if do_cythonize:
from Cython.Build import cythonize
kwargs['ext_modules'] = cythonize("pymoo/cython/*.pyx")
else:
cpp_files = [f for f in files if f.endswith(".cpp")]
if len(cpp_files) == 0:
print('*' * 75)
print("WARNING: No modules for compilation available. To compile pyx files, execute:")
print("make compile-with-cython")
print('*' * 75)
return
else:
for source in cpp_files:
kwargs['ext_modules'].append(
Extension("pymoo.cython.%s" % source[:-4], [os.path.join(cython_folder, source)]))
print("==========================")
if len(kwargs['ext_modules']) == 0:
print('*' * 75)
print("WARNING: No modules for compilation available. To compile pyx files, add --cythonize.")
print('*' * 75)
else:
# print(kwargs['ext_modules'])
setup(**kwargs)
print('*' * 75)
print("Compilation Successful.")
print("Installation with Compilation succeeded.")
print('*' * 75)
except BaseException as e:
setup(**setup_args)
ex_type, ex_value, ex_traceback = sys.exc_info()
print('*' * 75)
print("WARNING: Compilation Failed.")
print("WARNING:", ex_type)
print("WARNING:", ex_value)
print()
print("=" * 75)
traceback.print_exc()
print("=" * 75)
print()
print("WARNING: For the compiled libraries numpy is required. Please make sure they are installed")
print("WARNING: pip install numpy")
print("WARNING: Also, make sure you have a compiler for C++!")
print('*' * 75)
print("Plain Python installation succeeded.")
print('*' * 75)
run_setup(kwargs)