setup.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 :: 3.5
  61. Programming Language :: Python :: Implementation :: CPython
  62. Programming Language :: Python :: Implementation :: PyPy
  63. Programming Language :: Python :: Implementation :: Jython
  64. Operating System :: OS Independent
  65. """
  66. classifiers = [s.strip() for s in classes.split('\n') if s]
  67. # -*- Distribution Meta -*-
  68. re_meta = re.compile(r'__(\w+?)__\s*=\s*(.*)')
  69. re_vers = re.compile(r'VERSION\s*=.*?\((.*?)\)')
  70. re_doc = re.compile(r'^"""(.+?)"""')
  71. def rq(s):
  72. return s.strip("\"'")
  73. def add_default(m):
  74. attr_name, attr_value = m.groups()
  75. return ((attr_name, rq(attr_value)),)
  76. def add_version(m):
  77. v = list(map(rq, m.groups()[0].split(', ')))
  78. return (('VERSION', '.'.join(v[0:3]) + ''.join(v[3:])),)
  79. def add_doc(m):
  80. return (('doc', m.groups()[0]),)
  81. pats = {re_meta: add_default,
  82. re_vers: add_version,
  83. re_doc: add_doc}
  84. here = os.path.abspath(os.path.dirname(__file__))
  85. with open(os.path.join(here, 'celery/__init__.py')) as meta_fh:
  86. meta = {}
  87. for line in meta_fh:
  88. if line.strip() == '# -eof meta-':
  89. break
  90. for pattern, handler in pats.items():
  91. m = pattern.match(line.strip())
  92. if m:
  93. meta.update(handler(m))
  94. # -*- Installation Requires -*-
  95. def strip_comments(l):
  96. return l.split('#', 1)[0].strip()
  97. def _pip_requirement(req):
  98. if req.startswith('-r '):
  99. _, path = req.split()
  100. return reqs(*path.split('/'))
  101. return [req]
  102. def _reqs(*f):
  103. return [
  104. _pip_requirement(r) for r in (
  105. strip_comments(l) for l in open(
  106. os.path.join(os.getcwd(), 'requirements', *f)).readlines()
  107. ) if r]
  108. def reqs(*f):
  109. return [req for subreq in _reqs(*f) for req in subreq]
  110. install_requires = reqs('default.txt')
  111. if JYTHON:
  112. install_requires.extend(reqs('jython.txt'))
  113. # -*- Tests Requires -*-
  114. tests_require = reqs('test3.txt' if PY3 else 'test.txt')
  115. # -*- Long Description -*-
  116. if os.path.exists('README.rst'):
  117. long_description = codecs.open('README.rst', 'r', 'utf-8').read()
  118. else:
  119. long_description = 'See http://pypi.python.org/pypi/celery'
  120. # -*- Entry Points -*- #
  121. console_scripts = entrypoints['console_scripts'] = [
  122. 'celery = celery.__main__:main',
  123. ]
  124. if CELERY_COMPAT_PROGRAMS:
  125. console_scripts.extend([
  126. 'celeryd = celery.__main__:_compat_worker',
  127. 'celerybeat = celery.__main__:_compat_beat',
  128. 'celeryd-multi = celery.__main__:_compat_multi',
  129. ])
  130. # -*- Extras -*-
  131. def extras(*p):
  132. return reqs('extras', *p)
  133. # Celery specific
  134. features = {
  135. 'auth', 'cassandra', 'memcache', 'couchbase', 'threads',
  136. 'eventlet', 'gevent', 'msgpack', 'yaml', 'redis',
  137. 'mongodb', 'sqs', 'couchdb', 'riak', 'beanstalk', 'zookeeper',
  138. 'zeromq', 'sqlalchemy', 'librabbitmq', 'pyro', 'slmq',
  139. 'new_cassandra',
  140. }
  141. extras_require = {x: extras(x + '.txt') for x in features}
  142. extra['extras_require'] = extras_require
  143. print(tests_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)