setup.py 6.3 KB

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