setup.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from setuptools import setup, find_packages
  4. import os
  5. import re
  6. import sys
  7. import codecs
  8. CELERY_COMPAT_PROGRAMS = int(os.environ.get('CELERY_COMPAT_PROGRAMS', 1))
  9. if sys.version_info < (2, 7):
  10. raise Exception('Celery 4.0 requires Python 2.7 or higher.')
  11. elif sys.version_info > (3, ) < (3, 4):
  12. raise Exception('Celery 4.0 requires Python 3.4 or higher.')
  13. # -*- Upgrading from older versions -*-
  14. downgrade_packages = [
  15. 'celery.app.task',
  16. ]
  17. orig_path = sys.path[:]
  18. for path in (os.path.curdir, os.getcwd()):
  19. if path in sys.path:
  20. sys.path.remove(path)
  21. try:
  22. import imp
  23. import shutil
  24. for pkg in downgrade_packages:
  25. try:
  26. parent, module = pkg.rsplit('.', 1)
  27. print('- Trying to upgrade %r in %r' % (module, parent))
  28. parent_mod = __import__(parent, None, None, [parent])
  29. _, mod_path, _ = imp.find_module(module, parent_mod.__path__)
  30. if mod_path.endswith('/' + module):
  31. print('- force upgrading previous installation')
  32. print(' - removing {0!r} package...'.format(mod_path))
  33. try:
  34. shutil.rmtree(os.path.abspath(mod_path))
  35. except Exception:
  36. sys.stderr.write('Could not remove {0!r}: {1!r}\n'.format(
  37. mod_path, sys.exc_info[1]))
  38. except ImportError:
  39. print('- upgrade %s: no old version found.' % module)
  40. except:
  41. pass
  42. finally:
  43. sys.path[:] = orig_path
  44. PY3 = sys.version_info[0] == 3
  45. JYTHON = sys.platform.startswith('java')
  46. PYPY = hasattr(sys, 'pypy_version_info')
  47. NAME = 'celery'
  48. entrypoints = {}
  49. extra = {}
  50. # -*- Classifiers -*-
  51. classes = """
  52. Development Status :: 5 - Production/Stable
  53. License :: OSI Approved :: BSD License
  54. Topic :: System :: Distributed Computing
  55. Topic :: Software Development :: Object Brokering
  56. Programming Language :: Python
  57. Programming Language :: Python :: 2
  58. Programming Language :: Python :: 2.7
  59. Programming Language :: Python :: 3
  60. Programming Language :: Python :: 3.4
  61. Programming Language :: Python :: 3.5
  62. Programming Language :: Python :: Implementation :: CPython
  63. Programming Language :: Python :: Implementation :: PyPy
  64. Programming Language :: Python :: Implementation :: Jython
  65. Operating System :: OS Independent
  66. """
  67. classifiers = [s.strip() for s in classes.split('\n') if s]
  68. # -*- Distribution Meta -*-
  69. re_meta = re.compile(r'__(\w+?)__\s*=\s*(.*)')
  70. re_vers = re.compile(r'VERSION\s*=.*?\((.*?)\)')
  71. re_doc = re.compile(r'^"""(.+?)"""')
  72. def rq(s):
  73. return s.strip("\"'")
  74. def add_default(m):
  75. attr_name, attr_value = m.groups()
  76. return ((attr_name, rq(attr_value)),)
  77. def add_version(m):
  78. v = list(map(rq, m.groups()[0].split(', ')))
  79. return (('VERSION', '.'.join(v[0:3]) + ''.join(v[3:])),)
  80. def add_doc(m):
  81. return (('doc', m.groups()[0]),)
  82. pats = {re_meta: add_default,
  83. re_vers: add_version,
  84. re_doc: add_doc}
  85. here = os.path.abspath(os.path.dirname(__file__))
  86. with open(os.path.join(here, 'celery/__init__.py')) as meta_fh:
  87. meta = {}
  88. for line in meta_fh:
  89. if line.strip() == '# -eof meta-':
  90. break
  91. for pattern, handler in pats.items():
  92. m = pattern.match(line.strip())
  93. if m:
  94. meta.update(handler(m))
  95. # -*- Installation Requires -*-
  96. def strip_comments(l):
  97. return l.split('#', 1)[0].strip()
  98. def _pip_requirement(req):
  99. if req.startswith('-r '):
  100. _, path = req.split()
  101. return reqs(*path.split('/'))
  102. return [req]
  103. def _reqs(*f):
  104. return [
  105. _pip_requirement(r) for r in (
  106. strip_comments(l) for l in open(
  107. os.path.join(os.getcwd(), 'requirements', *f)).readlines()
  108. ) if r]
  109. def reqs(*f):
  110. return [req for subreq in _reqs(*f) for req in subreq]
  111. install_requires = reqs('default.txt')
  112. if JYTHON:
  113. install_requires.extend(reqs('jython.txt'))
  114. # -*- Tests Requires -*-
  115. tests_require = reqs('test3.txt' if PY3 else 'test.txt')
  116. # -*- Long Description -*-
  117. if os.path.exists('README.rst'):
  118. long_description = codecs.open('README.rst', 'r', 'utf-8').read()
  119. else:
  120. long_description = 'See http://pypi.python.org/pypi/celery'
  121. # -*- Entry Points -*- #
  122. console_scripts = entrypoints['console_scripts'] = [
  123. 'celery = celery.__main__:main',
  124. ]
  125. if CELERY_COMPAT_PROGRAMS:
  126. console_scripts.extend([
  127. 'celeryd = celery.__main__:_compat_worker',
  128. 'celerybeat = celery.__main__:_compat_beat',
  129. 'celeryd-multi = celery.__main__:_compat_multi',
  130. ])
  131. # -*- Extras -*-
  132. def extras(*p):
  133. return reqs('extras', *p)
  134. # Celery specific
  135. features = set([
  136. 'auth', 'cassandra', 'memcache', 'couchbase', 'threads',
  137. 'eventlet', 'gevent', 'msgpack', 'yaml', 'redis',
  138. 'mongodb', 'sqs', 'couchdb', 'riak', 'beanstalk', 'zookeeper',
  139. 'zeromq', 'sqlalchemy', 'librabbitmq', 'pyro', 'slmq',
  140. 'new_cassandra',
  141. ])
  142. extras_require = dict((x, extras(x + '.txt')) for x in features)
  143. extra['extras_require'] = extras_require
  144. # -*- %%% -*-
  145. setup(
  146. name=NAME,
  147. version=meta['VERSION'],
  148. description=meta['doc'],
  149. author=meta['author'],
  150. author_email=meta['contact'],
  151. url=meta['homepage'],
  152. platforms=['any'],
  153. license='BSD',
  154. packages=find_packages(exclude=['ez_setup', 'tests', 'tests.*']),
  155. include_package_data=False,
  156. zip_safe=False,
  157. install_requires=install_requires,
  158. tests_require=tests_require,
  159. test_suite='nose.collector',
  160. classifiers=classifiers,
  161. entry_points=entrypoints,
  162. long_description=long_description,
  163. **extra)