setup.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. Programming Language :: Python :: Implementation :: Jython
  86. Operating System :: OS Independent
  87. """
  88. classifiers = [s.strip() for s in classes.split('\n') if s]
  89. # -*- Distribution Meta -*-
  90. re_meta = re.compile(r'__(\w+?)__\s*=\s*(.*)')
  91. re_vers = re.compile(r'VERSION\s*=.*?\((.*?)\)')
  92. re_doc = re.compile(r'^"""(.+?)"""')
  93. def rq(s):
  94. return s.strip("\"'")
  95. def add_default(m):
  96. attr_name, attr_value = m.groups()
  97. return ((attr_name, rq(attr_value)),)
  98. def add_version(m):
  99. v = list(map(rq, m.groups()[0].split(', ')))
  100. return (('VERSION', '.'.join(v[0:3]) + ''.join(v[3:])),)
  101. def add_doc(m):
  102. return (('doc', m.groups()[0]),)
  103. pats = {re_meta: add_default,
  104. re_vers: add_version,
  105. re_doc: add_doc}
  106. here = os.path.abspath(os.path.dirname(__file__))
  107. with open(os.path.join(here, 'celery/__init__.py')) as meta_fh:
  108. meta = {}
  109. for line in meta_fh:
  110. if line.strip() == '# -eof meta-':
  111. break
  112. for pattern, handler in pats.items():
  113. m = pattern.match(line.strip())
  114. if m:
  115. meta.update(handler(m))
  116. # -*- Installation Requires -*-
  117. def strip_comments(l):
  118. return l.split('#', 1)[0].strip()
  119. def _pip_requirement(req):
  120. if req.startswith('-r '):
  121. _, path = req.split()
  122. return reqs(*path.split('/'))
  123. return [req]
  124. def _reqs(*f):
  125. return [
  126. _pip_requirement(r) for r in (
  127. strip_comments(l) for l in open(
  128. os.path.join(os.getcwd(), 'requirements', *f)).readlines()
  129. ) if r]
  130. def reqs(*f):
  131. return [req for subreq in _reqs(*f) for req in subreq]
  132. install_requires = reqs('default.txt')
  133. if JYTHON:
  134. install_requires.extend(reqs('jython.txt'))
  135. # -*- Tests Requires -*-
  136. tests_require = reqs('test3.txt' if PY3 else 'test.txt')
  137. # -*- Long Description -*-
  138. if os.path.exists('README.rst'):
  139. long_description = codecs.open('README.rst', 'r', 'utf-8').read()
  140. else:
  141. long_description = 'See http://pypi.python.org/pypi/celery'
  142. # -*- Entry Points -*- #
  143. console_scripts = entrypoints['console_scripts'] = [
  144. 'celery = celery.__main__:main',
  145. ]
  146. # -*- Extras -*-
  147. def extras(*p):
  148. return reqs('extras', *p)
  149. # Celery specific
  150. features = set([
  151. 'auth', 'cassandra', 'elasticsearch', 'memcache', 'pymemcache',
  152. 'couchbase', 'threads', 'eventlet', 'gevent', 'msgpack', 'yaml',
  153. 'redis', 'mongodb', 'sqs', 'couchdb', 'riak', 'beanstalk', 'zookeeper',
  154. 'zeromq', 'sqlalchemy', 'librabbitmq', 'pyro', 'slmq',
  155. ])
  156. extras_require = dict((x, extras(x + '.txt')) for x in features)
  157. extra['extras_require'] = extras_require
  158. # -*- %%% -*-
  159. setup(
  160. name=NAME,
  161. version=meta['VERSION'],
  162. description=meta['doc'],
  163. author=meta['author'],
  164. author_email=meta['contact'],
  165. url=meta['homepage'],
  166. platforms=['any'],
  167. license='BSD',
  168. packages=find_packages(exclude=['ez_setup', 'tests', 'tests.*']),
  169. include_package_data=False,
  170. zip_safe=False,
  171. install_requires=install_requires,
  172. tests_require=tests_require,
  173. test_suite='nose.collector',
  174. classifiers=classifiers,
  175. entry_points=entrypoints,
  176. long_description=long_description,
  177. **extra)