setup.py 7.61 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
with open('README.md', 'r') as f:
    long_description = f.read()

LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
67
68
69
70
71
72
73
74
75
76
77
78
# 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
79
80
81
82
83
84


#
# version management
#
MAJOR = '0'
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
85
86
MINOR = '0'
MICRO = '1'
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
87
88
89
90
91
92
93
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__


LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
94
def write_version_py(filename='py/unsiotools/version.py'):
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
95
96
97
98
99
100
101
102
103
104
105
106
    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()

LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
107

LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
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
# 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.*',
        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'
                      ],

LAMBERT Jean-charles's avatar
update    
LAMBERT Jean-charles committed
161
                      extra_compile_args = ['-O2','-std=c++03'],
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
162
163
164
165
166
167
                      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'],
168
                      library_dirs=['/usr/lib/x86_64-linux-gnu','/usr/lib64','/lib64',os.environ['HOME']+'/local/unsio/lib',
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
169
170
171
                                    os.environ['NEMO']+'/lib',
                                    os.environ['NEMO']+'/usr/dehnen/utils/lib',
                                    os.environ['NEMO']+'/usr/dehnen/falcON/lib'],
172
                      runtime_library_dirs=['/usr/lib/x86_64-linux-gnu','/usr/lib64','/lib64',os.environ['HOME']+'/local/unsio/lib',
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
173
174
175
176
177
                                            os.environ['NEMO']+'/lib',
                                            os.environ['NEMO']+'/usr/dehnen/utils/lib',
                                            os.environ['NEMO']+'/usr/dehnen/falcON/lib' ]
            )
        ],
178
179
180
181
182
183
184
185
186
187
188
189
        entry_points={
            "console_scripts": [
                "uns_2dplot.py   = unsiotools.simulations.c2dplot:commandLine",
                "uns_2dpgplot.py = unsiotools.simulations.c2dpgplot:commandLine",
                "merging_time.py = unsiotools.simulations.ccod:commandLineMT",
                "uns_cod.py      = unsiotools.simulations.ccod:commandLine",
                "uns_inert.py    = unsiotools.simulations.cinert:commandLine",
                "uns_plot_inert.py  = unsiotools.simulations.cplotinert:commandLine",
                "post_build_movie.py = unsiotools.simulations.cmovie:commandLine",
                "processing_analysis.py  = unsiotools.simulations.cuns_analysis:commandLine",
            ],
        },
LAMBERT Jean-charles's avatar
update    
LAMBERT Jean-charles committed
190
191
        #install_requires=['numpy'],
        #setup_requires=['numpy']
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
192
193
    )
    setup(**metadata)
194
195
196
197
198
    #
    #py_modules = ["py_baryc"]
    #data_files=[('',['src/numpy.i'])]


LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
199
200
201
202
# main
#
if __name__ == '__main__':
    setup_package()