setup.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. if PY26_OR_LESS:
  34. raise Exception(E_UNSUPPORTED_PYTHON % (PYIMP, '2.7'))
  35. elif PY33_OR_LESS and not PYPY24_ATLEAST:
  36. raise Exception(E_UNSUPPORTED_PYTHON % (PYIMP, '3.4'))
  37. # -*- Upgrading from older versions -*-
  38. downgrade_packages = [
  39. 'celery.app.task',
  40. ]
  41. orig_path = sys.path[:]
  42. for path in (os.path.curdir, os.getcwd()):
  43. if path in sys.path:
  44. sys.path.remove(path)
  45. try:
  46. import imp
  47. import shutil
  48. for pkg in downgrade_packages:
  49. try:
  50. parent, module = pkg.rsplit('.', 1)
  51. print('- Trying to upgrade %r in %r' % (module, parent))
  52. parent_mod = __import__(parent, None, None, [parent])
  53. _, mod_path, _ = imp.find_module(module, parent_mod.__path__)
  54. if mod_path.endswith('/' + module):
  55. print('- force upgrading previous installation')
  56. print(' - removing {0!r} package...'.format(mod_path))
  57. try:
  58. shutil.rmtree(os.path.abspath(mod_path))
  59. except Exception:
  60. sys.stderr.write('Could not remove {0!r}: {1!r}\n'.format(
  61. mod_path, sys.exc_info[1]))
  62. except ImportError:
  63. print('- upgrade %s: no old version found.' % module)
  64. except:
  65. pass
  66. finally:
  67. sys.path[:] = orig_path
  68. NAME = 'celery'
  69. entrypoints = {}
  70. extra = {}
  71. # -*- Classifiers -*-
  72. classes = """
  73. Development Status :: 5 - Production/Stable
  74. License :: OSI Approved :: BSD License
  75. Topic :: System :: Distributed Computing
  76. Topic :: Software Development :: Object Brokering
  77. Programming Language :: Python
  78. Programming Language :: Python :: 2
  79. Programming Language :: Python :: 2.7
  80. Programming Language :: Python :: 3
  81. Programming Language :: Python :: 3.4
  82. Programming Language :: Python :: 3.5
  83. Programming Language :: Python :: Implementation :: CPython
  84. Programming Language :: Python :: Implementation :: PyPy
  85. Operating System :: OS Independent
  86. """
  87. classifiers = [s.strip() for s in classes.split('\n') if s]
  88. # -*- Distribution Meta -*-
  89. re_meta = re.compile(r'__(\w+?)__\s*=\s*(.*)')
  90. re_doc = re.compile(r'^"""(.+?)"""')
  91. def add_default(m):
  92. attr_name, attr_value = m.groups()
  93. return ((attr_name, attr_value.strip("\"'")),)
  94. def add_doc(m):
  95. return (('doc', m.groups()[0]),)
  96. pats = {re_meta: add_default, re_doc: add_doc}
  97. here = os.path.abspath(os.path.dirname(__file__))
  98. with open(os.path.join(here, 'celery/__init__.py')) as meta_fh:
  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. # -*- Installation Requires -*-
  108. def strip_comments(l):
  109. return l.split('#', 1)[0].strip()
  110. def _pip_requirement(req):
  111. if req.startswith('-r '):
  112. _, path = req.split()
  113. return reqs(*path.split('/'))
  114. return [req]
  115. def _reqs(*f):
  116. return [
  117. _pip_requirement(r) for r in (
  118. strip_comments(l) for l in open(
  119. os.path.join(os.getcwd(), 'requirements', *f)).readlines()
  120. ) if r]
  121. def reqs(*f):
  122. return [req for subreq in _reqs(*f) for req in subreq]
  123. install_requires = reqs('default.txt')
  124. if JYTHON:
  125. install_requires.extend(reqs('jython.txt'))
  126. # -*- Long Description -*-
  127. if os.path.exists('README.rst'):
  128. long_description = codecs.open('README.rst', 'r', 'utf-8').read()
  129. else:
  130. long_description = 'See http://pypi.python.org/pypi/celery'
  131. # -*- Entry Points -*- #
  132. console_scripts = entrypoints['console_scripts'] = [
  133. 'celery = celery.__main__:main',
  134. ]
  135. # -*- Extras -*-
  136. def extras(*p):
  137. return reqs('extras', *p)
  138. # Celery specific
  139. features = set([
  140. 'auth', 'cassandra', 'elasticsearch', 'memcache', 'pymemcache',
  141. 'couchbase', 'eventlet', 'gevent', 'msgpack', 'yaml',
  142. 'redis', 'sqs', 'couchdb', 'riak', 'zookeeper',
  143. 'sqlalchemy', 'librabbitmq', 'pyro', 'slmq', 'tblib', 'consul'
  144. ])
  145. extras_require = dict((x, extras(x + '.txt')) for x in features)
  146. extra['extras_require'] = extras_require
  147. # -*- %%% -*-
  148. setup(
  149. name=NAME,
  150. version=meta['version'],
  151. description=meta['doc'],
  152. author=meta['author'],
  153. author_email=meta['contact'],
  154. url=meta['homepage'],
  155. platforms=['any'],
  156. license='BSD',
  157. packages=find_packages(exclude=['ez_setup', 'tests', 'tests.*']),
  158. include_package_data=False,
  159. zip_safe=False,
  160. install_requires=install_requires,
  161. tests_require=reqs('test.txt'),
  162. test_suite='nose.collector',
  163. classifiers=classifiers,
  164. entry_points=entrypoints,
  165. long_description=long_description,
  166. **extra)