setup.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. try:
  4. from setuptools import setup, find_packages
  5. from setuptools.command.test import test
  6. is_setuptools = True
  7. except ImportError:
  8. raise
  9. from ez_setup import use_setuptools
  10. use_setuptools()
  11. from setuptools import setup, find_packages # noqa
  12. from setuptools.command.test import test # noqa
  13. is_setuptools = False
  14. import os
  15. import sys
  16. import codecs
  17. CELERY_COMPAT_PROGRAMS = int(os.environ.get('CELERY_COMPAT_PROGRAMS', 1))
  18. if sys.version_info < (2, 6):
  19. raise Exception('Celery 3.1 requires Python 2.6 or higher.')
  20. downgrade_packages = [
  21. 'celery.app.task',
  22. 'celery.concurrency.processes',
  23. ]
  24. orig_path = sys.path[:]
  25. for path in (os.path.curdir, os.getcwd()):
  26. if path in sys.path:
  27. sys.path.remove(path)
  28. try:
  29. import imp
  30. import shutil
  31. for pkg in downgrade_packages:
  32. try:
  33. parent, module = pkg.rsplit('.', 1)
  34. print('- Trying to upgrade %r in %r' % (module, parent))
  35. parent_mod = __import__(parent, None, None, [parent])
  36. _, mod_path, _ = imp.find_module(module, parent_mod.__path__)
  37. if mod_path.endswith('/' + module):
  38. print('- force upgrading previous installation')
  39. print(' - removing {0!r} package...'.format(mod_path))
  40. try:
  41. shutil.rmtree(os.path.abspath(mod_path))
  42. except Exception:
  43. sys.stderr.write('Could not remove {0!r}: {1!r}\n'.format(
  44. mod_path, sys.exc_info[1]))
  45. except ImportError:
  46. print('- upgrade %s: no old version found.' % module)
  47. except:
  48. pass
  49. finally:
  50. sys.path[:] = orig_path
  51. NAME = 'celery'
  52. entrypoints = {}
  53. extra = {}
  54. # -*- Classifiers -*-
  55. classes = """
  56. Development Status :: 5 - Production/Stable
  57. License :: OSI Approved :: BSD License
  58. Topic :: System :: Distributed Computing
  59. Topic :: Software Development :: Object Brokering
  60. Programming Language :: Python
  61. Programming Language :: Python :: 2
  62. Programming Language :: Python :: 2.6
  63. Programming Language :: Python :: 2.7
  64. Programming Language :: Python :: 3
  65. Programming Language :: Python :: 3.2
  66. Programming Language :: Python :: 3.3
  67. Programming Language :: Python :: Implementation :: CPython
  68. Programming Language :: Python :: Implementation :: PyPy
  69. Programming Language :: Python :: Implementation :: Jython
  70. Operating System :: OS Independent
  71. Operating System :: POSIX
  72. Operating System :: Microsoft :: Windows
  73. Operating System :: MacOS :: MacOS X
  74. """
  75. classifiers = [s.strip() for s in classes.split('\n') if s]
  76. PY3 = sys.version_info[0] == 3
  77. JYTHON = sys.platform.startswith('java')
  78. PYPY = hasattr(sys, 'pypy_version_info')
  79. # -*- Distribution Meta -*-
  80. import re
  81. re_meta = re.compile(r'__(\w+?)__\s*=\s*(.*)')
  82. re_vers = re.compile(r'VERSION\s*=\s*\((.*?)\)')
  83. re_doc = re.compile(r'^"""(.+?)"""')
  84. rq = lambda s: s.strip("\"'")
  85. def add_default(m):
  86. attr_name, attr_value = m.groups()
  87. return ((attr_name, rq(attr_value)), )
  88. def add_version(m):
  89. v = list(map(rq, m.groups()[0].split(', ')))
  90. return (('VERSION', '.'.join(v[0:3]) + ''.join(v[3:])), )
  91. def add_doc(m):
  92. return (('doc', m.groups()[0]), )
  93. pats = {re_meta: add_default,
  94. re_vers: add_version,
  95. re_doc: add_doc}
  96. here = os.path.abspath(os.path.dirname(__file__))
  97. meta_fh = open(os.path.join(here, 'celery/__init__.py'))
  98. try:
  99. meta = {}
  100. for line in meta_fh:
  101. if line.strip() == '# -eof meta-':
  102. break
  103. for pattern, handler in pats.items():
  104. m = pattern.match(line.strip())
  105. if m:
  106. meta.update(handler(m))
  107. finally:
  108. meta_fh.close()
  109. # -*- Custom Commands -*-
  110. class quicktest(test):
  111. extra_env = dict(SKIP_RLIMITS=1, QUICKTEST=1)
  112. def run(self, *args, **kwargs):
  113. for env_name, env_value in self.extra_env.items():
  114. os.environ[env_name] = str(env_value)
  115. test.run(self, *args, **kwargs)
  116. # -*- Installation Requires -*-
  117. py_version = sys.version_info
  118. def strip_comments(l):
  119. return l.split('#', 1)[0].strip()
  120. def reqs(*f):
  121. return [
  122. r for r in (
  123. strip_comments(l) for l in open(
  124. os.path.join(os.getcwd(), 'requirements', *f)).readlines()
  125. ) if r]
  126. install_requires = reqs('default.txt')
  127. if JYTHON:
  128. install_requires.extend(reqs('jython.txt'))
  129. # -*- Tests Requires -*-
  130. tests_require = reqs('test3.txt' if PY3 else 'test.txt')
  131. # -*- Long Description -*-
  132. if os.path.exists('README.rst'):
  133. long_description = codecs.open('README.rst', 'r', 'utf-8').read()
  134. else:
  135. long_description = 'See http://pypi.python.org/pypi/celery'
  136. # -*- Entry Points -*- #
  137. console_scripts = entrypoints['console_scripts'] = [
  138. 'celery = celery.__main__:main',
  139. ]
  140. if CELERY_COMPAT_PROGRAMS:
  141. console_scripts.extend([
  142. 'celeryd = celery.__main__:_compat_worker',
  143. 'celerybeat = celery.__main__:_compat_beat',
  144. 'celeryd-multi = celery.__main__:_compat_multi',
  145. ])
  146. if is_setuptools:
  147. extras = lambda *p: reqs('extras', *p)
  148. extras_require = extra['extras_require'] = {
  149. # Celery specific
  150. 'auth': extras('auth.txt'),
  151. 'cassandra': extras('cassandra.txt'),
  152. 'memcache': extras('memcache.txt'),
  153. 'couchbase': extras('couchbase.txt'),
  154. 'threads': extras('threads.txt'),
  155. 'eventlet': extras('eventlet.txt'),
  156. 'gevent': extras('gevent.txt'),
  157. 'msgpack': extras('msgpack.txt'),
  158. 'yaml': extras('yaml.txt'),
  159. 'redis': extras('redis.txt'),
  160. 'mongodb': extras('mongodb.txt'),
  161. 'sqs': extras('sqs.txt'),
  162. 'couchdb': extras('couchdb.txt'),
  163. 'beanstalk': extras('beanstalk.txt'),
  164. 'zookeeper': extras('zookeeper.txt'),
  165. 'zeromq': extras('zeromq.txt'),
  166. 'sqlalchemy': extras('sqlalchemy.txt'),
  167. 'librabbitmq': extras('librabbitmq.txt'),
  168. 'pyro': extras('pyro.txt'),
  169. 'slmq': extras('slmq.txt'),
  170. }
  171. # -*- %%% -*-
  172. setup(
  173. name=NAME,
  174. version=meta['VERSION'],
  175. description=meta['doc'],
  176. author=meta['author'],
  177. author_email=meta['contact'],
  178. url=meta['homepage'],
  179. platforms=['any'],
  180. license='BSD',
  181. packages=find_packages(exclude=['ez_setup', 'tests', 'tests.*']),
  182. zip_safe=False,
  183. install_requires=install_requires,
  184. tests_require=tests_require,
  185. test_suite='nose.collector',
  186. cmdclass={'quicktest': quicktest},
  187. classifiers=classifiers,
  188. entry_points=entrypoints,
  189. long_description=long_description,
  190. **extra)