setup.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import os, sys
  2. import setuptools
  3. import pkg_resources
  4. from setuptools import setup, Command
  5. classifiers = ['Development Status :: 6 - Mature',
  6. 'Intended Audience :: Developers',
  7. 'License :: OSI Approved :: MIT License',
  8. 'Operating System :: POSIX',
  9. 'Operating System :: Microsoft :: Windows',
  10. 'Operating System :: MacOS :: MacOS X',
  11. 'Topic :: Software Development :: Testing',
  12. 'Topic :: Software Development :: Libraries',
  13. 'Topic :: Utilities'] + [
  14. ('Programming Language :: Python :: %s' % x) for x in
  15. '2 2.6 2.7 3 3.2 3.3 3.4 3.5'.split()]
  16. with open('README.rst') as fd:
  17. long_description = fd.read()
  18. def get_version():
  19. p = os.path.join(os.path.dirname(
  20. os.path.abspath(__file__)), "_pytest", "__init__.py")
  21. with open(p) as f:
  22. for line in f.readlines():
  23. if "__version__" in line:
  24. return line.strip().split("=")[-1].strip(" '")
  25. raise ValueError("could not read version")
  26. def has_environment_marker_support():
  27. """
  28. Tests that setuptools has support for PEP-426 environment marker support.
  29. The first known release to support it is 0.7 (and the earliest on PyPI seems to be 0.7.2
  30. so we're using that), see: http://pythonhosted.org/setuptools/history.html#id142
  31. References:
  32. * https://wheel.readthedocs.io/en/latest/index.html#defining-conditional-dependencies
  33. * https://www.python.org/dev/peps/pep-0426/#environment-markers
  34. """
  35. try:
  36. return pkg_resources.parse_version(setuptools.__version__) >= pkg_resources.parse_version('0.7.2')
  37. except Exception as exc:
  38. sys.stderr.write("Could not test setuptool's version: %s\n" % exc)
  39. return False
  40. def main():
  41. install_requires = ['py>=1.4.29'] # pluggy is vendored in _pytest.vendored_packages
  42. extras_require = {}
  43. if has_environment_marker_support():
  44. extras_require[':python_version=="2.6" or python_version=="3.0" or python_version=="3.1"'] = ['argparse']
  45. extras_require[':sys_platform=="win32"'] = ['colorama']
  46. else:
  47. if sys.version_info < (2, 7) or (3,) <= sys.version_info < (3, 2):
  48. install_requires.append('argparse')
  49. if sys.platform == 'win32':
  50. install_requires.append('colorama')
  51. setup(
  52. name='pytest',
  53. description='pytest: simple powerful testing with Python',
  54. long_description=long_description,
  55. version=get_version(),
  56. url='http://pytest.org',
  57. license='MIT license',
  58. platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
  59. author='Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin and others',
  60. author_email='holger at merlinux.eu',
  61. entry_points=make_entry_points(),
  62. classifiers=classifiers,
  63. cmdclass={'test': PyTest},
  64. # the following should be enabled for release
  65. install_requires=install_requires,
  66. extras_require=extras_require,
  67. packages=['_pytest', '_pytest.assertion', '_pytest._code', '_pytest.vendored_packages'],
  68. py_modules=['pytest'],
  69. zip_safe=False,
  70. )
  71. def cmdline_entrypoints(versioninfo, platform, basename):
  72. target = 'pytest:main'
  73. if platform.startswith('java'):
  74. points = {'py.test-jython': target}
  75. else:
  76. if basename.startswith('pypy'):
  77. points = {'py.test-%s' % basename: target}
  78. else: # cpython
  79. points = {'py.test-%s.%s' % versioninfo[:2] : target}
  80. points['py.test'] = target
  81. return points
  82. def make_entry_points():
  83. basename = os.path.basename(sys.executable)
  84. points = cmdline_entrypoints(sys.version_info, sys.platform, basename)
  85. keys = list(points.keys())
  86. keys.sort()
  87. l = ['%s = %s' % (x, points[x]) for x in keys]
  88. return {'console_scripts': l}
  89. class PyTest(Command):
  90. user_options = []
  91. def initialize_options(self):
  92. pass
  93. def finalize_options(self):
  94. pass
  95. def run(self):
  96. import subprocess
  97. PPATH = [x for x in os.environ.get('PYTHONPATH', '').split(':') if x]
  98. PPATH.insert(0, os.getcwd())
  99. os.environ['PYTHONPATH'] = ':'.join(PPATH)
  100. errno = subprocess.call([sys.executable, 'pytest.py', '--ignore=doc'])
  101. raise SystemExit(errno)
  102. if __name__ == '__main__':
  103. main()