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