setup.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. 'django',
  44. 'elasticsearch',
  45. 'memcache',
  46. 'pymemcache',
  47. 'couchbase',
  48. 'eventlet',
  49. 'gevent',
  50. 'msgpack',
  51. 'yaml',
  52. 'redis',
  53. 'sqs',
  54. 'couchdb',
  55. 'riak',
  56. 'zookeeper',
  57. 'solar',
  58. 'sqlalchemy',
  59. 'librabbitmq',
  60. 'pyro',
  61. 'slmq',
  62. 'tblib',
  63. 'consul'
  64. }
  65. # -*- Classifiers -*-
  66. classes = """
  67. Development Status :: 5 - Production/Stable
  68. License :: OSI Approved :: BSD License
  69. Topic :: System :: Distributed Computing
  70. Topic :: Software Development :: Object Brokering
  71. Programming Language :: Python
  72. Programming Language :: Python :: 2
  73. Programming Language :: Python :: 2.7
  74. Programming Language :: Python :: 3
  75. Programming Language :: Python :: 3.4
  76. Programming Language :: Python :: 3.5
  77. Programming Language :: Python :: Implementation :: CPython
  78. Programming Language :: Python :: Implementation :: PyPy
  79. Operating System :: OS Independent
  80. """
  81. classifiers = [s.strip() for s in classes.split('\n') if s]
  82. # -*- Distribution Meta -*-
  83. re_meta = re.compile(r'__(\w+?)__\s*=\s*(.*)')
  84. re_doc = re.compile(r'^"""(.+?)"""')
  85. def add_default(m):
  86. attr_name, attr_value = m.groups()
  87. return ((attr_name, attr_value.strip("\"'")),)
  88. def add_doc(m):
  89. return (('doc', m.groups()[0]),)
  90. def parse_dist_meta():
  91. pats = {re_meta: add_default, re_doc: add_doc}
  92. here = os.path.abspath(os.path.dirname(__file__))
  93. with open(os.path.join(here, 'celery', '__init__.py')) as meta_fh:
  94. distmeta = {}
  95. for line in meta_fh:
  96. if line.strip() == '# -eof meta-':
  97. break
  98. for pattern, handler in pats.items():
  99. m = pattern.match(line.strip())
  100. if m:
  101. distmeta.update(handler(m))
  102. return distmeta
  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. def extras(*p):
  120. return reqs('extras', *p)
  121. def install_requires():
  122. if JYTHON:
  123. return reqs('default.txt') + reqs('jython.txt')
  124. return reqs('default.txt')
  125. def extras_require():
  126. return {x: extras(x + '.txt') for x in EXTENSIONS}
  127. def long_description():
  128. try:
  129. return codecs.open('README.rst', 'r', 'utf-8').read()
  130. except IOError:
  131. return 'Long description error: Missing README.rst file'
  132. class pytest(setuptools.command.test.test):
  133. user_options = [('pytest-args=', 'a', 'Arguments to pass to py.test')]
  134. def initialize_options(self):
  135. setuptools.command.test.test.initialize_options(self)
  136. self.pytest_args = []
  137. def run_tests(self):
  138. import pytest as _pytest
  139. sys.exit(_pytest.main(self.pytest_args))
  140. # -*- %%% -*-
  141. meta = parse_dist_meta()
  142. setuptools.setup(
  143. name=NAME,
  144. packages=setuptools.find_packages(exclude=['t', 't.*']),
  145. version=meta['version'],
  146. description=meta['doc'],
  147. long_description=long_description(),
  148. keywords=meta['keywords'],
  149. author=meta['author'],
  150. author_email=meta['contact'],
  151. url=meta['homepage'],
  152. license='BSD',
  153. platforms=['any'],
  154. install_requires=install_requires(),
  155. tests_require=reqs('test.txt'),
  156. extras_require=extras_require(),
  157. classifiers=classifiers,
  158. cmdclass={'test': pytest},
  159. include_package_data=True,
  160. zip_safe=False,
  161. entry_points={
  162. 'console_scripts': [
  163. 'celery = celery.__main__:main',
  164. ],
  165. 'pytest11': [
  166. 'celery = celery.contrib.pytest',
  167. ],
  168. },
  169. )