forked from spacetelescope/jwst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
177 lines (145 loc) · 4.69 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
import os
from os.path import basename
import subprocess
import sys
from setuptools import setup, find_packages, Extension, Command
from setuptools.command.test import test as TestCommand
from numpy import get_include as np_include
from glob import glob
if sys.version_info < (3, 5):
error = """
JWST 0.9+ does not support Python 2.x, 3.0, 3.1, 3.2, 3.3 or 3.4.
Beginning with JWST 0.9, Python 3.5 and above is required.
This may be due to an out of date pip
Make sure you have pip >= 9.0.1.
"""
sys.exit(error)
# hack building the sphinx docs with C source
from setuptools.command.build_ext import build_ext
try:
import sphinx
from sphinx.setup_command import BuildDoc
class BuildSphinx(BuildDoc):
"""Build Sphinx documentation after compiling C source files"""
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')
sphinx.build_main(['setup.py', '-b', 'html', './docs', './docs/_build/html'])
except ImportError:
class BuildSphinx(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
print('!\n! Sphinx is not installed!\n!', file=sys.stderr)
exit(1)
NAME = 'jwst'
SCRIPTS = [s for s in glob('scripts/*') if basename(s) != '__pycache__']
PACKAGE_DATA = {
'': [
'*.fits',
'*.txt',
'*.inc',
'*.cfg',
'*.csv',
'*.yaml',
'*.json'
]
}
def get_transforms_data():
# Installs the schema files in jwst/transforms
# Because the path to the schemas includes "stsci.edu" they
# can't be installed using setuptools.
transforms_schemas = []
root = os.path.join(NAME, 'transforms', 'schemas')
for node, dirs, files in os.walk(root):
for fname in files:
if fname.endswith('.yaml'):
transforms_schemas.append(
os.path.relpath(os.path.join(node, fname), root))
# In the package directory, install to the subdirectory 'schemas'
transforms_schemas = [os.path.join('schemas', s) for s in transforms_schemas]
return transforms_schemas
transforms_schemas = get_transforms_data()
PACKAGE_DATA['jwst.transforms'] = transforms_schemas
class PyTest(TestCommand):
def initialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = [NAME]
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
try:
import pytest
except ImportError:
print('Unable to run tests...')
print('To continue, please install "pytest":')
print(' pip install pytest')
exit(1)
errno = pytest.main(self.pytest_args)
sys.exit(errno)
if os.path.exists('relic'):
sys.path.insert(1, 'relic')
import relic.release
else:
try:
import relic.release
except ImportError:
try:
subprocess.check_call(['git', 'clone',
'https://github.com/jhunkeler/relic.git'])
sys.path.insert(1, 'relic')
import relic.release
except subprocess.CalledProcessError as e:
print(e)
exit(1)
version = relic.release.get_info()
relic.release.write_template(version, NAME)
entry_points = dict(asdf_extensions='jwst_pipeline = jwst.transforms.jwextension:JWSTExtension')
setup(
name=NAME,
version=version.pep386,
author='OED/SSB, etc',
author_email='[email protected]',
description='JWST',
url='http://ssb.stsci.edu',
license='BSD',
classifiers=[
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Software Development :: Libraries :: Python Modules',
],
python_requires='>=3.5',
scripts=SCRIPTS,
packages=find_packages(),
package_data=PACKAGE_DATA,
ext_modules=[
Extension('jwst.tweakreg.chelp',
glob('src/tweakreg/*.c'),
include_dirs=[np_include()],
define_macros=[('NUMPY', '1')]),
],
install_requires=[
'namedlist'
],
tests_require=[
'pytest',
'requests_mock'
],
cmdclass={
'test': PyTest,
'build_sphinx': BuildSphinx
},
entry_points=entry_points,
)