setup.py 4.85 KB
Newer Older
1 2
import glob
import os
3
import sys
4 5 6
import re
import subprocess

7 8 9 10
from distutils import log
from distutils.core import setup
    
from distutils.core import Extension
11 12 13 14 15 16
from distutils.sysconfig import get_python_lib

import os.path
from distutils import log
from distutils.extension import Extension

17 18
from distutils.dist import Distribution as ori_Distribution

Celine Mercier committed
19 20
from python.obitools3.version import version

21

22 23 24 25 26 27 28 29 30 31 32 33 34
class Distribution(ori_Distribution):
    
    def __init__(self,attrs=None):
        self.cobitools3=attrs['cobitools3']
        
        ori_Distribution.__init__(self, attrs)
        
        self.global_options.insert(0,('cobitools3', None, "intall location of the C library"
                                     ))

from distutils.command.build import build as build_ori
from distutils.core import Command

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
class build_clib(Command):
    user_options=[]
    
    def initialize_options(self):
        self.clib_dir=self.distribution.cobitools3
    
    def finalize_options(self):
        if self.clib_dir is None:
            self.clib_dir=get_python_lib()
    
    def run(self):
        log.info("Build the build/cobject directory")
        try:
            os.mkdir("build")
        except OSError:
            pass
        try:
            os.mkdir("build/cobject")
        except OSError:
            pass
        
        oldwd = os.getcwd()
        os.chdir("build/cobject")
        install_clibdir_option="-DPYTHONLIB:STRING='%s'" % self.clib_dir
        log.info("Run CMake")
        subprocess.call(['cmake', install_clibdir_option, '../../src'])
        log.info("Compile the shared C library")
        subprocess.call(['make','install'])   # temporary fix but should be in src
        os.chdir(oldwd)
65

66 67 68 69 70 71 72

class build(build_ori):
    def run(self):
        self.run_command("build_clib")
        build_ori.run(self)


73 74
sys.path.append(os.path.abspath("python"))

75

76 77 78 79 80 81 82 83 84
def findPackage(root,base=None):
    modules=[]
    if base is None:
        base=[]
    for module in (os.path.basename(os.path.dirname(x)) 
                   for x in glob.glob(os.path.join(root,'*','__init__.py'))):
        modules.append('.'.join(base+[module]))
        modules.extend(findPackage(os.path.join(root,module),base+[module]))
    return modules
85
  
86 87

PACKAGE     = "OBITools3"
Celine Mercier committed
88
VERSION     = version
89 90
AUTHOR      = 'Celine Mercier'
EMAIL       = 'celine.mercier@metabarcoding.org'
91
URL         = "http://metabarcoding.org/obitools3"
92 93
LICENSE     = "CeCILL-V2"
DESCRIPTION = "Tools and library for DNA metabarcoding",
Celine Mercier committed
94
PYTHONMIN   = '3.5'
95 96 97 98

SRC       = 'python'
CSRC      = 'src'

99 100 101 102 103 104
REQUIRES  = ['Cython>=0.24',
             'Sphinx>=1.2.0',
             'ipython>=3.0.0',
             'breathe>=4.0.0'
            ]

Celine Mercier committed
105
os.environ['CFLAGS'] = '-O3 -w -I "src" -I "src/libecoPCR" -I "src/libjson"'
106 107


108 109
from Cython.Build import cythonize

110 111 112 113
cython_src  = [x for x in glob.iglob('python/obitools3/**/*.pyx', 
                                     recursive=True
                                    )
              ]
114
      
115 116 117

cython_ext  = [Extension('.'.join([os.path.dirname(x).replace("python/",""),
                                   os.path.splitext(os.path.basename(x))[0]]).replace('/','.'),
118 119 120 121 122 123
                         [x],
                         library_dirs=[get_python_lib()],
                         include_dirs=["src","src/libecoPCR","src/libjson"],
                         libraries=["cobitools3"],
                         runtime_library_dirs=[get_python_lib()],
                         extra_compile_args=['-msse2',
Celine Mercier committed
124
                                          '-w',
125 126 127 128 129 130 131 132 133 134 135
                                          '-fPIC'
                                         ],
                         extra_link_args=["-Wl,-rpath,"+get_python_lib(), 
                                          "-L"+get_python_lib()
                                         ]
                        )
                for x in cython_src
              ]              

xx = cythonize(cython_ext,
               language_level=3,
136 137
               annotate=True,
               build_dir="build")
138

139
classifiers=['Development Status :: 4 - Beta',
140 141 142 143 144
             'Environment :: Console',
             'Intended Audience :: Science/Research',
             'License :: Other/Proprietary License',
             'Operating System :: Unix',
             'Programming Language :: Python :: 3',
145
             'Programming Language :: C',
146 147 148 149
             'Topic :: Scientific/Engineering :: Bio-Informatics',
             'Topic :: Utilities',
             ]

150 151 152 153 154 155 156 157 158
setup(name=PACKAGE,
      description=DESCRIPTION,
      classifiers=classifiers,
      version=VERSION,
      author=AUTHOR,
      author_email=EMAIL,
      license=LICENSE,
      url=URL,
      ext_modules=xx,
159 160 161 162
      distclass=Distribution,
      cmdclass={'build': build,
                'build_clib': build_clib},
      cobitools3=get_python_lib(),
163 164
      packages = findPackage('python'),
      package_dir = {"" : "python"},
165
      scripts = ['scripts/obi']
166
)
167