setup.py 5.4 KB

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