forked from pycurl/pycurl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix.py
214 lines (190 loc) · 9.17 KB
/
matrix.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
import os, os.path, subprocess, shutil, re
try:
from urllib.request import urlopen
except ImportError:
from urllib import urlopen
python_versions = ['2.4.6', '2.5.6', '2.6.8', '2.7.5', '3.1.5', '3.2.5', '3.3.5', '3.4.1']
libcurl_versions = ['7.19.0', '7.37.0']
# http://bsdpower.com/building-python-24-with-zlib/
patch_python_for_zlib = "sed -e 's/^#zlib/zlib/g' Modules/Setup >Modules/Setup.patched && mv Modules/Setup.patched Modules/Setup"
patch_python_for_ssl = "sed -e '/^#SSL/,/^$/s/^#//' -e 's/^#\*shared\*/*shared*/' Modules/Setup >Modules/Setup.patched && mv Modules/Setup.patched Modules/Setup"
python_meta = {
'2.4.6': {
'post-configure': [patch_python_for_zlib, patch_python_for_ssl],
},
'2.5.6': {
'patches': ['python25.patch'],
'post-configure': [patch_python_for_zlib, patch_python_for_ssl],
},
'3.0.1': {
'patches': ['python25.patch', 'python30.patch'],
},
}
libcurl_meta = {
'7.19.0': {
'patches': [
'curl-7.19.0-sslv2-c66b0b32fba-modified.patch',
#'curl-7.19.0-sslv2-2b0e09b0f98.patch',
],
},
}
root = os.path.abspath(os.path.dirname(__file__))
class in_dir:
def __init__(self, dir):
self.dir = dir
def __enter__(self):
self.oldwd = os.getcwd()
os.chdir(self.dir)
def __exit__(self, type, value, traceback):
os.chdir(self.oldwd)
def subprocess_check_call(cmd, **kwargs):
try:
subprocess.check_call(cmd, **kwargs)
except OSError as exc:
message = exc.args[0]
message = '%s while trying to execute %s' % (message, str(cmd))
args = tuple([message] + exc.args[1:])
raise type(exc)(args)
def fetch(url, archive=None):
if archive is None:
archive = os.path.basename(url)
if not os.path.exists(archive):
sys.stdout.write("Fetching %s\n" % url)
io = urlopen(url)
with open('.tmp.%s' % archive, 'wb') as f:
while True:
chunk = io.read(65536)
if len(chunk) == 0:
break
f.write(chunk)
os.rename('.tmp.%s' % archive, archive)
def build(archive, dir, prefix, meta=None):
if not os.path.exists(dir):
sys.stdout.write("Building %s\n" % archive)
subprocess_check_call(['tar', 'xf', archive])
with in_dir(dir):
if meta and 'patches' in meta:
for patch in meta['patches']:
patch_path = os.path.join(root, 'matrix', patch)
subprocess_check_call(['patch', '-p1', '-i', patch_path])
subprocess_check_call(['./configure', '--prefix=%s' % prefix])
if 'post-configure' in meta:
for cmd in meta['post-configure']:
subprocess_check_call(cmd, shell=True)
subprocess_check_call(['make'])
subprocess_check_call(['make', 'install'])
def patch_pycurl_for_24():
# change relative imports to old syntax as python 2.4 does not
# support relative imports
for root, dirs, files in os.walk('tests'):
for file in files:
if file.endswith('.py'):
path = os.path.join(root, file)
with open(path, 'r') as f:
contents = f.read()
contents = re.compile(r'^(\s*)from \. import', re.M).sub(r'\1import', contents)
contents = re.compile(r'^(\s*)from \.(\w+) import', re.M).sub(r'\1from \2 import', contents)
with open(path, 'w') as f:
f.write(contents)
def run_matrix(python_versions, libcurl_versions):
for python_version in python_versions:
url = 'http://www.python.org/ftp/python/%s/Python-%s.tgz' % (python_version, python_version)
archive = os.path.basename(url)
fetch(url, archive)
dir = archive.replace('.tgz', '')
prefix = os.path.abspath('i/%s' % dir)
build(archive, dir, prefix, meta=python_meta.get(python_version))
for libcurl_version in libcurl_versions:
url = 'http://curl.haxx.se/download/curl-%s.tar.gz' % libcurl_version
archive = os.path.basename(url)
fetch(url, archive)
dir = archive.replace('.tar.gz', '')
prefix = os.path.abspath('i/%s' % dir)
build(archive, dir, prefix, meta=libcurl_meta.get(libcurl_version))
fetch('https://raw.github.com/pypa/virtualenv/1.7/virtualenv.py', 'virtualenv-1.7.py')
fetch('https://raw.github.com/pypa/virtualenv/1.9.1/virtualenv.py', 'virtualenv-1.9.1.py')
if not os.path.exists('venv'):
os.mkdir('venv')
for python_version in python_versions:
python_version_pieces = [int(piece) for piece in python_version.split('.')[:2]]
for libcurl_version in libcurl_versions:
python_prefix = os.path.abspath('i/Python-%s' % python_version)
libcurl_prefix = os.path.abspath('i/curl-%s' % libcurl_version)
venv = os.path.abspath('venv/Python-%s-curl-%s' % (python_version, libcurl_version))
if os.path.exists(venv):
shutil.rmtree(venv)
if python_version_pieces >= [2, 5]:
fetch('https://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c11-py2.5.egg')
fetch('https://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg')
fetch('https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg')
# I had virtualenv 1.8.2 installed systemwide which
# did not work with python 3.0:
# http://stackoverflow.com/questions/14224361/why-am-i-getting-this-error-related-to-pip-and-easy-install-when-trying-to-set
# so, use known versions everywhere
# md5=89e68df89faf1966bcbd99a0033fbf8e
fetch('https://pypi.python.org/packages/source/d/distribute/distribute-0.6.49.tar.gz')
subprocess_check_call(['python', 'virtualenv-1.9.1.py', venv, '-p', '%s/bin/python%d.%d' % (python_prefix, python_version_pieces[0], python_version_pieces[1]), '--no-site-packages', '--never-download'])
else:
# md5=bd639f9b0eac4c42497034dec2ec0c2b
fetch('https://pypi.python.org/packages/2.4/s/setuptools/setuptools-0.6c11-py2.4.egg')
# md5=6afbb46aeb48abac658d4df742bff714
fetch('https://pypi.python.org/packages/source/p/pip/pip-1.4.1.tar.gz')
subprocess_check_call(['python', 'virtualenv-1.7.py', venv, '-p', '%s/bin/python' % python_prefix, '--no-site-packages', '--never-download'])
curl_config_path = os.path.join(libcurl_prefix, 'bin/curl-config')
curl_lib_path = os.path.join(libcurl_prefix, 'lib')
with in_dir('pycurl'):
extra_patches = []
extra_env = []
if python_version_pieces >= [2, 6]:
deps_cmd = 'pip install -r requirements-dev.txt'
elif python_version_pieces >= [2, 5]:
deps_cmd = 'pip install -r requirements-dev-2.5.txt'
else:
deps_cmd = 'easy_install nose simplejson==2.1.0'
patch_pycurl_for_24()
extra_env.append('PYCURL_STANDALONE_APP=yes')
extra_patches = ' && '.join(extra_patches)
extra_env = ' '.join(extra_env)
cmd = '''
make clean &&
. %(venv)s/bin/activate &&
%(deps_cmd)s && %(extra_patches)s
python -V &&
LD_LIBRARY_PATH=%(curl_lib_path)s PYCURL_CURL_CONFIG=%(curl_config_path)s %(extra_env)s make test
''' % dict(
venv=venv,
deps_cmd=deps_cmd,
extra_patches=extra_patches,
curl_lib_path=curl_lib_path,
curl_config_path=curl_config_path,
extra_env=extra_env
)
print(cmd)
subprocess_check_call(cmd, shell=True)
if __name__ == '__main__':
import sys
def main():
import optparse
parser = optparse.OptionParser()
parser.add_option('-p', '--python', help='Specify python version to test against')
parser.add_option('-c', '--curl', help='Specify libcurl version to test against')
options, args = parser.parse_args()
if options.python:
python_version = options.python
if python_version in python_versions:
chosen_python_versions = [python_version]
else:
chosen_python_versions = [v for v in python_versions if v.startswith(python_version)]
if len(chosen_python_versions) != 1:
raise Exception('Bogus python version requested: %s' % python_version)
else:
chosen_python_versions = python_versions
if options.curl:
chosen_libcurl_versions = [options.curl]
else:
chosen_libcurl_versions = libcurl_versions
run_matrix(chosen_python_versions, chosen_libcurl_versions)
if len(sys.argv) > 1 and sys.argv[1] == 'patch-24':
patch_pycurl_for_24()
else:
main()