setup.py 5.8 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. # -*- Upgrading from older versions -*-
  40. downgrade_packages = [
  41. 'celery.app.task',
  42. ]
  43. orig_path = sys.path[:]
  44. for path in (os.path.curdir, os.getcwd()):
  45. if path in sys.path:
  46. sys.path.remove(path)
  47. try:
  48. import imp
  49. import shutil
  50. for pkg in downgrade_packages:
  51. try:
  52. parent, module = pkg.rsplit('.', 1)
  53. print('- Trying to upgrade %r in %r' % (module, parent))
  54. parent_mod = __import__(parent, None, None, [parent])
  55. _, mod_path, _ = imp.find_module(module, parent_mod.__path__)
  56. if mod_path.endswith('/' + module):
  57. print('- force upgrading previous installation')
  58. print(' - removing {0!r} package...'.format(mod_path))
  59. try:
  60. shutil.rmtree(os.path.abspath(mod_path))
  61. except Exception:
  62. sys.stderr.write('Could not remove {0!r}: {1!r}\n'.format(
  63. mod_path, sys.exc_info[1]))
  64. except ImportError:
  65. print('- upgrade %s: no old version found.' % module)
  66. except:
  67. pass
  68. finally:
  69. sys.path[:] = orig_path
  70. # -*- Classifiers -*-
  71. classes = """
  72. Development Status :: 5 - Production/Stable
  73. License :: OSI Approved :: BSD License
  74. Topic :: System :: Distributed Computing
  75. Topic :: Software Development :: Object Brokering
  76. Programming Language :: Python
  77. Programming Language :: Python :: 2
  78. Programming Language :: Python :: 2.7
  79. Programming Language :: Python :: 3
  80. Programming Language :: Python :: 3.4
  81. Programming Language :: Python :: 3.5
  82. Programming Language :: Python :: Implementation :: CPython
  83. Programming Language :: Python :: Implementation :: PyPy
  84. Operating System :: OS Independent
  85. """
  86. classifiers = [s.strip() for s in classes.split('\n') if s]
  87. # -*- Distribution Meta -*-
  88. re_meta = re.compile(r'__(\w+?)__\s*=\s*(.*)')
  89. re_doc = re.compile(r'^"""(.+?)"""')
  90. def add_default(m):
  91. attr_name, attr_value = m.groups()
  92. return ((attr_name, attr_value.strip("\"'")),)
  93. def add_doc(m):
  94. return (('doc', m.groups()[0]),)
  95. pats = {re_meta: add_default, re_doc: add_doc}
  96. here = os.path.abspath(os.path.dirname(__file__))
  97. with open(os.path.join(here, 'celery/__init__.py')) as meta_fh:
  98. meta = {}
  99. for line in meta_fh:
  100. if line.strip() == '# -eof meta-':
  101. break
  102. for pattern, handler in pats.items():
  103. m = pattern.match(line.strip())
  104. if m:
  105. meta.update(handler(m))
  106. # -*- Installation Requires -*-
  107. def strip_comments(l):
  108. return l.split('#', 1)[0].strip()
  109. def _pip_requirement(req):
  110. if req.startswith('-r '):
  111. _, path = req.split()
  112. return reqs(*path.split('/'))
  113. return [req]
  114. def _reqs(*f):
  115. return [
  116. _pip_requirement(r) for r in (
  117. strip_comments(l) for l in open(
  118. os.path.join(os.getcwd(), 'requirements', *f)).readlines()
  119. ) if r]
  120. def reqs(*f):
  121. return [req for subreq in _reqs(*f) for req in subreq]
  122. def extras(*p):
  123. return reqs('extras', *p)
  124. install_requires = reqs('default.txt')
  125. if JYTHON:
  126. install_requires.extend(reqs('jython.txt'))
  127. # -*- Long Description -*-
  128. if os.path.exists('README.rst'):
  129. long_description = codecs.open('README.rst', 'r', 'utf-8').read()
  130. else:
  131. long_description = 'See http://pypi.python.org/pypi/celery'
  132. # -*- %%% -*-
  133. class pytest(setuptools.command.test.test):
  134. user_options = [('pytest-args=', 'a', 'Arguments to pass to py.test')]
  135. def initialize_options(self):
  136. setuptools.command.test.test.initialize_options(self)
  137. self.pytest_args = []
  138. def run_tests(self):
  139. import pytest
  140. sys.exit(pytest.main(self.pytest_args))
  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. author=meta['author'],
  148. author_email=meta['contact'],
  149. platforms=['any'],
  150. license='BSD',
  151. url=meta['homepage'],
  152. install_requires=install_requires,
  153. tests_require=reqs('test.txt'),
  154. extras_require=dict((x, extras(x + '.txt')) for x in set([
  155. 'auth', 'cassandra', 'elasticsearch', 'memcache', 'pymemcache',
  156. 'couchbase', 'eventlet', 'gevent', 'msgpack', 'yaml',
  157. 'redis', 'sqs', 'couchdb', 'riak', 'zookeeper', 'solar',
  158. 'sqlalchemy', 'librabbitmq', 'pyro', 'slmq', 'tblib', 'consul'
  159. ])),
  160. classifiers=classifiers,
  161. entry_points={
  162. 'console_scripts': [
  163. 'celery = celery.__main__:main',
  164. ]
  165. },
  166. cmdclass={'test': pytest},
  167. include_package_data=True,
  168. zip_safe=False,
  169. )