-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.py
More file actions
241 lines (194 loc) · 7.18 KB
/
Copy pathsetup.py
File metadata and controls
241 lines (194 loc) · 7.18 KB
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import errno
import os
import os.path
import shutil
import subprocess
import tarfile
from distutils import log
from distutils.command.build_clib import build_clib as _build_clib
from distutils.command.build_ext import build_ext as _build_ext
from distutils.errors import DistutilsError
from io import BytesIO
import sys
from setuptools import Distribution as _Distribution, setup, find_packages, __version__ as setuptools_version
from setuptools.command.develop import develop as _develop
from setuptools.command.egg_info import egg_info as _egg_info
from setuptools.command.sdist import sdist as _sdist
try:
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
except ImportError:
_bdist_wheel = None
pass
try:
from urllib2 import urlopen, URLError
except ImportError:
from urllib.request import urlopen
from urllib.error import URLError
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
from setup_support import absolute, build_flags, has_system_lib
# Version of libevmjit to download if none exists in the `libevmjit`
# directory
LIB_TARBALL_URL = "https://github.com/ethereum/evmjit/archive/v0.10.0-rc.1.tar.gz"
# We require setuptools >= 3.3
if [int(i) for i in setuptools_version.split('.')] < [3, 3]:
raise SystemExit(
"Your setuptools version ({}) is too old to correctly install this "
"package. Please upgrade to a newer version (>= 3.3).".format(setuptools_version)
)
# Ensure pkg-config is available
try:
subprocess.check_call(['pkg-config', '--version'])
except OSError:
raise SystemExit(
"'pkg-config' is required to install this package. "
"Please see the README for details."
)
def download_library(command):
if command.dry_run:
return
libdir = absolute("libevmjit")
if os.path.exists(os.path.join(libdir, "appveyor.yml")):
# Library already downloaded
return
if not os.path.exists(libdir):
command.announce("downloading libevmjit source code", level=log.INFO)
try:
r = urlopen(LIB_TARBALL_URL)
if r.getcode() == 200:
content = BytesIO(r.read())
content.seek(0)
with tarfile.open(fileobj=content) as tf:
dirname = tf.getnames()[0].partition('/')[0]
tf.extractall()
shutil.move(dirname, libdir)
else:
raise SystemExit(
"Unable to download evmjit library: HTTP-Status: %d",
r.getcode()
)
except URLError as ex:
raise SystemExit("Unable to download evmjit library: %s",
ex.message)
class egg_info(_egg_info):
def run(self):
# Ensure library has been downloaded (sdist might have been skipped)
download_library(self)
_egg_info.run(self)
class sdist(_sdist):
def run(self):
download_library(self)
_sdist.run(self)
if _bdist_wheel:
class bdist_wheel(_bdist_wheel):
def run(self):
download_library(self)
_bdist_wheel.run(self)
else:
bdist_wheel = None
class Distribution(_Distribution):
def has_c_libraries(self):
return not has_system_lib()
class build_clib(_build_clib):
def initialize_options(self):
_build_clib.initialize_options(self)
self.build_flags = None
def finalize_options(self):
_build_clib.finalize_options(self)
if self.build_flags is None:
self.build_flags = {
'include_dirs': [],
'library_dirs': [],
'define': [],
}
def get_source_files(self):
# Ensure library has been downloaded (sdist might have been skipped)
download_library(self)
return [
absolute(os.path.join(root, filename))
for root, _, filenames in os.walk(absolute("libevmjit"))
for filename in filenames
]
def build_libraries(self, libraries):
raise Exception("build_libraries")
def check_library_list(self, libraries):
raise Exception("check_library_list")
def get_library_names(self):
return build_flags('libevmjit', 'l', os.path.abspath(self.build_temp))
def run(self):
if has_system_lib():
log.info("Using system library")
return
build_temp = os.path.abspath(self.build_temp)
try:
os.makedirs(build_temp)
except OSError as e:
if e.errno != errno.EEXIST:
raise
subprocess.check_call(["cmake"], cwd=build_temp)
subprocess.check_call(["make"], cwd=build_temp)
subprocess.check_call(["make", "install"], cwd=build_temp)
subprocess.check_call(["ldconfig"], cwd=build_temp)
self.build_flags['include_dirs'].extend(build_flags('libevmjit', 'I', build_temp))
self.build_flags['library_dirs'].extend(build_flags('libevmjit', 'L', build_temp))
if not has_system_lib():
self.build_flags['define'].append(('CFFI_ENABLE_RECOVERY', None))
else:
pass
class build_ext(_build_ext):
def run(self):
if self.distribution.has_c_libraries():
build_clib = self.get_finalized_command("build_clib")
self.include_dirs.append(
os.path.join(build_clib.build_clib, "include"),
)
self.include_dirs.extend(build_clib.build_flags['include_dirs'])
self.library_dirs.append(
os.path.join(build_clib.build_clib, "lib"),
)
self.library_dirs.extend(build_clib.build_flags['library_dirs'])
self.define = build_clib.build_flags['define']
return _build_ext.run(self)
class develop(_develop):
def run(self):
if not has_system_lib():
raise DistutilsError(
"This library is not usable in 'develop' mode when using the "
"bundled libevmjit. See README for details.")
_develop.run(self)
setup(
name="evmjit",
version="0.1.1",
description='FFI bindings to libevmjit',
url='https://github.com/RomanZacharia/pyevmjit',
author='Roman Zacharia',
author_email='roman.zacharia@gmail.com',
license='MIT',
setup_requires=['cffi>=1.3.0', 'pytest-runner==2.6.2'],
install_requires=['cffi>=1.3.0'],
tests_require=['pytest==2.8.7'],
packages=find_packages(exclude=('_cffi_build', '_cffi_build.*', 'libevmjit')),
ext_package="evmjit",
cffi_modules=[
"_cffi_build/build.py:ffi"
],
cmdclass={
'build_clib': build_clib,
'build_ext': build_ext,
'develop': develop,
'egg_info': egg_info,
'sdist': sdist,
'bdist_wheel': bdist_wheel
},
distclass=Distribution,
zip_safe=False,
classifiers=[
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: Libraries",
"Topic :: Virtualization :: VM"
]
)