-
Notifications
You must be signed in to change notification settings - Fork 396
/
setup.py
208 lines (163 loc) · 6.43 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
import argparse
import copy
import sysconfig
import os
import sys
import traceback
from setuptools import setup, Extension, find_packages
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.9',
author_email="[email protected]",
description="Multi-Objective Optimization in Python",
license='Apache License 2.0',
keywords="optimization",
packages=find_packages(include=['pymoo', 'pymoo.*']),
include_package_data=True,
exclude_package_data={
'': ['*.c', '*.cpp', '*.pyx'],
},
install_requires=['numpy>=1.15',
'scipy>=1.1',
'matplotlib>=3',
'autograd>=1.4',
'cma>=3.2.2',
'alive-progress',
'dill',
'Deprecated'],
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.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'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()
data['long_description'] = readme()
data['long_description_content_type'] = 'text/x-rst'
# ---------------------------------------------------------------------------------------------------------
# OPTIONS
# ---------------------------------------------------------------------------------------------------------
parser = argparse.ArgumentParser()
parser.add_argument('--nopyx', dest='nopyx', action='store_true',
help='Whether the pyx files shall be considered at all.')
parser.add_argument('--nocython', dest='nocython', action='store_true', help='Whether pyx files shall be cythonized.')
parser.add_argument('--nolibs', dest='nolibs', action='store_true', help='Whether the libraries should be compiled.')
args, _ = parser.parse_known_args()
sys.argv = [e for e in sys.argv if not e.lstrip("-") in args]
# ============================================================
# MacOSX FIX for compiling modules
# ============================================================
def is_new_osx():
name = sysconfig.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
# ============================================================
ROOT = os.path.dirname(os.path.realpath(__file__))
backup = copy.deepcopy(data)
try:
if args.nopyx:
ext = []
elif args.nocython:
path = os.path.join(ROOT, "pymoo", "cython")
pyx = [os.path.join(path, f) for f in os.listdir() if f.endswith(".pyx")]
ext = [Extension(f"pymoo.cython.{source[:-4]}", [source]) for source in pyx]
else:
from Cython.Build import cythonize
ext = cythonize("pymoo/cython/*.pyx")
if not args.nolibs:
if len(ext) > 0:
data['ext_modules'] = ext
try:
import numpy as np
data['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
data['cmdclass'] = dict(build_ext=construct_build_ext(build_ext))
setup(**data)
print('*' * 75)
print("Compilation Successful.")
print("Installation with compiled libraries succeeded.")
print('*' * 75)
except BaseException:
# retrieve the original input arguments and execute default setup
setup(**backup)
# 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)