setup.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # -*- coding: utf-8 -*-
  2. """
  3. Based entirely on Django's own ``setup.py``.
  4. """
  5. import os
  6. import sys
  7. from distutils.command.install import INSTALL_SCHEMES
  8. from distutils.command.install_data import install_data
  9. try:
  10. from setuptools import setup
  11. except ImportError:
  12. from distutils.core import setup # NOQA
  13. try:
  14. from setuptools.command.test import test as TestCommand
  15. class PyTest(TestCommand):
  16. user_options = [('pytest-args=', 'a', "Arguments to pass into py.test")]
  17. def initialize_options(self):
  18. TestCommand.initialize_options(self)
  19. self.pytest_args = 'tests django_extensions --ds=tests.testapp.settings --cov=django_extensions'
  20. def finalize_options(self):
  21. TestCommand.finalize_options(self)
  22. self.test_args = []
  23. self.test_suite = True
  24. def run_tests(self):
  25. import shlex
  26. import pytest
  27. errno = pytest.main(shlex.split(self.pytest_args))
  28. sys.exit(errno)
  29. except ImportError:
  30. PyTest = None
  31. class osx_install_data(install_data):
  32. # On MacOS, the platform-specific lib dir is at:
  33. # /System/Library/Framework/Python/.../
  34. # which is wrong. Python 2.5 supplied with MacOS 10.5 has an Apple-specific
  35. # fix for this in distutils.command.install_data#306. It fixes install_lib
  36. # but not install_data, which is why we roll our own install_data class.
  37. def finalize_options(self):
  38. # By the time finalize_options is called, install.install_lib is set to
  39. # the fixed directory, so we set the installdir to install_lib. The
  40. # install_data class uses ('install_data', 'install_dir') instead.
  41. self.set_undefined_options('install', ('install_lib', 'install_dir'))
  42. install_data.finalize_options(self)
  43. if sys.platform == "darwin":
  44. cmdclasses = {'install_data': osx_install_data}
  45. else:
  46. cmdclasses = {'install_data': install_data}
  47. if PyTest:
  48. cmdclasses['test'] = PyTest
  49. def fullsplit(path, result=None):
  50. """
  51. Split a pathname into components (the opposite of os.path.join) in a
  52. platform-neutral way.
  53. """
  54. if result is None:
  55. result = []
  56. head, tail = os.path.split(path)
  57. if head == '':
  58. return [tail] + result
  59. if head == path:
  60. return result
  61. return fullsplit(head, [tail] + result)
  62. # Tell distutils to put the data_files in platform-specific installation
  63. # locations. See here for an explanation:
  64. # http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb
  65. for scheme in INSTALL_SCHEMES.values():
  66. scheme['data'] = scheme['purelib']
  67. # Compile the list of packages available, because distutils doesn't have
  68. # an easy way to do this.
  69. packages, package_data = [], {}
  70. root_dir = os.path.dirname(__file__)
  71. if root_dir != '':
  72. os.chdir(root_dir)
  73. extensions_dir = 'django_extensions'
  74. for dirpath, dirnames, filenames in os.walk(extensions_dir):
  75. # Ignore PEP 3147 cache dirs and those whose names start with '.'
  76. dirnames[:] = [d for d in dirnames if not d.startswith('.') and d != '__pycache__']
  77. parts = fullsplit(dirpath)
  78. package_name = '.'.join(parts)
  79. if '__init__.py' in filenames:
  80. packages.append(package_name)
  81. elif filenames:
  82. relative_path = []
  83. while '.'.join(parts) not in packages:
  84. relative_path.append(parts.pop())
  85. relative_path.reverse()
  86. path = os.path.join(*relative_path)
  87. package_files = package_data.setdefault('.'.join(parts), [])
  88. package_files.extend([os.path.join(path, f) for f in filenames])
  89. version = __import__('django_extensions').__version__
  90. setup(
  91. name='django-extensions',
  92. version=version,
  93. description="Extensions for Django",
  94. long_description="""django-extensions bundles several useful
  95. additions for Django projects. See the project page for more information:
  96. http://github.com/django-extensions/django-extensions""",
  97. author='Michael Trier',
  98. author_email='mtrier@gmail.com',
  99. maintainer='Bas van Oostveen',
  100. maintainer_email='v.oostveen@gmail.com',
  101. url='http://github.com/django-extensions/django-extensions',
  102. license='MIT License',
  103. platforms=['any'],
  104. packages=packages,
  105. cmdclass=cmdclasses,
  106. package_data=package_data,
  107. install_requires=['six>=1.2'],
  108. tests_require=[
  109. 'Django',
  110. 'shortuuid',
  111. 'python-dateutil',
  112. 'pytest',
  113. 'pytest-django',
  114. 'pytest-cov',
  115. 'tox',
  116. 'mock',
  117. 'vobject'
  118. ],
  119. classifiers=[
  120. 'Development Status :: 5 - Production/Stable',
  121. 'Environment :: Web Environment',
  122. 'Framework :: Django',
  123. 'Framework :: Django :: 1.8',
  124. 'Framework :: Django :: 1.9',
  125. 'Framework :: Django :: 1.10',
  126. 'Intended Audience :: Developers',
  127. 'License :: OSI Approved :: MIT License',
  128. 'Operating System :: OS Independent',
  129. 'Programming Language :: Python',
  130. 'Programming Language :: Python :: 2',
  131. 'Programming Language :: Python :: 3',
  132. 'Programming Language :: Python :: Implementation :: PyPy',
  133. 'Topic :: Utilities',
  134. ],
  135. )