-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathsetup.py
119 lines (101 loc) · 3.58 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import os
import sys
import shutil
from glob import glob
from setuptools import setup
from setuptools import Extension
use_system_qd = os.environ.get('USE_SYSTEM_QD', '')
have_windows = bool(sys.platform.startswith('win'))
have_darwin = bool(sys.platform == 'darwin')
have_linux = bool(sys.platform == 'linux')
qd_library_path = os.path.relpath(os.path.join('libqd'))
qd_library_c_path = os.path.join(qd_library_path, 'src')
qd_library_include_path = os.path.join(qd_library_path, 'include')
qd_sources = glob(os.path.join(qd_library_c_path, '*.cpp'))
def qd_config(arg):
result = ''
if not use_system_qd:
if arg == 'libs':
result = '' if have_windows else 'm'
elif arg == 'cflags':
result = qd_library_include_path
else:
if have_windows:
qdpath = os.environ.get('QD_PATH', '')
if not qdpath:
print('WINDOWS USERS:\n\n'
'Define QD_PATH to the prefix where "qd" '
'is installed:\n\n'
'set QD_PATH="x:\\prefix\\of\\qd"\n\n'
'Expected directory structure of QD_PATH:\n'
' QD_PATH\\lib\n'
' QD_PATH\\include\n\n', file=sys.stderr)
exit(1)
qdpath = os.path.abspath(qdpath)
if arg == 'libs':
result = '/LIBPATH:' + os.path.join(qdpath, 'lib')
result += ' qd.lib'
elif arg == 'cflags':
result = '-I' + os.path.join(qdpath, 'include')
else:
print('Unsupported option: {}'.format(arg), file=sys.stderr)
exit(1)
else:
from subprocess import check_output
if not shutil.which('qd-config'):
print('"qd-config" not found. Please install "qd" '
'(see: https://www.davidhbailey.com/dhbsoftware)',
file=sys.stderr)
exit(1)
result = check_output(['qd-config'] + ['--' + arg]).decode().strip()
return result.split()
try:
import numpy
except ImportError:
print('Missing requirement: numpy. Cannot continue.', file=sys.stderr)
exit(1)
PACKAGENAME = "spherical_geometry"
# Include all .c files, recursively, including those generated by
# Cython, since we can not do this in MANIFEST.in with a "dynamic"
# directory name.
c_files = []
for root, dirs, files in os.walk(PACKAGENAME):
for filename in files:
if filename.endswith('.c'):
c_files.append(
os.path.join(
os.path.relpath(root, PACKAGENAME), filename))
sources = [os.path.join('src', 'math_util.c')]
ext_info = {
'include_dirs': [numpy.get_include(), 'src'],
'libraries': [],
'extra_link_args': [],
'extra_compile_args': [],
'define_macros': [],
}
if not use_system_qd:
sources += qd_sources
ext_info['libraries'] += qd_config('libs')
ext_info['include_dirs'] += qd_config('cflags')
else:
ext_info['extra_link_args'] += qd_config('libs')
ext_info['extra_compile_args'] += qd_config('cflags')
if have_windows:
ext_info['define_macros'] += [
('_CRT_SECURE_NO_WARNINGS', None),
]
elif have_darwin:
ext_info['extra_link_args'] += [
'-mmacosx-version-min=10.9'
]
ext_info['extra_compile_args'] += [
'-mmacosx-version-min=10.9'
]
ext_info['language'] = 'c++'
setup(
ext_modules=[
Extension('spherical_geometry.math_util', sources, **ext_info)
],
)