This repository has been archived by the owner on May 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
setup.py
101 lines (84 loc) · 3.18 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# encoding: utf-8
#
# Copyright (C) 2015-2016 Tomasz Miasko
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
import sys
from setuptools import dist, setup, Extension
import subprocess
import versioneer
def content(path):
with open(path) as fh:
return fh.read()
def add_pkg_config(ext, package):
flags_map = {
'-I': ['include_dirs'],
'-L': ['library_dirs', 'runtime_library_dirs'],
'-l': ['libraries'],
}
try:
args = ['pkg-config', '--libs', '--cflags', package]
output = subprocess.check_output(args)
output = output.decode()
for flag in output.split():
for attr in flags_map[flag[:2]]:
getattr(ext, attr).append(flag[2:])
args = ['pkg-config', '--modversion', package]
output = subprocess.check_output(args, universal_newlines=True)
return output.strip()
except Exception as err:
print("Error while executing pkg-config: {}".format(err))
sys.exit(1)
def add_jags(ext):
version = add_pkg_config(ext, 'jags')
version = '"{}"'.format(version)
ext.define_macros.append(('PYJAGS_JAGS_VERSION', version))
def add_numpy(ext):
try:
import numpy
except ImportError:
sys.exit('Please install numpy first.')
ext.include_dirs.append(numpy.get_include())
def add_pybind11(ext):
ext.include_dirs.append('pybind11/include')
if __name__ == '__main__':
ext = Extension('pyjags.console',
language='c++',
sources=['pyjags/console.cc'])
add_jags(ext)
add_numpy(ext)
add_pybind11(ext)
setup(name='pyjags',
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
description='Python interface to JAGS library for Bayesian data analysis.',
long_description=content('README.rst'),
author=u'Tomasz Miąsko',
author_email='[email protected]',
url='https://github.com/tmiasko/pyjags',
license='GPLv2',
classifiers=[
'Development Status :: 4 - Beta',
'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',
'Operating System :: POSIX',
'Programming Language :: C++',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python',
'Topic :: Scientific/Engineering :: Information Analysis',
'Topic :: Scientific/Engineering',
],
packages=['pyjags'],
ext_modules=[ext],
install_requires=['numpy'],
test_suite='test')