~ubuntu-branches/ubuntu/precise/pyzmq/precise

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ożarowski
  • Date: 2011-02-15 09:08:36 UTC
  • mfrom: (2.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110215090836-phh4slym1g6muucn
Tags: 2.0.10.1-2
* Team upload.
* Upload to unstable
* Add Breaks: ${python:Breaks}

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#-----------------------------------------------------------------------------
25
25
 
26
26
import os, sys
 
27
from traceback import print_exc
27
28
 
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
30
34
 
31
35
from unittest import TextTestRunner, TestLoader
32
36
from glob import glob
33
 
from os.path import splitext, basename, join as pjoin, walk
34
 
 
 
37
from os.path import splitext, basename, join as pjoin
 
38
 
 
39
try:
 
40
    import nose
 
41
except ImportError:
 
42
    nose = None
 
43
 
 
44
try:
 
45
    from os.path import walk
 
46
except:
 
47
    from os import walk
 
48
 
 
49
#-----------------------------------------------------------------------------
 
50
# Flags
 
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
 
57
else:
 
58
    ignore_common_warnings=False
 
59
 
 
60
release = False # flag for whether to include *.c in package_data
35
61
 
36
62
#-----------------------------------------------------------------------------
37
63
# Extra commands
47
73
 
48
74
    def finalize_options(self):
49
75
        pass
50
 
 
51
 
    def run(self):
52
 
        """Finds all the tests modules in zmq/tests/, and runs them."""
 
76
    
 
77
    def run_nose(self):
 
78
        """Run the test suite with nose."""
 
79
        return nose.core.TestProgram(argv=["", '-vvs', pjoin(self._dir, 'zmq', 'tests')])
 
80
    
 
81
    def run_unittest(self):
 
82
        """Finds all the tests modules in zmq/tests/ and runs them."""
53
83
        testfiles = [ ]
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]])
 
88
                    ['zmq.tests', name])
58
89
                )
59
90
        tests = TestLoader().loadTestsFromNames(testfiles)
60
 
        t = TextTestRunner(verbosity = 1)
 
91
        t = TextTestRunner(verbosity = 2)
61
92
        t.run(tests)
 
93
    
 
94
    def run(self):
 
95
        """Run the test suite, with nose, or unittest if nose is unavailable"""
 
96
        # crude check for inplace build:
 
97
        try:
 
98
            import zmq
 
99
        except ImportError:
 
100
            print_exc()
 
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.")
 
104
            sys.exit(1)
 
105
        
 
106
        if nose is None:
 
107
            print ("nose unavailable, falling back on unittest. Skipped tests will appear as ERRORs.")
 
108
            return self.run_unittest()
 
109
        else:
 
110
            return self.run_nose()
62
111
 
63
112
 
64
113
class CleanCommand(Command):
67
116
    user_options = [ ]
68
117
 
69
118
    def initialize_options(self):
70
 
        self._clean_me = [pjoin('zmq', '_zmq.so') ]
 
119
        self._clean_me = []
71
120
        for root, dirs, files in os.walk('.'):
72
121
            for f in files:
73
 
                if f.endswith('.pyc'):
 
122
                if f.endswith('.pyc') or f.endswith('.so'):
74
123
                    self._clean_me.append(pjoin(root, f))
75
124
 
76
125
    def finalize_options(self):
83
132
            except:
84
133
                pass
85
134
 
 
135
 
 
136
class CheckSDist(sdist):
 
137
    """Custom sdist that ensures Cython has compiled all pyx files to c."""
 
138
 
 
139
    def initialize_options(self):
 
140
        sdist.initialize_options(self)
 
141
        self._pyxfiles = []
 
142
        for root, dirs, files in os.walk('.'):
 
143
            for f in files:
 
144
                if f.endswith('.pyx'):
 
145
                    self._pyxfiles.append(pjoin(root, f))
 
146
    def run(self):
 
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
 
152
        sdist.run(self)
 
153
 
 
154
class CheckingBuildExt(build_ext):
 
155
    """Subclass build_ext to get clearer report if Cython is neccessary."""
 
156
    
 
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):
 
