-
Notifications
You must be signed in to change notification settings - Fork 18
/
setup.py
executable file
·149 lines (110 loc) · 4.16 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python
# This file is adapted from the Astropy package template, which is licensed
# under a 3-clause BSD style license - see licenses/TEMPLATE_LICENSE.rst
# NOTE: The configuration for the package, including the name, version, and
# other information are set in the setup.cfg file.
import os
import sys
from setuptools import setup
def get_extensions():
from setuptools import Extension
import os
from extension_helpers import add_openmp_flags_if_available, pkg_config
import numpy as np
pkg_config_packages = ['gsl']
orig_kwargs = {
'sources': [
'src/bayestar_distance.c',
'src/bayestar_moc.c',
'src/bayestar_sky_map.c',
'src/core.c',
'src/cubic_interp.c',
'src/cubic_interp_test.c',
'src/find_floor.c',
],
'include_dirs': [
np.get_include()
],
'define_macros': [
('GSL_RANGE_CHECK_OFF', None),
('HAVE_INLINE', None),
('Py_LIMITED_API', 0x030A0000),
('NPY_TARGET_VERSION', 'NPY_1_23_API_VERSION'),
('NPY_NO_DEPRECATED_API', 'NPY_2_0_API_VERSION'),
],
'extra_compile_args': [
'-std=gnu11',
'-fvisibility=hidden'
],
}
if os.environ.get('LIGO_SKYMAP_USE_SYSTEM_CHEALPIX'):
pkg_config_packages.append('chealpix')
else:
orig_kwargs['include_dirs'].append('cextern/chealpix')
orig_kwargs['sources'].append('cextern/chealpix/chealpix.c')
if os.environ.get('LIGO_SKYMAP_USE_ITTNOTIFY'):
pkg_config_packages.append('ittnotify')
orig_kwargs['define_macros'].append(('WITH_ITTNOTIFY', 1))
kwargs = pkg_config(pkg_config_packages, [])
for key, orig_value in orig_kwargs.items():
kwargs.setdefault(key, []).extend(orig_value)
extension = Extension(name='ligo.skymap.core', language='c',
py_limited_api=True, **kwargs)
if not os.environ.get('LIGO_SKYMAP_DISABLE_OPENMP'):
add_openmp_flags_if_available(extension)
return [extension]
# First provide helpful messages if contributors try and run legacy commands
# for tests or docs.
TEST_HELP = """
Note: running tests is no longer done using 'python setup.py test'. Instead
you will need to run:
tox -e test
If you don't already have tox installed, you can install it with:
pip install tox
If you only want to run part of the test suite, you can also use pytest
directly with::
pip install -e .[test]
pytest
For more information, see:
http://docs.astropy.org/en/latest/development/testguide.html#running-tests
"""
if 'test' in sys.argv:
print(TEST_HELP)
sys.exit(1)
DOCS_HELP = """
Note: building the documentation is no longer done using
'python setup.py build_docs'. Instead you will need to run:
tox -e build_docs
If you don't already have tox installed, you can install it with:
pip install tox
You can also build the documentation with Sphinx directly using::
pip install -e .[docs]
cd docs
make html
For more information, see:
http://docs.astropy.org/en/latest/install.html#builddocs
"""
if 'build_docs' in sys.argv or 'build_sphinx' in sys.argv:
print(DOCS_HELP)
sys.exit(1)
VERSION_TEMPLATE = """
# Note that we need to fall back to the hard-coded version if either
# setuptools_scm can't be imported or setuptools_scm can't determine the
# version, so we catch the generic 'Exception'.
try:
from setuptools_scm import get_version
version = get_version(root='..', relative_to=__file__)
except Exception:
version = '{version}'
""".lstrip()
use_scm_version = {'write_to': 'ligo/skymap/version.py',
'write_to_template': VERSION_TEMPLATE}
# If we are building under the GitLab CI pipeline and we are building on the
# default branch, then disable the local part of the version
# (+g<short commit hash>) so that we can upload nightly builds to PyPI.
if (
os.environ.get('CI') == 'true' and
os.environ.get('CI_COMMIT_BRANCH') == os.environ['CI_DEFAULT_BRANCH']
):
use_scm_version['local_scheme'] = 'no-local-version'
setup(use_scm_version=use_scm_version, ext_modules=get_extensions())