setup.py 5.4 KB

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