-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.py
More file actions
193 lines (182 loc) · 8.51 KB
/
setup.py
File metadata and controls
193 lines (182 loc) · 8.51 KB
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
#!/usr/bin/env python3
# Copyright (C) 2005-25 Dr. Ralf Schlatterbeck Open Source Consulting.
# Reichergasse 131, A-3411 Weidling.
# Web: http://www.runtux.com Email: office@runtux.com
# ****************************************************************************
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ****************************************************************************
import sys
from setuptools import setup, Extension
sys.path.insert (1, '.')
from pga import __version__
if sys.version_info.major > 2 :
from subprocess import run, PIPE
from textwrap import dedent
from os import path, environ
from glob import glob
with open ('README.rst') as f :
description = f.read ()
if __version__.startswith ('0+'):
with open ('Version.h', 'w') as f:
print ('#define VERSION "%s"' % __version__, file = f)
with open ('pgapack/docs/user_guide.pdf', 'w') as f:
pass
license = 'BSD License'
pgapack_sources = []
stub = 'pgapack/source/mpi_stub.c'
pgapack_sources.extend (fn for fn in glob ('pgapack/source/*.c') if fn != stub)
# This is used to override the module to install from the module
# definitions below.
modulename = environ.get ('PGA_MODULE', 'module_from_pgapack_submodule')
# The default pgapack module: Use the version from the submodule pgapack
# that comes with pgapy.
module_from_pgapack_submodule = Extension \
( 'pga.pga'
, sources = ['pgamodule.c'] + pgapack_sources + [stub]
, define_macros = [('FAKE_MPI', '1')]
, include_dirs = ['.', 'pgapack/fakempi', 'pgapack/include']
, depends = ['pgapack/include/pgapack.h', 'pgapack/fakempi/mpi.h']
)
# example config for default pga home when installing pga from source
# contributed by Márk Váradi. You need to set the environment-variable
# 'PGA_MODULE' to 'module_from_source' if you want to use this setting.
BASE = '/usr/local/pga/' # default pga home in Linux machines
DEB_BASE = '/usr/include/pgapack-serial' # Default on Debian since lenny
module_from_source = Extension \
( 'pga.pga'
, sources = ['pgamodule.c']
, define_macros = []
, include_dirs = ['.', path.join (BASE, 'include'), DEB_BASE]
, libraries = [':libpgaO.a'] # you might need to adapt name of pga lib
, library_dirs = [path.join (BASE, 'lib/linux')]
)
# default config since debian lenny, serial version (installation in /usr):
# Set environment variable PGA_MODULE to 'module_from_install' if you
# want to use that version.
module_from_install = Extension \
( 'pga.pga'
, sources = ['pgamodule.c']
, define_macros = []
, include_dirs = ['.', '/usr/include/pgapack-serial']
, libraries = ['pgapack-serial']
)
# Parallel version. You need to specify PGA_PARALLEL_VARIANT in the
# environment, the default is 'mpich'.
# Note: The parallel version below is specific to python3 on debian-like
# distributions. Let me know if you want to build a parallel version on
# other architectures and we can figure out how to.
if modulename == 'module_from_parallel_install' and sys.version_info.major > 2 :
parallel_variant = environ.get ('PGA_PARALLEL_VARIANT', 'mpich')
result = run (['dpkg-architecture', '-qDEB_BUILD_GNU_TYPE'], stdout = PIPE)
arch_dir = result.stdout.decode ('utf-8').rstrip ()
arch_dir = path.join ('/usr/include', arch_dir)
include_by_variant = dict \
( mpich = path.join (arch_dir, 'mpich')
, lam = '/usr/include/lam'
, openmpi = path.join (arch_dir, 'openmpi')
)
module_from_parallel_install = Extension \
( 'pga.pga'
, sources = ['pgamodule.c']
, define_macros = []
, include_dirs = \
[ '.'
, '/usr/include/pgapack-' + parallel_variant
, include_by_variant [parallel_variant]
]
, libraries = ['pgapack-' + parallel_variant]
)
module1 = locals ()[modulename]
setup \
( name = 'PGAPy'
, version = __version__
, description = 'Python wrapper for pgapack, the parallel genetic '\
'algorithm library'
, long_description_content_type = 'text/x-rst'
, long_description = ''.join (description)
, ext_modules = [module1]
, packages = ['pga']
, data_files = [ ( 'share/pgapy/examples'
, [ 'examples/cards.py'
, 'examples/cards_mutate.py'
, 'examples/constraint.py'
, 'examples/dtlz2.py'
, 'examples/fourbar.py'
, 'examples/gears.py'
, 'examples/hello_world_char.py'
, 'examples/hello_world_int.py'
, 'examples/himmelblau.py'
, 'examples/magic_prio.py'
, 'examples/magic_square.py'
, 'examples/minfloat.py'
, 'examples/multi.py'
, 'examples/namefull.py'
, 'examples/one_max.py'
, 'examples/sort_numbers.py'
, 'examples/twobar.py'
, 'examples/vibr.py'
, 'examples/neural.py'
]
)
, ( 'share/pgapy/examples/gp'
, [ 'examples/gp/gp.py'
, 'examples/gp/opt_integral.py'
, 'examples/gp/opt_parity3.py'
, 'examples/gp/opt_xor.py'
, 'examples/gp/README.rst'
]
)
, ( 'share/pgapy/examples/sequence'
, [ 'examples/sequence/croes.tsp'
, 'examples/sequence/oliver30.tsp'
, 'examples/sequence/plot_tour.py'
, 'examples/sequence/tsp.py'
]
)
, ( 'share/pgapy'
, ['pgapack/docs/user_guide.pdf']
)
]
, author = "Ralf Schlatterbeck"
, author_email = "rsc@runtux.com"
, url = "https://github.com/schlatterbeck/pgapy"
, classifiers = \
[ 'Development Status :: 5 - Production/Stable'
, 'Intended Audience :: Developers'
, 'Intended Audience :: Education'
, 'Intended Audience :: Science/Research'
, 'License :: OSI Approved :: ' + license
, 'Operating System :: OS Independent'
, 'Programming Language :: C'
, 'Programming Language :: Python'
, 'Topic :: Education'
, 'Topic :: Scientific/Engineering'
, 'Topic :: Scientific/Engineering :: Artificial Intelligence'
, 'Topic :: Software Development :: Libraries'
, 'Topic :: Software Development :: Libraries :: Python Modules'
# Would be nice if distutils supported the following category -- it
# doesn't according to "python setup.py register --list-classifiers"
# , 'Topic :: Software Development :: Algorithms :: Genetic Algorithms'
]
)