setup.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #
  2. # Imports
  3. #
  4. import os
  5. import sys
  6. import glob
  7. from distutils.core import setup, Extension
  8. if sys.version_info < (2, 4, 0):
  9. raise ValueError, 'Versions of Python before 2.4 are not supported'
  10. #
  11. # Macros and libraries
  12. #
  13. # The `macros` dict determines the macros that will be defined when
  14. # the C extension is compiled. Each value should be either 0 or 1.
  15. # (An undefined macro is assumed to have value 0.) `macros` is only
  16. # used on Unix platforms.
  17. #
  18. # The `libraries` dict determines the libraries to which the C
  19. # extension will be linked. This should probably be either `['rt']`
  20. # if you need `librt` or else `[]`.
  21. #
  22. # Meaning of macros
  23. #
  24. # HAVE_SEM_OPEN
  25. # Set this to 1 if you have `sem_open()`. This enables the use of
  26. # posix named semaphores which are necessary for the
  27. # implementation of the synchronization primitives on Unix. If
  28. # set to 0 then the only way to create synchronization primitives
  29. # will be via a manager (e.g. "m = Manager(); lock = m.Lock()").
  30. #
  31. # HAVE_SEM_TIMEDWAIT
  32. # Set this to 1 if you have `sem_timedwait()`. Otherwise polling
  33. # will be necessary when waiting on a semaphore using a timeout.
  34. #
  35. # HAVE_FD_TRANSFER
  36. # Set this to 1 to compile functions for transferring file
  37. # descriptors between processes over an AF_UNIX socket using a
  38. # control message with type SCM_RIGHTS. On Unix the pickling of
  39. # of socket and connection objects depends on this feature.
  40. #
  41. # If you get errors about missing CMSG_* macros then you should
  42. # set this to 0.
  43. #
  44. # HAVE_BROKEN_SEM_GETVALUE
  45. # Set to 1 if `sem_getvalue()` does not work or is unavailable.
  46. # On Mac OSX it seems to return -1 with message "[Errno 78]
  47. # Function not implemented".
  48. #
  49. # HAVE_BROKEN_SEM_UNLINK
  50. # Set to 1 if `sem_unlink()` is unnecessary. For some reason this
  51. # seems to be the case on Cygwin where `sem_unlink()` is missing
  52. # from semaphore.h.
  53. #
  54. if sys.platform == 'win32': # Windows
  55. macros = dict()
  56. libraries = ['ws2_32']
  57. elif sys.platform == 'darwin': # Mac OSX
  58. macros = dict(
  59. HAVE_SEM_OPEN=1,
  60. HAVE_SEM_TIMEDWAIT=0,
  61. HAVE_FD_TRANSFER=1,
  62. HAVE_BROKEN_SEM_GETVALUE=1
  63. )
  64. libraries = []
  65. elif sys.platform == 'cygwin': # Cygwin
  66. macros = dict(
  67. HAVE_SEM_OPEN=1,
  68. HAVE_SEM_TIMEDWAIT=1,
  69. HAVE_FD_TRANSFER=0,
  70. HAVE_BROKEN_SEM_UNLINK=1
  71. )
  72. libraries = []
  73. else: # Linux and other unices
  74. macros = dict(
  75. HAVE_SEM_OPEN=1,
  76. HAVE_SEM_TIMEDWAIT=1,
  77. HAVE_FD_TRANSFER=1
  78. )
  79. libraries = ['rt']
  80. #macros['Py_DEBUG'] = 1
  81. #
  82. # Print configuration info
  83. #
  84. print 'Macros:'
  85. for name, value in sorted(macros.iteritems()):
  86. print '\t%s = %r' % (name, value)
  87. print '\nLibraries:\n\t%r\n' % libraries
  88. #
  89. # Compilation of `_processing` extension
  90. #
  91. if sys.platform == 'win32':
  92. sources = [
  93. 'src/processing.c',
  94. 'src/semaphore.c',
  95. 'src/pipe_connection.c',
  96. 'src/socket_connection.c',
  97. 'src/win_functions.c'
  98. ]
  99. else:
  100. sources = [
  101. 'src/processing.c',
  102. 'src/socket_connection.c'
  103. ]
  104. if macros.get('HAVE_SEM_OPEN', False):
  105. sources.append('src/semaphore.c')
  106. ext_modules = [
  107. Extension(
  108. 'processing._processing',
  109. sources=sources,
  110. libraries=libraries,
  111. define_macros=macros.items(),
  112. depends=glob.glob('src/*.h') + ['setup.py']
  113. )
  114. ]
  115. #
  116. # Get version number
  117. #
  118. for line in open('lib/__init__.py'):
  119. if line.startswith('__version__'):
  120. version = line.split()[-1].strip("'").strip('"')
  121. break
  122. else:
  123. raise ValueError, '"__version__" not found in "__init__.py"'
  124. #
  125. # Get `long_description` from `README.txt`
  126. #
  127. readme = open('README.txt', 'rU').read()
  128. start_string = ':Licence: BSD Licence\n\n'
  129. end_string = '.. raw:: html'
  130. start = readme.index(start_string) + len(start_string)
  131. end = readme.index(end_string)
  132. readme = readme[start:end]
  133. long_description = readme.replace('<./', '<http://pyprocessing.berlios.de/')
  134. #
  135. # Packages
  136. #
  137. packages = [
  138. 'processing',
  139. 'processing.dummy',
  140. ]
  141. package_dir = {
  142. 'processing': 'lib',
  143. 'processing.doc': 'doc',
  144. 'processing.tests': 'tests',
  145. 'processing.examples': 'examples'
  146. }
  147. package_data = {
  148. 'processing.doc': ['*.html', '*.css', '../*.html']
  149. }
  150. INSTALL_EXTRA = True
  151. if INSTALL_EXTRA:
  152. # install test files and html documentation
  153. packages.extend([
  154. 'processing.tests',
  155. 'processing.examples',
  156. 'processing.doc'
  157. ])
  158. #
  159. # Setup
  160. #
  161. setup(
  162. name='processing',
  163. version=version,
  164. description=('Package for using processes which mimics ' +
  165. 'the threading module'),
  166. long_description=long_description,
  167. packages=packages,
  168. package_dir=package_dir,
  169. package_data=package_data,
  170. ext_modules=ext_modules,
  171. author='R Oudkerk',
  172. author_email='roudkerk at users.berlios.de',
  173. url='http://developer.berlios.de/projects/pyprocessing',
  174. license='BSD Licence',
  175. platforms='Unix and Windows',
  176. classifiers=[
  177. 'Development Status :: 4 - Beta',
  178. 'Intended Audience :: Developers',
  179. 'Programming Language :: Python',
  180. ]
  181. )
  182. #
  183. # Check for ctypes
  184. #
  185. try:
  186. import ctypes
  187. except ImportError:
  188. print >>sys.stderr, '''
  189. WARNING: ctypes is not available which means that the use of shared
  190. memory for storing data will not be supported. (ctypes is not
  191. included with Python 2.4, but can be intsalled separately.)
  192. '''