161
                raise IOError('',
 
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.
 
165
                """%src)
 
166
    def build_extensions(self):
 
167
        self.check_cython_extensions(self.extensions)
 
168
        self.check_extensions_list(self.extensions)
 
169
 
 
170
        for ext in self.extensions:
 
171
            self.build_extension(ext)
 
172
 
 
173
#-----------------------------------------------------------------------------
 
174
# Suppress Common warnings
 
175
#-----------------------------------------------------------------------------
 
176
 
 
177
extra_flags = []
 
178
if ignore_common_warnings:
 
179
    for warning in ('unused-function', 'strict-aliasing'):
 
180
        extra_flags.append('-Wno-'+warning)
 
181
 
86
182
#-----------------------------------------------------------------------------
87
183
# Extensions
88
184
#-----------------------------------------------------------------------------
89
185
 
90
186
cmdclass = {'test':TestCommand}
91
187
 
 
188
includes = [pjoin('zmq', sub) for sub in ('utils','core','devices')]
 
189
 
 
190
def pxd(subdir, name):
 
191
    return os.path.abspath(pjoin('zmq', subdir, name+'.pxd'))
 
192
 
 
193
def pyx(subdir, name):
 
194
    return os.path.abspath(pjoin('zmq', subdir, name+'.pyx'))
 
195
 
 
196
def dotc(subdir, name):
 
197
    return os.path.abspath(pjoin('zmq', subdir, name+'.c'))
 
198
 
 
199
czmq = pxd('core', 'czmq')
 
200
allocate = pxd('utils', 'allocate')
 
201
buffers = pxd('utils', 'buffers')
 
202
 
 
203
submodules = dict(
 
204
    core = {'constants': [czmq],
 
205
            'error':[czmq],
 
206
            'poll':[czmq, allocate], 
 
207
            'stopwatch':[czmq],
 
208
            'context':[pxd('core', 'socket'), czmq],
 
209
            'message':[czmq, buffers],
 
210
            'socket':[pxd('core', 'context'), pxd('core', 'message'), 
 
211
                      czmq, allocate, buffers],
 
212
            'device':[czmq],
 
213
            'version':[czmq],
 
214
    },
 
215
    devices = {
 
216
            'monitoredqueue':[buffers, czmq],
 
217
    },
 
218
    utils = {
 
219
            'initthreads':[czmq]
 
220
    }
 
221
)
 
222
 
92
223
try:
93
224
    from Cython.Distutils import build_ext
94
225
except ImportError:
95
 
    zmq_source = os.path.join('zmq','_zmq.c')
 
226
    suffix = '.c'
 
227
    cmdclass['build_ext'] = CheckingBuildExt
96
228
else:
97
 
    zmq_source = os.path.join('zmq','_zmq.pyx')
 
229
    
 
230
    suffix = '.pyx'
 
231
    
 
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):
 
237
            pass
 
238
    
 
239
    cmdclass['cython'] = CythonCommand
98
240
    cmdclass['build_ext'] =  build_ext
 
241
    cmdclass['sdist'] =  CheckSDist
99
242
 
100
243
if sys.platform == 'win32':
101
244
    libzmq = 'libzmq'
102
245
else:
103
246
    libzmq = 'zmq'
104
247
 
105
 
zmq = Extension(
106
 
    'zmq._zmq',
107
 
    sources = [zmq_source],
108
 
    libraries = [libzmq]
109
 
)
110
 
 
 
248
extensions = []
 
249
for submod, packages in submodules.items():
 
250
    for pkg in sorted(packages):
 
251
        sources = [pjoin('zmq', submod, pkg+suffix)]
 
252
        if suffix == '.pyx':
 
253
            sources.extend(packages[pkg])
 
254
        ext = Extension(
 
255
            'zmq.%s.%s'%(submod, pkg),
 
256
            sources = sources,
 
257
            libraries = [libzmq],
 
258
            include_dirs = includes,
 
259
            extra_compile_args = extra_flags
 
260
        )
 
261
        extensions.append(ext)
 
262
 
 
263
#
 
264
package_data = {'zmq':['*.pxd'],
 
265
                'zmq.core':['*.pxd'],
 
266
                'zmq.devices':['*.pxd'],
 
267
                'zmq.utils':['*.pxd', '*.h'],
 
268
}
 
269
 
 
270
if release:
 
271
    for pkg,data in pkgdata.iteritems():
 
272
        data.append('*.c')
 
273
        
111
274
#-----------------------------------------------------------------------------
112
275
# Main setup
113
276
#-----------------------------------------------------------------------------
114
277
 
 
278
long_desc = \
 
279
"""
 
280
PyZMQ is a lightweight and super-fast messaging library built on top of
 
281
the ZeroMQ library (http://www.zeromq.org). 
 
282
"""
 
283
 
115
284
setup(
116
285
    name = "pyzmq",
117
 
    version = "0.1",
118
 
    packages = ['zmq', 'zmq.tests', 'zmq.eventloop'],
119
 
    ext_modules = [zmq],
 
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",
124
 
    cmdclass = cmdclass
 
298
    cmdclass = cmdclass,
 
299
    classifiers = [
 
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'
 
310
    ]
125
311
)
126
312