forked from glue-viz/glue
-
Notifications
You must be signed in to change notification settings - Fork 2
/
setupext.py
167 lines (122 loc) · 3.84 KB
/
setupext.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
"""
Some helper functions taken from matplotlib
"""
from __future__ import print_function
from distutils import version
from textwrap import fill
def print_line(char='='):
print(char * 76)
def print_status(package, status):
initial_indent = "%22s: " % package
indent = ' ' * 24
print(fill(str(status), width=76,
initial_indent=initial_indent,
subsequent_indent=indent))
def print_message(message):
indent = ' ' * 24 + "* "
print(fill(str(message), width=76,
initial_indent=indent,
subsequent_indent=indent))
def print_raw(section):
print(section)
def convert_qt_version(version):
version = '%x' % version
temp = []
while len(version) > 0:
version, chunk = version[:-2], version[-2:]
temp.insert(0, str(int(chunk, 16)))
return '.'.join(temp)
def check_for_qt4():
try:
from PyQt4 import pyqtconfig
except ImportError:
print_status("Qt4", "no")
return False
else:
print_status("Qt4", "Qt: %s, PyQt4: %s" %
(convert_qt_version(
pyqtconfig.Configuration().qt_version),
pyqtconfig.Configuration().pyqt_version_str))
return True
def check_for_pyside():
try:
from PySide import __version__
from PySide import QtCore
except ImportError:
print_status("PySide", "no")
return False
else:
print_status("PySide", "Qt: %s, PySide: %s" %
(QtCore.__version__, __version__))
return True
def check_for_numpy(min_version):
try:
import numpy
except ImportError:
print_status("numpy", "no")
print_message("You must install numpy %s or later to build glue." %
min_version)
return False
expected_version = version.LooseVersion(min_version)
found_version = version.LooseVersion(numpy.__version__)
if not found_version >= expected_version:
print_message(
'numpy %s or later is required; you have %s' %
(min_version, numpy.__version__))
return False
print_status("numpy", numpy.__version__)
return True
def check_warn_version(func):
def do_check(min_version=None):
#check if installed
found_version = func()
module = func.__name__.split('_')[-1]
if found_version is None:
print_status(module, 'no')
return False
print_status(module, found_version)
#check if recent enough
if min_version is None:
return True
expected = version.LooseVersion(min_version)
found = version.LooseVersion(found_version)
if not found >= expected:
print_message("%s %s or later recommended: you have %s" %
(module, min_version, found_version))
return False
return True
return do_check
def version_standard(mod):
"""Return version number of module by looking for module.__version__"""
try:
return __import__(mod).__version__
except ImportError:
return None
@check_warn_version
def check_for_scipy():
return version_standard('scipy')
@check_warn_version
def check_for_matplotlib():
return version_standard('matplotlib')
@check_warn_version
def check_for_astropy():
return version_standard('astropy')
@check_warn_version
def check_for_aplpy():
return version_standard('aplpy')
@check_warn_version
def check_for_ipython():
return version_standard('IPython')
@check_warn_version
def check_for_pil():
try:
from PIL import Image
return Image.VERSION
except ImportError:
return None
@check_warn_version
def check_for_pytest():
return version_standard('pytest')
@check_warn_version
def check_for_mock():
return version_standard('mock')