setup.py 6.8 KB
Newer Older
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
#!/usr/bin/env python

"""

>> PACKAGING

Dependencies :
==============
apt-get install python3-stdeb fakeroot python3-all-dev python3-all swig python3-numpy python3-setuptools
apt-get install python-stdeb fakeroot python-all-dev python-all swig python-numpy python-setuptools libsqlite3-dev
( see https://pypi.org/project/stdeb/)

NEMO (https://github.com/teuben/nemo)
you must have NEMO package installed (especially falcON) to build this module

To build RPM :
==============
python3 setup.py  bdist_rpm --release 1mga6

To build deb package :
======================
python3 setup.py --command-packages=stdeb.command bdist_deb sdist_dsc --with-python2=True --with-python3=True --dist-dir=my_deb --debian-version 0ubuntu16.04

To build MacOSX :
=================
1) use clang compiler and python3
2) build
CC=/usr/bin/cc CXX=/usr/bin/c++ python3 setup.py build_ext -L ${HOME}/local/unsio/lib -R ${HOME}/local/unsio/lib
3) install locally
python3 setup.py install --user
4) set DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=${HOME}/local/unsio/lib

>> INSTALL

to install locally :
====================
python3 setup.py install --user


"""

#from distutils.core import setup, Extension
import numpy,os,sys
from setuptools import setup, Extension
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
46
from setuptools.command.build_py import build_py as _build_py
47
48


LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
49
#  find out numpy include directory.
50
51
52
53
54
55
try:
    numpy_include = numpy.get_include()
except AttributeError:
    numpy_include = numpy.get_numpy_include()

#DEHNEN=$ENV{NEMO}/usr/dehnen
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
56
57
if sys.version_info[:2] < (2, 7) or (3, 0) <= sys.version_info[:2] < (3, 4):
    raise RuntimeError("Python version 2.7 or >= 3.4 required.")
58
59
60
61
62
63

# detect python version (2 or 3)
pyversion="3"
if sys.version_info[0]<3 :
  pyversion=""

LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
64
65
66
67
68
69
70
71
72
73
74
75
# trick to add SWIG generated module
# see https://stackoverflow.com/questions/12491328/python-distutils-not-include-the-swig-generated-module
# and especially : https://stackoverflow.com/questions/29477298/setup-py-run-build-ext-before-anything-else/48942866#48942866
# and the fix for python2 https://stackoverflow.com/questions/1713038/super-fails-with-error-typeerror-argument-1-must-be-type-not-classobj-when/1713052#1713052

class build_py(_build_py, object):
    def run(self):
        self.run_command("build_ext")
        if pyversion == "":  # python2
            return super(build_py, self).run()
        else:                # python3
            return super().run()
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
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


#
# version management
#
MAJOR = '0'
MINOR = '9'
MICRO = '2rc2'
VERSION = '%s.%s.%s' % (MAJOR, MINOR, MICRO)

#
# write_version : write unsio version in py/unsio/version.py file
# it's imported from __init__.py as __version__


def write_version_py(filename='py/unsio/version.py'):
    cnt = """
# THIS FILE IS GENERATED FROM PYTHON-UNSIO SETUP.PY
#
version = '%(version)s'
"""
    a = open(filename, 'w')
    try:
        a.write(cnt % {'version': VERSION})

    finally:
        a.close()

s#
# setup_package :
#

def setup_package():
    # generate version
    write_version_py()

    # metada for setup
    metadata = dict(
        name='python-unsiotools',
        version=VERSION,
        description='Python wrapper to unsiotools',
        long_description=long_description,
        author='Jean-Charles LAMBERT',
        author_email='jean-charles.lambert@lam.fr',
        url='https://projets.lam.fr/projects/uns_projects',
        license='CeCILL2.1 (https://opensource.org/licenses/CECILL-2.1)',
        classifiers=[
            "Intended Audience :: Developers",
            "Intended Audience :: Science/Research",
            "Programming Language :: C",
            "Programming Language :: C++",
            "Programming Language :: Python",
            "Programming Language :: Python :: 2.7",
            "Programming Language :: Python :: 3.4",
            "Programming Language :: Python :: 3.5",
            "Programming Language :: Python :: 3.6",
            "Programming Language :: Python :: 3.7",
            "Topic :: Scientific/Engineering :: Astronomy",
            "Topic :: Software Development"],
        platforms=["Linux", "Mac OS-X", "Unix"],
        python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*',
        cmdclass={'build_py': build_py},
        package_dir={'':'py'}, # all packages are under 'py' directory
        packages=['unsiotools', 'unsiotools/simulations'],
        cmdclass={'build_py': build_py},
        py_modules=['unsiotools/py_unstools'],
        ext_modules = [
            Extension("unsiotools/_py_unstools",
                      sources=[ "py/unsiotools/py_unstools.i"],
                      swig_opts=['-c++','-modern', '-DNO_CUDA -DNOBOOST',
                                 '-Isrc','-I./py/unsiotools', '-Iswig','-Ilib/utils','-Ilib/utils/nemodep', '-Ilib/projects/nemodep'],
                      include_dirs = [numpy_include,'src',
                                      'lib/utils',
                                      'lib/utils/nemodep',
                                      'lib/projects/nemodep',
                                      os.environ['NEMO']+'/usr/dehnen/utils',
                                      os.environ['NEMO']+'/usr/dehnen/utils/inc',
                                      os.environ['NEMO']+'/usr/dehnen/falcON',
                                      os.environ['NEMO']+'/usr/dehnen/falcON/inc',
                                      os.environ['NEMO']+'/usr/dehnen/falcON/public',
                                      os.environ['NEMO']+'/inc'
                      ],

                      extra_compile_args = ['-O2'],
                      define_macros=[('NOBOOST',None),  # equivalent to -DNOBOOST
                                     ('falcON_SINGLE',None),
                                     ('falcON_NEMO',None),
                                     ('NO_CUDA',None) ],
                      # NOTE : libraries linking order is VERY important !!!
                      libraries=['JCLutils', 'JCLprojects','unsio',  'WDutils', 'falcON', 'nemo','cpgplot', 'pgplot','sqlite3','X11','gfortran'],
                      library_dirs=['/usr/lib64','/lib64',os.environ['HOME']+'/local/unsiotools/lib',
                                    os.environ['NEMO']+'/lib',
                                    os.environ['NEMO']+'/usr/dehnen/utils/lib',
                                    os.environ['NEMO']+'/usr/dehnen/falcON/lib'],
                      runtime_library_dirs=['/usr/lib64','/lib64',os.environ['HOME']+'/local/unsiotools/lib',
                                            os.environ['NEMO']+'/lib',
                                            os.environ['NEMO']+'/usr/dehnen/utils/lib',
                                            os.environ['NEMO']+'/usr/dehnen/falcON/lib' ]
            )
        ],
        install_requires=['numpy'],
        setup_requires=['numpy']
    )
    setup(**metadata)
180
181
182
183
184
    #
    #py_modules = ["py_baryc"]
    #data_files=[('',['src/numpy.i'])]


LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
185
186
187
188
# main
#
if __name__ == '__main__':
    setup_package()