setup.py 4.36 KB
Newer Older
1 2 3
#!/usr/bin/env python

"""
4
UNSIO : Universal Nbody Snapshot Input Output
5 6 7

"""

LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
8 9 10 11
import numpy
import os
import sys
from setuptools import setup, Extension
12 13
from setuptools.command.build_py import build_py as _build_py

14

LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
15
#  find out numpy include directory.
16 17 18 19 20
try:
    numpy_include = numpy.get_include()
except AttributeError:
    numpy_include = numpy.get_numpy_include()

21 22 23
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.")

24
# detect python version (2 or 3)
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
25 26 27
pyversion = "3"
if sys.version_info[0] < 3:
    pyversion = ""
28

LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
29 30
with open('README.md', 'r') as f:
    long_description = f.read()
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
31

32 33 34
# 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
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
35
# 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
36

LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
37
class build_py(_build_py, object):
38 39
    def run(self):
        self.run_command("build_ext")
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
40 41 42
        if pyversion == "":  # python2
            return super(build_py, self).run()
        else:                # python3
43
            return super().run()
44

45

LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
46 47 48 49 50
#
# version management
#
MAJOR = '0'
MINOR = '9'
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
51
MICRO = '3rc2'
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
52 53 54 55 56
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__
57

LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
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

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()

#
# setup_package :
#

def setup_package():
    # generate version
    write_version_py()

    # metada for setup
    metadata = dict(
        # name='python'+pyversion+'-unsio',
        name='python-unsio',
        version=VERSION,
        description='A python wrapper to unsio',
        long_description=long_description,
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
87
        long_description_content_type='text/markdown',
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
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
        author='Jean-Charles LAMBERT',
        author_email='jean-charles.lambert@lam.fr',
        url='https://projets.lam.fr/projects/unsio',
        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=['unsio', 'unsio/test'],
        # cmdclass = {'install':Build_ext_first},
        # cmdclass={'build': CustomBuild, 'install': CustomInstall},
        cmdclass={'build_py': build_py},
        py_modules=['unsio/py_unsio'],
        ext_modules=[
            Extension("unsio/_py_unsio",
                      sources=["py/unsio/py_unsio.i"],
                      swig_opts=['-c++', '-modern', '-Isrc',
                                 '-I./py/unsio', '-Iswig'],
                      include_dirs=[numpy_include, 'src'],
                      libraries=['unsio'],
                      library_dirs=[os.environ['HOME']+'/local/unsio/lib',
                                    '/usr/lib64', '/lib64'],
                      runtime_library_dirs=[
                          os.environ['HOME']+'/local/unsio/lib', '/usr/lib64', '/lib64']
                      )
        ],
        entry_points={
            "console_scripts": [
                "test_unsio_lib = unsio.test.ctestunsio:commandLine",
            ],
        },
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
131
        install_requires=['numpy'],
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
132
        #setup_requires=['numpy']
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
133 134 135 136 137 138 139 140 141 142
        #
    )
    setup(**metadata)


#
# main
#
if __name__ == '__main__':
    setup_package()