forked from anyoptimization/pymoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
214 lines (163 loc) · 6.67 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import copy
import distutils
import os
import sys
import traceback
import setuptools
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
from pymoo.version import __version__
# ---------------------------------------------------------------------------------------------------------
# GENERAL
# ---------------------------------------------------------------------------------------------------------
__name__ = "pymoo"
__author__ = "Julian Blank"
__url__ = "https://pymoo.org"
data = 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', 'cma==2.7'],
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'
]
)
# ---------------------------------------------------------------------------------------------------------
# OTHER METADATA
# ---------------------------------------------------------------------------------------------------------
# update the readme.rst to be part of setup
def readme():
with open('README.rst') as f:
return f.read()
def packages():
return ["pymoo"] + ["pymoo." + e for e in setuptools.find_packages(where='pymoo')]
data['long_description'] = readme()
data['packages'] = packages()
# ---------------------------------------------------------------------------------------------------------
# Extensions
# ---------------------------------------------------------------------------------------------------------
# ============================================================
# MacOSX FIX for compiling modules
# ============================================================
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++'
# ============================================================
# Module for Compilation - Throws an Exception if Failing
# ============================================================
# exception that is thrown when the build fails
class CompilingFailed(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 BaseException as e:
raise CompilingFailed(e)
def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except BaseException as e:
raise CompilingFailed(e)
return WrappedBuildExt
# ============================================================
# SETUP
# ============================================================
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 for compiling purpose - if it fails setup_args remain unchanged
kwargs = copy.deepcopy(setup_args)
kwargs['cmdclass'] = {}
try:
import numpy as np
kwargs['include_dirs'] = [np.get_include()]
except BaseException:
raise CompilingFailed(
"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("pymoo", "cython")
cython_files = os.listdir(cython_folder)
# if the pyx files should be translated and then compiled
if do_cythonize:
from Cython.Build import cythonize
kwargs['ext_modules'] = cythonize("pymoo/cython/*.pyx")
# otherwise use the existing pyx files - normal case during pip installation
else:
# find all cpp files in czthon folder
cpp_files = [f for f in cython_files if f.endswith(".cpp")]
# add for each file an extension object to be compiled
for source in cpp_files:
ext = Extension("pymoo.cython.%s" % source[:-4], [os.path.join(cython_folder, source)])
kwargs['ext_modules'].append(ext)
if len(kwargs['ext_modules']) == 0:
print('*' * 75)
print("WARNING: No modules for compilation available. To compile pyx files, execute:")
print("make compile-with-cython")
print('*' * 75)
raise CompilingFailed()
setup(**kwargs)
print('*' * 75)
print("Compilation Successful.")
print("Installation with Compilation succeeded.")
print('*' * 75)
except BaseException:
# retrieve the original input arguments and execute default setup
kwargs = setup_args
setup(**kwargs)
# get information why compiling has failed
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(data)