Files
obitools3/setup.py

184 lines
5.4 KiB
Python
Raw Permalink Normal View History

import glob
import os
import sys
import re
import subprocess
2019-04-12 13:03:53 +02:00
from distutils import log
#from distutils.core import setup
from setuptools import setup # to work with pip
2019-04-12 13:03:53 +02:00
from distutils.core import Extension
from distutils.sysconfig import get_python_lib
import os.path
from distutils import log
from distutils.extension import Extension
2019-04-12 14:55:05 +02:00
from distutils.dist import Distribution as ori_Distribution
2019-12-12 17:03:13 +01:00
from python.obitools3.version import version
2019-04-12 14:55:05 +02:00
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, "install location of the C library"
2019-04-12 14:55:05 +02:00
))
from distutils.command.build import build as build_ori
from setuptools.command.bdist_egg import bdist_egg as bdist_egg_ori
2019-04-12 14:55:05 +02:00
from distutils.core import Command
2019-04-12 14:55:05 +02:00
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)
2019-04-12 14:55:05 +02:00
class build(build_ori):
def run(self):
self.run_command("build_clib")
build_ori.run(self)
class bdist_egg(bdist_egg_ori):
def run(self):
self.run_command('build_clib')
bdist_egg_ori.run(self)
sys.path.append(os.path.abspath("python"))
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
PACKAGE = "OBITools3"
2019-12-12 17:03:13 +01:00
VERSION = version
AUTHOR = 'Celine Mercier'
EMAIL = 'celine.mercier@metabarcoding.org'
2020-05-20 15:59:04 +02:00
URL = "https://metabarcoding.org/obitools3"
PLATFORMS = "posix"
LICENSE = "CeCILL-V2"
2020-05-20 15:59:04 +02:00
DESCRIPTION = "A package for the management of analyses and data in DNA metabarcoding."
2019-09-22 18:52:05 +02:00
PYTHONMIN = '3.5'
SRC = 'python'
CSRC = 'src'
REQUIRES = ['Cython>=0.24',
'Sphinx>=1.2.0',
'ipython>=3.0.0',
'breathe>=4.0.0'
]
2019-09-25 11:38:00 +02:00
os.environ['CFLAGS'] = '-O3 -w -I "src" -I "src/libecoPCR" -I "src/libjson"'
2019-04-12 13:03:53 +02:00
from Cython.Build import cythonize
cython_src = [x for x in glob.iglob('python/obitools3/**/*.pyx',
recursive=True
)
]
2019-03-31 16:19:05 +02:00
cython_ext = [Extension('.'.join([os.path.dirname(x).replace("python/",""),
os.path.splitext(os.path.basename(x))[0]]).replace('/','.'),
[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',
2019-09-25 11:38:00 +02:00
'-w',
'-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,
annotate=True,
build_dir="build")
classifiers=['Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: Science/Research',
'License :: Other/Proprietary License',
'Operating System :: Unix',
'Programming Language :: Python :: 3',
'Programming Language :: C',
'Topic :: Scientific/Engineering :: Bio-Informatics',
'Topic :: Utilities',
]
2020-05-20 15:59:04 +02:00
with open("README.md", "r") as fh:
long_description = fh.read()
setup(name=PACKAGE,
description=DESCRIPTION,
2020-05-20 15:59:04 +02:00
long_description=long_description,
long_description_content_type="text/markdown",
classifiers=classifiers,
version=VERSION,
author=AUTHOR,
author_email=EMAIL,
2020-05-20 15:59:04 +02:00
platforms=PLATFORMS,
license=LICENSE,
url=URL,
ext_modules=xx,
2019-04-12 14:55:05 +02:00
distclass=Distribution,
cmdclass={'build': build,
'bdist_egg': bdist_egg,
2019-04-12 14:55:05 +02:00
'build_clib': build_clib},
cobitools3=get_python_lib(),
packages = findPackage('python'),
package_dir = {"" : "python"},
scripts = ['scripts/obi']
)