setup.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import codecs
  4. import os
  5. import re
  6. import sys
  7. import setuptools
  8. import setuptools.command.test
  9. try:
  10. import platform
  11. _pyimp = platform.python_implementation
  12. except (AttributeError, ImportError):
  13. def _pyimp():
  14. return 'Python'
  15. NAME = 'celery'
  16. E_UNSUPPORTED_PYTHON = """
  17. ----------------------------------------
  18. Celery 4.0 requires %s %s or later
  19. ----------------------------------------
  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. PY26_OR_LESS = sys.version_info < (2, 7)
  29. PY3 = sys.version_info[0] == 3
  30. PY33_OR_LESS = PY3 and sys.version_info < (3, 4)
  31. JYTHON = sys.platform.startswith('java')
  32. PYPY_VERSION = getattr(sys, 'pypy_version_info', None)
  33. PYPY = PYPY_VERSION is not None
  34. PYPY24_ATLEAST = PYPY_VERSION and PYPY_VERSION >= (2, 4)
  35. if PY26_OR_LESS:
  36. raise Exception(E_UNSUPPORTED_PYTHON % (PYIMP, '2.7'))
  37. elif PY33_OR_LESS and not PYPY24_ATLEAST:
  38. raise Exception(E_UNSUPPORTED_PYTHON % (PYIMP, '3.4'))
  39. # -*- Extras -*-
  40. EXTENSIONS = {
  41. 'auth',
  42. 'cassandra',
  43. 'elasticsearch',
  44. 'memcache',
  45. 'pymemcache',
  46. 'couchbase',
  47. 'eventlet',
  48. 'gevent',
  49. 'msgpack',
  50. 'yaml',
  51. 'redis',
  52. 'sqs',
  53. 'couchdb',
  54. 'riak',
  55. 'zookeeper',
  56. 'solar',
  57. 'sqlalchemy',
  58. 'librabbitmq',
  59. 'pyro',
  60. 'slmq',
  61. 'tblib',
  62. 'consul'
  63. }
  64. # -*- Classifiers -*-
  65. classes = """
  66. Development Status :: 5 - Production/Stable
  67. License :: OSI Approved :: BSD License
  68. Topic :: System :: Distributed Computing
  69. Topic :: Software Development :: Object Brokering
  70. Programming Language :: Python
  71. Programming Language :: Python :: 2
  72. Programming Language :: Python :: 2.7
  73. Programming Language :: Python :: 3
  74. Programming Language :: Python :: 3.4
  75. Programming Language :: Python :: 3.5
  76. Programming Language :: Python :: Implementation :: CPython
  77. Programming Language :: Python :: Implementation :: PyPy
  78. Operating System :: OS Independent
  79. """
  80. classifiers = [s.strip() for s in classes.split('\n') if s]
  81. # -*- Distribution Meta -*-
  82. re_meta = re.compile(r'__(\w+?)__\s*=\s*(.*)')
  83. re_doc = re.compile(r'^"""(.+?)"""')
  84. def add_default(m):
  85. attr_name, attr_value = m.groups()
  86. return ((attr_name, attr_value.strip("\"'")),)
  87. def add_doc(m):
  88. return (('doc', m.groups()[0]),)
  89. def parse_dist_meta():
  90. pats = {re_meta: add_default, re_doc: add_doc}
  91. here = os.path.abspath(os.path.dirname(__file__))
  92. with open(os.path.join(here, 'celery', '__init__.py')) as meta_fh:
  93. distmeta = {}
  94. for line in meta_fh:
  95. if line.strip() == '# -eof meta-':
  96. break
  97. for pattern, handler in pats.items():
  98. m = pattern.match(line.strip())
  99. if m:
  100. distmeta.update(handler(m))
  101. return distmeta
  102. # -*- Installation Requires -*-
  103. def strip_comments(l):
  104. return l.split('#', 1)[0].strip()
  105. def _pip_requirement(req):
  106. if req.startswith('-r '):
  107. _, path = req.split()
  108. return reqs(*path.split('/'))
  109. return [req]
  110. def _reqs(*f):
  111. return [
  112. _pip_requirement(r) for r in (
  113. strip_comments(l) for l in open(
  114. os.path.join(os.getcwd(), 'requirements', *f)).readlines()
  115. ) if r]
  116. def reqs(*f):
  117. return [req for subreq in _reqs(*f) for req in subreq]
  118. def extras(*p):
  119. return reqs('extras', *p)
  120. def install_requires():
  121. if JYTHON:
  122. return reqs('default.txt') + reqs('jython.txt')
  123. return reqs('default.txt')
  124. def extras_require():
  125. return {x: extras(x + '.txt') for x in EXTENSIONS}
  126. def long_description():
  127. try:
  128. return codecs.open('README.rst', 'r', 'utf-8').read()
  129. except IOError:
  130. return 'Long description error: Missing README.rst file'
  131. class pytest(setuptools.command.test.test):
  132. user_options = [('pytest-args=', 'a', 'Arguments to pass to py.test')]
  133. def initialize_options(self):
  134. setuptools.command.test.test.initialize_options(self)
  135. self.pytest_args = []
  136. def run_tests(self):
  137. import pytest as _pytest
  138. sys.exit(_pytest.main(self.pytest_args))
  139. # -*- %%% -*-
  140. meta = parse_dist_meta()
  141. setuptools.setup(
  142. name=NAME,
  143. packages=setuptools.find_packages(exclude=['t', 't.*']),
  144. version=meta['version'],
  145. description=meta['doc'],
  146. long_description=long_description(),
  147. keywords=meta['keywords'],
  148. author=meta['author'],
  149. author_email=meta['contact'],
  150. url=meta['homepage'],
  151. license='BSD',
  152. platforms=['any'],
  153. install_requires=install_requires(),
  154. tests_require=reqs('test.txt'),
  155. extras_require=extras_require(),
  156. classifiers=classifiers,
  157. cmdclass={'test': pytest},
  158. include_package_data=True,
  159. zip_safe=False,
  160. entry_points={
  161. 'console_scripts': [
  162. 'celery = celery.__main__:main',
  163. ]
  164. },
  165. )