forked from pyCGNS/pyCGNS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
520 lines (433 loc) · 17.7 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# -------------------------------------------------------------------------
# pyCGNS - Python package for CFD General Notation System
# See license.txt file in the root directory of this Python module source
# -------------------------------------------------------------------------
#
from __future__ import print_function
import os
import sys
import string
import argparse
import glob
import re
from setuptools import setup, Extension
# in the case the default python/distutils compiler fails with mpi, set
# this variable. You should check this compiler is the one used for HDF5 prod
# in the share/cmake config of your HDF5 installation.
CYTHON_COMPILER_FOR_MAP = 'mpicc'
# --- get overall configuration
sys.path = ['{}/lib'.format(os.getcwd())] + sys.path
from setuputils import (MAJOR_VERSION, MINOR_VERSION,
HAS_MSW, HAS_PY2, HAS_PY3,
log, line, is_windows, fix_path,
search, clean, touch,
ConfigException,
updateVersionInFile, installConfigFiles)
line('pyCGNS v{}.{} install'.format(MAJOR_VERSION, MINOR_VERSION))
line()
doc1 = """
pyCGNS installation setup
- Usual python setup options are unchanged (build, install, help...)
- The recommanded way to build is to set your shell environment with
your own PATH, LD_LIBRARY_PATH and PYTHONPATH so that the setup would
find all expected ressources itself.
- You can either use the command line args as described below or edit
the setup_userConfig.py with the values you want.
All packages are installed if all expected dependancies are found.
See doc for more installation details and depend:
https://pycgns.github.io/install.html
MPI: using HDF5 with parallel features adds dependancies on mpi. The
simple way to resolve these deps is to force mpicc instead of cc:
CC=mpicc python setup.py build
or edit the pyCGNS/stup.py file and change CYTHON_COMPILER_FOR_MAP
** IMPORTANT WARNING **
The *install* command runs the *build* as first step.
If you run first the *build* with specific options
you *SHOULD* add these options again in the *install*
command line unless you will have a *NEW* build.
"""
doc2 = """
Examples:
1. The best way is to let setup find out required stuff, build and
install. This would need write access to python installation dirs:
python setup.py install
2. You can build and install in two separate commands
python setup.py build
python setup.py install
3. Specific paths would be used prior to any automatic detection:
python setup.py build --includes=/usr/local/includes:/home/tools/include
4. Installation to a local directory (usual setup pattern)
python setup.py install --prefix=/home/myself/install
"""
def str2bool(value):
if value.lower() in ('yes', 'true', 't', 'y', '1'):
return True
elif value.lower() in ('no', 'false', 'f', 'n', '0'):
return False
else:
raise argparse.ArgumentTypeError('Boolean value expected.')
pr = argparse.ArgumentParser(description=doc1, epilog=doc2,
formatter_class=argparse.RawDescriptionHelpFormatter,
usage='python %(prog)s [options] file1 file2 ...')
pr.add_argument("-I", "--includes", dest="incs",
help='list of paths for include search ( : separated), order is significant and is kept unchanged')
pr.add_argument("-L", "--libraries", dest="libs",
help='list of paths for libraries search ( : separated), order is significant and is kept unchanged')
pr.add_argument("-U", "--update", action='store_true',
help='update version (dev only)')
pr.add_argument("-F", "--force", action='store_false',
help='skip all .pyx files regeneration')
pr.add_argument("-A", "--alternate", action='store_true',
help='use full h5py CGNS/HDF5 interface (ongoing work)')
modules = {"app": True, "map": True, "pat": True, "val": True, "nav": True}
for name, val in modules.items():
pr.add_argument("--" + name, type=str2bool, default=val,
help='enable/disable building of CGNS.' + name.upper())
for hstr in ['--help', '-h', 'help']:
if hstr in sys.argv:
pr.print_help()
sys.exit(1)
# Remove modules from command-line arguments
pr1 = argparse.ArgumentParser()
for name, val in modules.items():
pr1.add_argument("--" + name, type=str2bool, default=val)
args1, unknown = pr1.parse_known_args()
sys.argv = sys.argv[:1] + unknown
if 'help' in unknown:
pr.print_help()
sys.exit(1)
try:
os.makedirs('./build/lib/CGNS')
except OSError:
pass
if HAS_PY3:
log('found Python 3 platform')
else:
log('found Python 2 platform')
log('using Python from {}'.format(sys.prefix))
if HAS_MSW:
log('found Windows platform')
else:
log('found Unix platform')
APP = args1.app
MAP = args1.map
PAT = args1.pat
VAL = args1.val
NAV = args1.nav
ALL_PACKAGES = []
ALL_SCRIPTS = []
ALL_EXTENSIONS = []
OTHER_INCLUDES_PATHS = []
OTHER_LIBRARIES_PATHS = []
EXTRA_DEFINE_MACROS = []
if HAS_MSW:
EXTRA_DEFINE_MACROS = [('_HDF5USEDLL_', None), ('H5_BUILT_AS_DYNAMIC_LIB', None)]
module_logs = []
incs = []
libs = []
args, unknown = pr.parse_known_args()
if 'install' in unknown:
args.force = False
if args.incs is not None:
incs = [os.path.expanduser(path) for path in args.incs.split(os.path.pathsep)]
if args.libs is not None:
libs = [os.path.expanduser(path) for path in args.libs.split(os.path.pathsep)]
if args.alternate:
deps = ['Cython', 'h5py', 'numpy', 'vtk', 'qtpy']
else:
deps = ['Cython', 'HDF5', 'numpy', 'vtk', 'qtpy']
RUN_REQUIRES= ['numpy', 'future']
SETUP_REQUIRES = RUN_REQUIRES + ['cython>=0.25', 'pkgconfig']
# Remove crashing deps test
if 'sdist' in sys.argv:
deps = ['Cython', 'numpy','vtk','qtpy']
# Dirty patch
# Get required EGG if needed
import setuptools.dist
dist = setuptools.dist.Distribution(dict({'setup_requires': SETUP_REQUIRES}))
try:
(CONFIG, status) = search(incs, libs, deps=deps)
except ConfigException as e:
log('***** Cannot build pyCGNS without: {}'.format(e))
sys.exit(1)
# Fake HDF5 Config
if 'sdist' in sys.argv:
CONFIG.HDF5_HST = 1
CONFIG.HDF5_H64 = 1
CONFIG.HDF5_HUP = 1
CONFIG.HDF5_VERSION = "1.10.4"
CONFIG.HDF5_PARALLEL = 0
line()
new_args = []
for arg in sys.argv:
if (not ('-I=' in arg or '--includes=' in arg) and
not ('-U' in arg or '--update' in arg) and
not ('-A' in arg or '--alternate' in arg) and
not ('-F' in arg or '--force' in arg) and
not ('-L=' in arg or '--libraries=' in arg)):
new_args += [arg]
sys.argv = new_args
if args.update:
#os.system('hg parents --template="{rev}\n" > %s/revision.tmp' \
# % CONFIG.PRODUCTION_DIR)
# Quick and dirty revision, should use git describe --always instead
os.system(r'git rev-list --count HEAD> {}/revision.tmp'.format(CONFIG.PRODUCTION_DIR))
updateVersionInFile(fix_path('./lib/pyCGNSconfig_default.py'), CONFIG)
def hasToGenerate(source, destination, force):
return (force or not os.path.exists(destination) or
os.path.getmtime(source) > os.path.getmtime(destination))
def resolveVars(filename, confvalues, force):
if hasToGenerate(filename + '.in', filename, force):
with open('{}.in'.format(filename), 'r') as fg1:
l1 = fg1.readlines()
l2 = [ll.format(**confvalues) for ll in l1]
with open(filename, 'w') as fg2:
fg2.writelines(l2)
if args.force:
print('Generation of pyx not skipped')
else:
print('Skipping pyx generation')
# -------------------------------------------------------------------------
if APP:
slist = ['cg_grep', 'cg_list', 'cg_link', 'cg_iges', 'cg_diff',
'cg_checksum',
'cg_gather', 'cg_scatter', 'cg_dump',
'cg_scan']
if NAV:
slist += ['cg_look']
ALL_SCRIPTS += ['CGNS/APP/tools/%s' % f for f in slist]
ALL_EXTENSIONS += [Extension("CGNS.APP.lib.arrayutils",
["CGNS/APP/lib/arrayutils.pyx",
"CGNS/APP/lib/hashutils.c"],
include_dirs=CONFIG.INCLUDE_DIRS + OTHER_INCLUDES_PATHS,
extra_compile_args=[])]
ALL_PACKAGES += ['CGNS.APP',
'CGNS.APP.lib',
'CGNS.APP.tools',
'CGNS.APP.examples',
'CGNS.APP.misc',
'CGNS.APP.test']
module_logs.append("APP add build")
else:
module_logs.append("APP skip build *")
# -------------------------------------------------------------------------
if MAP:
if not CONFIG.HAS_H5PY:
# generate files
# CHLone_config.h.in -> CHLone_config.h
# pyCHLone.pyx.in -> pyCHLone.pyx
#
# --- config values
hdfplib = CONFIG.HDF5_PATH_LIBRARIES
hdflib = CONFIG.HDF5_LINK_LIBRARIES
hdfpinc = CONFIG.HDF5_PATH_INCLUDES
include_dirs = ['.'] + hdfpinc + CONFIG.INCLUDE_DIRS + OTHER_INCLUDES_PATHS
library_dirs = hdfplib
optional_libs = hdflib
extra_compile_args = CONFIG.HDF5_EXTRA_ARGS
extra_define_macro = EXTRA_DEFINE_MACROS
conf = {'CHLONE_HAS_PTHREAD': 1,
'CHLONE_HAS_REGEXP': 1,
'CHLONE_PRINTF_TRACE': 0,
'CHLONE_ON_WINDOWS': HAS_MSW,
'CHLONE_H5CONF_STD': CONFIG.HDF5_HST,
'CHLONE_H5CONF_64': CONFIG.HDF5_H64,
'CHLONE_H5CONF_UP': CONFIG.HDF5_HUP,
'HDF5_VERSION': CONFIG.HDF5_VERSION,
'CHLONE_INSTALL_LIBRARIES': "",
'CHLONE_INSTALL_INCLUDES': "",
}
depfiles = ['CGNS/MAP/CHLone_config.h', 'CGNS/MAP/EmbeddedCHLone.pyx']
EXTRA_MAP_COMPILE_ARGS = ''
resolveVars(fix_path(depfiles[0]), conf, args.force)
resolveVars(fix_path(depfiles[1]), conf, args.force)
library_dirs = [l for l in library_dirs if l != '']
# hack: actually shoudl read hdf5/cmake config to get true compiler...
if CONFIG.HDF5_PARALLEL:
os.environ['CC']=CYTHON_COMPILER_FOR_MAP
ALL_EXTENSIONS += [Extension("CGNS.MAP.EmbeddedCHLone",
["CGNS/MAP/EmbeddedCHLone.pyx",
"CGNS/MAP/SIDStoPython.c",
"CGNS/MAP/l3.c",
"CGNS/MAP/error.c",
"CGNS/MAP/linksearch.c",
"CGNS/MAP/sha256.c",
],
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=optional_libs,
depends=depfiles,
define_macros=extra_define_macro,
extra_compile_args=extra_compile_args)]
ALL_PACKAGES += ['CGNS.MAP', 'CGNS.MAP.test']
module_logs.append("MAP add build")
else:
module_logs.append("MAP skip build *")
# -------------------------------------------------------------------------
if VAL:
ALL_PACKAGES += ['CGNS.VAL',
'CGNS.VAL.grammars',
'CGNS.VAL.suite',
'CGNS.VAL.suite.SIDS',
'CGNS.VAL.parse',
'CGNS.VAL.test']
ALL_SCRIPTS += ['CGNS/VAL/CGNS.VAL']
if args.force:
touch("CGNS/VAL/grammars/CGNS_VAL_USER_SIDS_.pyx")
touch("CGNS/VAL/grammars/etablesids.pyx")
touch("CGNS/VAL/grammars/valutils.pyx")
ALL_EXTENSIONS += [Extension("CGNS.VAL.grammars.CGNS_VAL_USER_SIDS_",
["CGNS/VAL/grammars/CGNS_VAL_USER_SIDS_.pyx"],
include_dirs=CONFIG.INCLUDE_DIRS,
extra_compile_args=[])]
ALL_EXTENSIONS += [Extension("CGNS.VAL.grammars.etablesids",
["CGNS/VAL/grammars/etablesids.pyx"],
include_dirs=CONFIG.INCLUDE_DIRS,
extra_compile_args=[])]
ALL_EXTENSIONS += [Extension("CGNS.VAL.grammars.valutils",
["CGNS/VAL/grammars/valutils.pyx"],
include_dirs=CONFIG.INCLUDE_DIRS,
extra_compile_args=[])]
module_logs.append("VAL add build")
else:
module_logs.append("VAL skip build *")
# -------------------------------------------------------------------------
if PAT:
# if CONFIG.HAS_CYTHON:
# ALL_EXTENSIONS+=[ Extension('CGNS.PAT.cgnsutils',
# ['CGNS/PAT/cgnsutils.pyx'],
# include_dirs = CONFIG.INCLUDE_DIRS) ]
ALL_PACKAGES += ['CGNS.PAT',
'CGNS.PAT.SIDS',
'CGNS.PAT.test']
module_logs.append("PAT add build")
else:
module_logs.append("PAT skip build *")
# -------------------------------------------------------------------------
if NAV and CONFIG.HAS_QTPY:
cui = CONFIG.COM_UIC
crc = CONFIG.COM_RCC
ccy = CONFIG.COM_CYTHON
fakefile = "./CGNS/NAV/fake.pxi"
if args.force:
touch(fakefile)
modnamelist = [
'Q7TreeWindow',
'Q7DiffWindow',
'Q7MergeWindow',
'Q7ControlWindow',
'Q7OptionsWindow',
'Q7FormWindow',
'Q7FileWindow',
'Q7QueryWindow',
'Q7SelectionWindow',
'Q7InfoWindow',
'Q7DiagWindow',
'Q7LinkWindow',
'Q7HelpWindow',
'Q7ToolsWindow',
'Q7PatternWindow',
'Q7AnimationWindow',
'Q7MessageWindow',
'Q7LogWindow',
]
if CONFIG.HAS_VTK:
modnamelist += ['Q7VTKWindow']
modgenlist = []
modextlist = []
mfile_list = ['mtree', 'mquery', 'mcontrol', 'mtable', 'mpattern',
'diff', 'mdifftreeview', 'merge', 'mmergetreeview']
if CONFIG.HAS_VTK:
mfile_list += ['mparser']
for mfile in mfile_list:
if args.force:
touch("CGNS/NAV/%s.pyx" % mfile)
modextlist += [Extension("CGNS.NAV.%s" % mfile,
["CGNS/NAV/%s.pyx" % mfile ],
include_dirs=CONFIG.NUMPY_PATH_INCLUDES,
library_dirs=CONFIG.NUMPY_PATH_LIBRARIES,
libraries=CONFIG.NUMPY_LINK_LIBRARIES,
)]
for m in modnamelist:
modextlist += [Extension("CGNS.NAV.%s" % m,
["CGNS/NAV/G/%s.pyx" % m ],
include_dirs=CONFIG.NUMPY_PATH_INCLUDES,
library_dirs=CONFIG.NUMPY_PATH_LIBRARIES,
libraries=CONFIG.NUMPY_LINK_LIBRARIES,
)]
g = ("CGNS/NAV/T/{}.ui".format(m), "CGNS/NAV/G/{}.pyx".format(m))
if (('true' not in [cui, crc]) and hasToGenerate(g[0], g[1],
args.force)):
modgenlist += [m]
for m in modgenlist:
log('Generate from updated Qt templates ({}): {}'.format(cui, m))
com = "{} --from-imports -o CGNS/NAV/G/{}.pyx CGNS/NAV/T/{}.ui".format(cui, m, m)
#print(fix_path(com))
os.system(fix_path(com))
com = "{} -a CGNS/NAV/G/{}.pyx".format(ccy, m)
#print(fix_path(com))
os.system(fix_path(com))
if (hasToGenerate('CGNS/NAV/R/Res.qrc', 'CGNS/NAV/Res_rc.py', args.force)):
log('Generate from updated Qt Ressources ({}): Res_rc.py'.format(crc))
com = "{} -o CGNS/NAV/Res_rc.py CGNS/NAV/R/Res.qrc".format(crc)
os.system(fix_path(com))
ALL_PACKAGES += ['CGNS.NAV', 'CGNS.NAV.test']
ALL_EXTENSIONS += modextlist
if CONFIG.HAS_VTK:
module_logs.append("NAV add build (with VTK)")
else:
module_logs.append("NAV add build (without VTK)")
else:
module_logs.append("NAV skip build *")
installConfigFiles(CONFIG.PRODUCTION_DIR)
# -------------------------------------------------------------------------
if CONFIG.HAS_CYTHON:
from Cython.Distutils import build_ext
cmd = {'clean': clean, 'build_ext': build_ext}
else:
cmd = {'clean': clean}
for module_log in module_logs:
log(module_log)
line()
# --- Distutils metadata --------------------------------------------
cls_txt = \
"""
Development Status :: 3 - Alpha
Intended Audience :: Developers
Intended Audience :: Information Technology
Intended Audience :: Science/Research
License :: OSI Approved :: GNU LGPL
Programming Language :: Cython
Programming Language :: Python
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: Implementation :: CPython
Topic :: Scientific/Engineering
Topic :: Database
Topic :: Software Development :: Libraries :: Python Modules
Operating System :: Unix
Operating System :: POSIX :: Linux
Operating System :: MacOS :: MacOS X
Operating System :: Microsoft :: Windows
"""
# -------------------------------------------------------------------------
setup(
name=CONFIG.NAME,
version='{}.{}.{}'.format(MAJOR_VERSION, MINOR_VERSION, CONFIG.REVISION),
description=CONFIG.DESCRIPTION,
long_description=CONFIG.DESCRIPTION,
classifiers=[x for x in cls_txt.split("\n") if x],
author=CONFIG.AUTHOR,
author_email=CONFIG.EMAIL,
license=CONFIG.LICENSE,
url=CONFIG.URL,
packages=ALL_PACKAGES,
scripts=ALL_SCRIPTS,
ext_modules=ALL_EXTENSIONS,
cmdclass=cmd,
install_requires=RUN_REQUIRES,
setup_requires=SETUP_REQUIRES
)
# -------------------------------------------------------------------------
# --- last line