setup.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. from platform import python_implementation as _pyimp
  11. except (AttributeError, ImportError):
  12. def _pyimp():
  13. return 'Python (unknown)'
  14. NAME = 'celery'
  15. # -*- Python Versions -*-
  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. 'dynamodb'
  65. }
  66. # -*- Classifiers -*-
  67. classes = """
  68. Development Status :: 5 - Production/Stable
  69. License :: OSI Approved :: BSD License
  70. Topic :: System :: Distributed Computing
  71. Topic :: Software Development :: Object Brokering
  72. Programming Language :: Python
  73. Programming Language :: Python :: 2
  74. Programming Language :: Python :: 2.7
  75. Programming Language :: Python :: 3
  76. Programming Language :: Python :: 3.4
  77. Programming Language :: Python :: 3.5
  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. # -*- Distribution Meta -*-
  84. re_meta = re.compile(r'__(\w+?)__\s*=\s*(.*)')
  85. re_doc = re.compile(r'^"""(.+?)"""')
  86. def _add_default(m):
  87. attr_name, attr_value = m.groups()
  88. return ((attr_name, attr_value.strip("\"'")),)
  89. def _add_doc(m):
  90. return (('doc', m.groups()[0]),)
  91. def parse_dist_meta():
  92. """Extract metadata information from ``$dist/__init__.py``."""
  93. pats = {re_meta: _add_default, re_doc: _add_doc}
  94. here = os.path.abspath(os.path.dirname(__file__))
  95. with open(os.path.join(here, NAME, '__init__.py')) as meta_fh:
  96. distmeta = {}
  97. for line in meta_fh:
  98. if line.strip() == '# -eof meta-':
  99. break
  100. for pattern, handler in pats.items():
  101. m = pattern.match(line.strip())
  102. if m:
  103. distmeta.update(handler(m))
  104. return distmeta
  105. # -*- Requirements -*-
  106. def _strip_comments(l):
  107. return l.split('#', 1)[0].strip()
  108. def _pip_requirement(req):
  109. if req.startswith('-r '):
  110. _, path = req.split()
  111. return reqs(*path.split('/'))
  112. return [req]
  113. def _reqs(*f):
  114. return [
  115. _pip_requirement(r) for r in (
  116. _strip_comments(l) for l in open(
  117. os.path.join(os.getcwd(), 'requirements', *f)).readlines()
  118. ) if r]
  119. def reqs(*f):
  120. """Parse requirement file.
  121. Example:
  122. reqs('default.txt') # requirements/default.txt
  123. reqs('extras', 'redis.txt') # requirements/extras/redis.txt
  124. Returns:
  125. List[str]: list of requirements specified in the file.
  126. """
  127. return [req for subreq in _reqs(*f) for req in subreq]
  128. def extras(*p):
  129. """Parse requirement in the requirements/extras/ directory."""
  130. return reqs('extras', *p)
  131. def install_requires():
  132. """Get list of requirements required for installation."""
  133. if JYTHON:
  134. return reqs('default.txt') + reqs('jython.txt')
  135. return reqs('default.txt')
  136. def extras_require():
  137. """Get map of all extra requirements."""
  138. return {x: extras(x + '.txt') for x in EXTENSIONS}
  139. # -*- Long Description -*-
  140. def long_description():
  141. try:
  142. return codecs.open('README.rst', 'r', 'utf-8').read()
  143. except IOError:
  144. return 'Long description error: Missing README.rst file'
  145. # -*- Command: setup.py test -*-
  146. class pytest(setuptools.command.test.test):
  147. user_options = [('pytest-args=', 'a', 'Arguments to pass to py.test')]
  148. def initialize_options(self):
  149. setuptools.command.test.test.initialize_options(self)
  150. self.pytest_args = []
  151. def run_tests(self):
  152. import pytest as _pytest
  153. sys.exit(_pytest.main(self.pytest_args))
  154. # -*- %%% -*-
  155. meta = parse_dist_meta()
  156. setuptools.setup(
  157. name=NAME,
  158. packages=setuptools.find_packages(exclude=['t', 't.*']),
  159. version=meta['version'],
  160. description=meta['doc'],
  161. long_description=long_description(),
  162. keywords=meta['keywords'],
  163. author=meta['author'],
  164. author_email=meta['contact'],
  165. url=meta['homepage'],
  166. license='BSD',
  167. platforms=['any'],
  168. install_requires=install_requires(),
  169. tests_require=reqs('test.txt'),
  170. extras_require=extras_require(),
  171. classifiers=[s.strip() for s in classes.split('\n') if s],
  172. cmdclass={'test': pytest},
  173. include_package_data=True,
  174. zip_safe=False,
  175. entry_points={
  176. 'console_scripts': [
  177. 'celery = celery.__main__:main',
  178. ],
  179. 'pytest11': [
  180. 'celery = celery.contrib.pytest',
  181. ],
  182. },
  183. )