setup.py 4.9 KB

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