-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
69 lines (65 loc) · 2.88 KB
/
setup.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from glob import glob
from setuptools import setup, Extension
from distutils.command.build import build as build_orig
from setuptools.command.build_ext import build_ext as build_ext_orig
import itertools
import os
import subprocess
# set things up
this_dir = os.path.dirname(os.path.abspath(__file__))
compact_tree_h = os.path.join(this_dir, 'CompactTree', 'compact_tree.h')
compact_tree_version = [l for l in open(compact_tree_h) if l.strip().startswith('#define COMPACTTREE_VERSION')][0].split()[-1].replace('"','')
try:
python_include_dir = list(glob('/usr/include/python3*'))[0]
except:
raise RuntimeError("Unable to find python3* folder in /usr/include")
# fix pip install
def partition(pred, iterable):
t1, t2 = itertools.tee(iterable)
return itertools.filterfalse(pred, t1), filter(pred, t2)
class build(build_orig):
def finalize_options(self):
super().finalize_options()
condition = lambda el: el[0] == 'build_ext'
rest, sub_build_ext = partition(condition, self.sub_commands)
self.sub_commands[:] = list(sub_build_ext) + list(rest)
# run SWIG and compile
class build_ext(build_ext_orig):
def run(self):
subprocess.check_call(['swig', '-c++', '-python', 'CompactTree/compact_tree.i'])
subprocess.check_call(['g++', '-fpic', '-c', 'CompactTree/compact_tree.h', 'CompactTree/compact_tree_wrap.cxx', '-I%s' % python_include_dir])
subprocess.check_call(['g++', '-shared', 'compact_tree_wrap.o', '-o', 'CompactTree/_compact_tree.so', '-lstdc++'])
build_ext_orig.run(self)
# package info
setup(
name='CompactTree',
version=compact_tree_version,
author='Niema Moshiri',
author_email='[email protected]',
description='CompactTree: Lightweight header-only C++ library for loading and traversing trees',
long_description='CompactTree is a header-only C++ library for loading and traversing trees.',
long_description_content_type='text/markdown',
url='https://github.com/niemasd/CompactTree',
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
],
keywords='tree phylogenetics fast',
packages=['CompactTree'],
ext_modules=[Extension('_compact_tree', sources=['CompactTree/compact_tree_wrap.cxx'])],
cmdclass={'build_ext': build_ext, 'build': build},
include_package_data=True,
package_data={
'CompactTree': ['_compact_tree.so', 'compact_tree.py'],
},
zip_safe=False,
install_requires=[],
)