setup.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import io
  4. import os
  5. import re
  6. import sys
  7. import setuptools
  8. import setuptools.command.test
  9. if sys.version_info < (2, 7):
  10. raise Exception('amqp requires Python 2.7 or higher.')
  11. NAME = 'amqp'
  12. # -*- Classifiers -*-
  13. classes = """
  14. Development Status :: 5 - Production/Stable
  15. Programming Language :: Python
  16. Programming Language :: Python :: 2
  17. Programming Language :: Python :: 2.7
  18. Programming Language :: Python :: 3
  19. Programming Language :: Python :: 3.4
  20. Programming Language :: Python :: 3.5
  21. Programming Language :: Python :: 3.6
  22. License :: OSI Approved :: BSD License
  23. Intended Audience :: Developers
  24. Operating System :: OS Independent
  25. """
  26. classifiers = [s.strip() for s in classes.split('\n') if s]
  27. # -*- Distribution Meta -*-
  28. re_meta = re.compile(r'__(\w+?)__\s*=\s*(.*)')
  29. re_doc = re.compile(r'^"""(.+?)"""')
  30. def add_default(m):
  31. attr_name, attr_value = m.groups()
  32. return ((attr_name, attr_value.strip("\"'")),)
  33. def add_doc(m):
  34. return (('doc', m.groups()[0]),)
  35. pats = {re_meta: add_default,
  36. re_doc: add_doc}
  37. here = os.path.abspath(os.path.dirname(__file__))
  38. with open(os.path.join(here, 'amqp/__init__.py')) as meta_fh:
  39. meta = {}
  40. for line in meta_fh:
  41. if line.strip() == '# -eof meta-':
  42. break
  43. for pattern, handler in pats.items():
  44. m = pattern.match(line.strip())
  45. if m:
  46. meta.update(handler(m))
  47. # -*- Installation Requires -*-
  48. py_version = sys.version_info
  49. is_jython = sys.platform.startswith('java')
  50. is_pypy = hasattr(sys, 'pypy_version_info')
  51. def strip_comments(l):
  52. return l.split('#', 1)[0].strip()
  53. def reqs(f):
  54. with open(os.path.join(os.getcwd(), 'requirements', f)) as fp:
  55. req = filter(None, [strip_comments(l) for l in fp.readlines()])
  56. # filter returns filter object(iterator) in Python 3,
  57. # but a list in Python 2.7, so make sure it returns a list.
  58. return list(req)
  59. # -*- Long Description -*-
  60. if os.path.exists('README.rst'):
  61. with io.open('README.rst', encoding='utf-8') as fp:
  62. long_description = fp.read()
  63. else:
  64. long_description = 'See https://pypi.org/project/amqp/'
  65. # -*- %%% -*-
  66. class pytest(setuptools.command.test.test):
  67. user_options = [('pytest-args=', 'a', 'Arguments to pass to py.test')]
  68. def initialize_options(self):
  69. setuptools.command.test.test.initialize_options(self)
  70. self.pytest_args = []
  71. def run_tests(self):
  72. import pytest
  73. sys.exit(pytest.main(self.pytest_args))
  74. setuptools.setup(
  75. name=NAME,
  76. packages=setuptools.find_packages(exclude=['ez_setup', 't', 't.*']),
  77. long_description=long_description,
  78. version=meta['version'],
  79. description=meta['doc'],
  80. keywords='amqp rabbitmq cloudamqp messaging',
  81. author=meta['author'],
  82. author_email=meta['contact'],
  83. maintainer=meta['maintainer'],
  84. url=meta['homepage'],
  85. platforms=['any'],
  86. license='BSD',
  87. classifiers=classifiers,
  88. python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
  89. install_requires=reqs('default.txt'),
  90. tests_require=reqs('test.txt'),
  91. cmdclass={'test': pytest},
  92. zip_safe=False,
  93. )