setup.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import os
  2. import re
  3. import shutil
  4. import sys
  5. if sys.version_info[:2] < (2, 6):
  6. sys.exit('virtualenv requires Python 2.6 or higher.')
  7. try:
  8. from setuptools import setup
  9. from setuptools.command.test import test as TestCommand
  10. class PyTest(TestCommand):
  11. user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]
  12. def initialize_options(self):
  13. TestCommand.initialize_options(self)
  14. self.pytest_args = []
  15. def finalize_options(self):
  16. TestCommand.finalize_options(self)
  17. #self.test_args = []
  18. #self.test_suite = True
  19. def run_tests(self):
  20. # import here, because outside the eggs aren't loaded
  21. import pytest
  22. sys.exit(pytest.main(self.pytest_args))
  23. setup_params = {
  24. 'entry_points': {
  25. 'console_scripts': ['virtualenv=virtualenv:main'],
  26. },
  27. 'zip_safe': False,
  28. 'cmdclass': {'test': PyTest},
  29. 'tests_require': ['pytest', 'mock'],
  30. }
  31. except ImportError:
  32. from distutils.core import setup
  33. if sys.platform == 'win32':
  34. print('Note: without Setuptools installed you will '
  35. 'have to use "python -m virtualenv ENV"')
  36. setup_params = {}
  37. else:
  38. script = 'scripts/virtualenv'
  39. setup_params = {'scripts': [script]}
  40. def read_file(*paths):
  41. here = os.path.dirname(os.path.abspath(__file__))
  42. with open(os.path.join(here, *paths)) as f:
  43. return f.read()
  44. # Get long_description from index.rst:
  45. long_description = read_file('docs', 'index.rst')
  46. long_description = long_description.strip().split('split here', 1)[0]
  47. # Add release history
  48. changes = read_file('docs', 'changes.rst')
  49. # Only report last two releases for brevity
  50. releases_found = 0
  51. change_lines = []
  52. for line in changes.splitlines():
  53. change_lines.append(line)
  54. if line.startswith('--------------'):
  55. releases_found += 1
  56. if releases_found > 2:
  57. break
  58. changes = '\n'.join(change_lines[:-2]) + '\n'
  59. changes += '`Full Changelog <https://virtualenv.pypa.io/en/latest/changes.html>`_.'
  60. # Replace issue/pull directives
  61. changes = re.sub(r':pull:`(\d+)`', r'PR #\1', changes)
  62. changes = re.sub(r':issue:`(\d+)`', r'#\1', changes)
  63. long_description += '\n\n' + changes
  64. def get_version():
  65. version_file = read_file('virtualenv.py')
  66. version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
  67. version_file, re.M)
  68. if version_match:
  69. return version_match.group(1)
  70. raise RuntimeError("Unable to find version string.")
  71. # Hack to prevent stupid TypeError: 'NoneType' object is not callable error on
  72. # exit of python setup.py test # in multiprocessing/util.py _exit_function when
  73. # running python setup.py test (see
  74. # http://www.eby-sarna.com/pipermail/peak/2010-May/003357.html)
  75. try:
  76. import multiprocessing # noqa
  77. except ImportError:
  78. pass
  79. setup(
  80. name='virtualenv',
  81. version=get_version(),
  82. description="Virtual Python Environment builder",
  83. long_description=long_description,
  84. classifiers=[
  85. 'Development Status :: 5 - Production/Stable',
  86. 'Intended Audience :: Developers',
  87. 'License :: OSI Approved :: MIT License',
  88. 'Programming Language :: Python :: 2',
  89. 'Programming Language :: Python :: 2.6',
  90. 'Programming Language :: Python :: 2.7',
  91. 'Programming Language :: Python :: 3',
  92. 'Programming Language :: Python :: 3.3',
  93. 'Programming Language :: Python :: 3.4',
  94. 'Programming Language :: Python :: 3.5',
  95. ],
  96. keywords='setuptools deployment installation distutils',
  97. author='Ian Bicking',
  98. author_email='ianb@colorstudy.com',
  99. maintainer='Jannis Leidel, Carl Meyer and Brian Rosner',
  100. maintainer_email='python-virtualenv@groups.google.com',
  101. url='https://virtualenv.pypa.io/',
  102. license='MIT',
  103. py_modules=['virtualenv'],
  104. packages=['virtualenv_support'],
  105. package_data={'virtualenv_support': ['*.whl']},
  106. **setup_params)