24
24
#-----------------------------------------------------------------------------
27
from traceback import print_exc
28
29
from distutils.core import setup, Command
30
from distutils.ccompiler import get_default_compiler
29
31
from distutils.extension import Extension
32
from distutils.command.sdist import sdist
33
from distutils.command.build_ext import build_ext
31
35
from unittest import TextTestRunner, TestLoader
32
36
from glob import glob
33
from os.path import splitext, basename, join as pjoin, walk
37
from os.path import splitext, basename, join as pjoin
45
from os.path import walk
49
#-----------------------------------------------------------------------------
51
#-----------------------------------------------------------------------------
52
# ignore unused-function and strict-aliasing warnings, of which there
53
# will be many from the Cython generated code:
54
# note that this is only for gcc-style compilers
55
if get_default_compiler() in ('unix', 'mingw32'):
56
ignore_common_warnings=True
58
ignore_common_warnings=False
60
release = False # flag for whether to include *.c in package_data
36
62
#-----------------------------------------------------------------------------
48
74
def finalize_options(self):
52
"""Finds all the tests modules in zmq/tests/, and runs them."""
78
"""Run the test suite with nose."""
79
return nose.core.TestProgram(argv=["", '-vvs', pjoin(self._dir, 'zmq', 'tests')])
81
def run_unittest(self):
82
"""Finds all the tests modules in zmq/tests/ and runs them."""
54
84
for t in glob(pjoin(self._dir, 'zmq', 'tests', '*.py')):
55
if not t.endswith('__init__.py'):
85
name = splitext(basename(t))[0]
86
if name.startswith('test_'):
56
87
testfiles.append('.'.join(
57
['zmq.tests', splitext(basename(t))[0]])
59
90
tests = TestLoader().loadTestsFromNames(testfiles)
60
t = TextTestRunner(verbosity = 1)
91
t = TextTestRunner(verbosity = 2)
95
"""Run the test suite, with nose, or unittest if nose is unavailable"""
96
# crude check for inplace build:
101
print ("Could not import zmq!")
102
print ("You must build pyzmq with 'python setup.py build_ext --inplace' for 'python setup.py test' to work.")
103
print ("If you did build pyzmq in-place, then this is a real error.")
107
print ("nose unavailable, falling back on unittest. Skipped tests will appear as ERRORs.")
108
return self.run_unittest()
110
return self.run_nose()
64
113
class CleanCommand(Command):
136
class CheckSDist(sdist):
137
"""Custom sdist that ensures Cython has compiled all pyx files to c."""
139
def initialize_options(self):
140
sdist.initialize_options(self)
142
for root, dirs, files in os.walk('.'):
144
if f.endswith('.pyx'):
145
self._pyxfiles.append(pjoin(root, f))
147
for pyxfile in self._pyxfiles:
148
cfile = pyxfile[:-3]+'c'
149
msg = "C-source file '%s' not found."%(cfile)+\
150
" Run 'setup.py cython' before sdist."
151
assert os.path.isfile(cfile), msg
154
class CheckingBuildExt(build_ext):
155
"""Subclass build_ext to get clearer report if Cython is neccessary."""
157
def check_cython_extensions(self, extensions):
158
for ext in extensions:
159
for src in ext.sources:
160
if not os.path.exists(src):
162
"""Cython-generated file '%s' not found.
163
Cython is required to compile pyzmq from a development branch.
164
Please install Cython or download a release package of pyzmq.
166
def build_extensions(self):
167
self.check_cython_extensions(self.extensions)
168
self.check_extensions_list(self.extensions)
170
for ext in self.extensions:
171
self.build_extension(ext)
173
#-----------------------------------------------------------------------------
174
# Suppress Common warnings
175
#-----------------------------------------------------------------------------
178
if ignore_common_warnings:
179
for warning in ('unused-function', 'strict-aliasing'):
180
extra_flags.append('-Wno-'+warning)
86
182
#-----------------------------------------------------------------------------
88
184
#-----------------------------------------------------------------------------
90
186
cmdclass = {'test':TestCommand}
188
includes = [pjoin('zmq', sub) for sub in ('utils','core','devices')]
190
def pxd(subdir, name):
191
return os.path.abspath(pjoin('zmq', subdir, name+'.pxd'))
193
def pyx(subdir, name):
194
return os.path.abspath(pjoin('zmq', subdir, name+'.pyx'))
196
def dotc(subdir, name):
197
return os.path.abspath(pjoin('zmq', subdir, name+'.c'))
199
czmq = pxd('core', 'czmq')
200
allocate = pxd('utils', 'allocate')
201
buffers = pxd('utils', 'buffers')
204
core = {'constants': [czmq],
206
'poll':[czmq, allocate],
208
'context':[pxd('core', 'socket'), czmq],
209
'message':[czmq, buffers],
210
'socket':[pxd('core', 'context'), pxd('core', 'message'),
211
czmq, allocate, buffers],
216
'monitoredqueue':[buffers, czmq],
93
224
from Cython.Distutils import build_ext
94
225
except ImportError:
95
zmq_source = os.path.join('zmq','_zmq.c')
227
cmdclass['build_ext'] = CheckingBuildExt
97
zmq_source = os.path.join('zmq','_zmq.pyx')
232
class CythonCommand(build_ext):
233
"""Custom distutils command subclassed from Cython.Distutils.build_ext
234
to compile pyx->c, and stop there. All this does is override the
235
C-compile method build_extension() with a no-op."""
236
def build_extension(self, ext):
239
cmdclass['cython'] = CythonCommand
98
240
cmdclass['build_ext'] = build_ext
241
cmdclass['sdist'] = CheckSDist
100
243
if sys.platform == 'win32':
101
244
libzmq = 'libzmq'
107
sources = [zmq_source],
249
for submod, packages in submodules.items():
250
for pkg in sorted(packages):
251
sources = [pjoin('zmq', submod, pkg+suffix)]
253
sources.extend(packages[pkg])
255
'zmq.%s.%s'%(submod, pkg),
257
libraries = [libzmq],
258
include_dirs = includes,
259
extra_compile_args = extra_flags
261
extensions.append(ext)
264
package_data = {'zmq':['*.pxd'],
265
'zmq.core':['*.pxd'],
266
'zmq.devices':['*.pxd'],
267
'zmq.utils':['*.pxd', '*.h'],
271
for pkg,data in pkgdata.iteritems():
111
274
#-----------------------------------------------------------------------------
113
276
#-----------------------------------------------------------------------------
280
PyZMQ is a lightweight and super-fast messaging library built on top of
281
the ZeroMQ library (http://www.zeromq.org).
118
packages = ['zmq', 'zmq.tests', 'zmq.eventloop'],
286
version = "2.0.10.1",
287
packages = ['zmq', 'zmq.tests', 'zmq.eventloop', 'zmq.log', 'zmq.core',
288
'zmq.devices', 'zmq.utils'],
289
ext_modules = extensions,
290
package_data = package_data,
120
291
author = "Brian E. Granger",
121
292
author_email = "ellisonbg@gmail.com",
122
description = "Cython based Python bindings for 0MQ.",
293
url = 'http://github.com/zeromq/pyzmq',
294
download_url = 'http://github.com/zeromq/pyzmq/downloads',
295
description = "Python bindings for 0MQ.",
296
long_description = long_desc,
123
297
license = "LGPL",
300
'Development Status :: 5 - Production/Stable',
301
'Intended Audience :: Developers',
302
'Intended Audience :: Financial and Insurance Industry',
303
'Intended Audience :: Science/Research',
304
'Intended Audience :: System Administrators',
305
'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
306
'Operating System :: MacOS :: MacOS X',
307
'Operating System :: Microsoft :: Windows',
308
'Operating System :: POSIX',
309
'Topic :: System :: Networking'