forked from spacetelescope/drizzlepac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·227 lines (191 loc) · 6.66 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env python
from __future__ import print_function
import inspect
import os
import pkgutil
import shutil
import sys
try:
_mnfe = ModuleNotFoundError
except NameError:
ModuleNotFoundError = ImportError
try:
import pandokia
except (ImportError, NameError, ModuleNotFoundError):
pandokia = False
try:
import numpy
except ImportError:
print("numpy not found, please install it.", file=sys.stderr)
exit(1)
try:
from astropy import wcs
except ImportError:
print("astropy not found, please install it.", file=sys.stderr)
exit(1)
from glob import glob
from setuptools import setup, find_packages, Extension, _install_setup_requires
from setuptools.command.install import install
from subprocess import check_call, CalledProcessError
if not pkgutil.find_loader('relic'):
relic_local = os.path.exists('relic')
relic_submodule = (relic_local and
os.path.exists('.gitmodules') and
not os.listdir('relic'))
try:
if relic_submodule:
check_call(['git', 'submodule', 'update', '--init', '--recursive'])
elif not relic_local:
check_call(['git', 'clone', 'https://github.com/spacetelescope/relic.git'])
sys.path.insert(1, 'relic')
except CalledProcessError as e:
print(e)
exit(1)
import relic.release
NAME = 'drizzlepac'
SETUP_REQUIRES = [
'numpydoc',
'stsci_rtd_theme',
'sphinx',
'sphinx-automodapi',
'sphinx_rtd_theme',
],
version = relic.release.get_info()
relic.release.write_template(version, NAME)
# Setup C module include directories
include_dirs = []
numpy_includes = [numpy.get_include()]
wcs_includes = [os.path.join(wcs.get_include(), 'astropy_wcs'),
os.path.join(wcs.get_include(), 'wcslib')]
include_dirs.extend(numpy_includes)
include_dirs.extend(wcs_includes)
# Setup C module macros
define_macros = []
# Handle MSVC `wcsset` redefinition
if sys.platform == 'win32':
define_macros += [
('_CRT_SECURE_NO_WARNING', None),
('__STDC__', 1)
]
# Deprecation warning:
# Pandokia integration will be removed in a later release.
if pandokia:
fctx_includes = [os.path.join(os.path.dirname(pandokia.__file__),
'runners', 'maker')]
include_dirs.extend(fctx_includes)
# Due to overriding `install` and `build_sphinx` we need to download
# setup_requires dependencies before reaching `setup()`. This allows
# `sphinx` to exist before the `BuildSphinx` class is injected.
_install_setup_requires(dict(setup_requires=SETUP_REQUIRES))
# Distribute compiled documentation alongside the installed package
docs_compiled_src = os.path.normpath('build/sphinx/html')
docs_compiled_dest = os.path.normpath('{0}/htmlhelp'.format(NAME))
class InstallCommand(install):
"""Ensure drizzlepac's C extensions are available when imported relative
to the documentation, instead of relying on `site-packages`. What comes
from `site-packages` may not be the same drizzlepac that was *just*
compiled.
"""
def run(self):
build_cmd = self.reinitialize_command('build_ext')
build_cmd.inplace = 1
self.run_command('build_ext')
# Explicit request for old-style install? Just do it
if self.old_and_unmanageable or self.single_version_externally_managed:
install.run(self)
elif not self._called_from_setup(inspect.currentframe()):
# Run in backward-compatibility mode to support bdist_* commands.
install.run(self)
else:
self.do_egg_install()
if not os.path.exists(docs_compiled_dest):
print('\nwarning: Sphinx "htmlhelp" documentation was NOT bundled!\n'
' Execute the following then reinstall:\n\n'
' $ python setup.py build_sphinx\n\n',
file=sys.stderr)
from sphinx.cmd.build import build_main
from sphinx.setup_command import BuildDoc
class BuildSphinx(BuildDoc):
"""Build Sphinx documentation after compiling C extensions"""
description = 'Build Sphinx documentation'
def initialize_options(self):
BuildDoc.initialize_options(self)
def finalize_options(self):
BuildDoc.finalize_options(self)
def run(self):
build_cmd = self.reinitialize_command('build_ext')
build_cmd.inplace = 1
self.run_command('build_ext')
build_main(['-b', 'html', 'doc/source', 'build/sphinx/html'])
# Bundle documentation inside of drizzlepac
if os.path.exists(docs_compiled_src):
if os.path.exists(docs_compiled_dest):
shutil.rmtree(docs_compiled_dest)
shutil.copytree(docs_compiled_src, docs_compiled_dest)
setup(
name=NAME,
version=version.pep386,
author='Megan Sosey, Warren Hack, Christopher Hanley, '
'Chris Sontag, Mihai Cara',
author_email='[email protected]',
description='drizzle tools: combines astronomical images, including '
'modeling distortion, removing cosmic rays, and generally '
'improving fidelity of data in the final image',
url='https://github.com/spacetelescope/drizzlepac',
classifiers=[
'Intended Audience :: Science/Research',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Scientific/Engineering :: Astronomy',
'Topic :: Software Development :: Libraries :: Python Modules',
],
setup_requires=SETUP_REQUIRES,
install_requires=[
'astropy',
'fitsblender',
'nictools',
'nose',
'numpy',
'scipy',
'spherical_geometry',
'stsci.tools',
'stsci.convolve',
'stsci.image>=2.3.0',
'stsci.imagemanip',
'stsci.imagestats',
'stsci.ndimage',
'stsci.skypac',
'stsci.stimage',
'stwcs',
'stregion',
],
packages=find_packages(),
package_data={
'drizzlepac': [
'pars/*',
'*.help',
'htmlhelp/*',
'htmlhelp/_*/*',
'htmlhelp/_*/*/*',
]
},
entry_points={
'console_scripts': [
'mdriz=drizzlepac.mdriz:main',
'resetbits=drizzlepac.resetbits:main',
'updatenpol=drizzlepac.updatenpol:main',
'runastrodriz=drizzlepac.runastrodriz:main'
],
},
ext_modules=[
Extension('drizzlepac.cdriz',
glob('src/*.c'),
include_dirs=include_dirs,
define_macros=define_macros),
],
cmdclass={
'install': InstallCommand,
'build_sphinx': BuildSphinx,
},
)