setup.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import os
  2. import sys
  3. from setuptools import setup
  4. from distutils.sysconfig import get_python_lib
  5. # Warn if we are installing over top of an existing installation. This can
  6. # cause issues where files that were deleted from a more recent Django are
  7. # still present in site-packages. See #18115.
  8. overlay_warning = False
  9. if "install" in sys.argv:
  10. lib_paths = [get_python_lib()]
  11. if lib_paths[0].startswith("/usr/lib/"):
  12. # We have to try also with an explicit prefix of /usr/local in order to
  13. # catch Debian's custom user site-packages directory.
  14. lib_paths.append(get_python_lib(prefix="/usr/local"))
  15. for lib_path in lib_paths:
  16. existing_path = os.path.abspath(os.path.join(lib_path, "django"))
  17. if os.path.exists(existing_path):
  18. # We note the need for the warning here, but present it after the
  19. # command is run, so it's more likely to be seen.
  20. overlay_warning = True
  21. break
  22. def fullsplit(path, result=None):
  23. """
  24. Split a pathname into components (the opposite of os.path.join)
  25. in a platform-neutral way.
  26. """
  27. if result is None:
  28. result = []
  29. head, tail = os.path.split(path)
  30. if head == '':
  31. return [tail] + result
  32. if head == path:
  33. return result
  34. return fullsplit(head, [tail] + result)
  35. EXCLUDE_FROM_PACKAGES = ['django.conf.project_template',
  36. 'django.conf.app_template',
  37. 'django.bin']
  38. def is_package(package_name):
  39. for pkg in EXCLUDE_FROM_PACKAGES:
  40. if package_name.startswith(pkg):
  41. return False
  42. return True
  43. # Compile the list of packages available, because distutils doesn't have
  44. # an easy way to do this.
  45. packages, package_data = [], {}
  46. root_dir = os.path.dirname(__file__)
  47. if root_dir != '':
  48. os.chdir(root_dir)
  49. django_dir = 'django'
  50. for dirpath, dirnames, filenames in os.walk(django_dir):
  51. # Ignore PEP 3147 cache dirs and those whose names start with '.'
  52. dirnames[:] = [d for d in dirnames if not d.startswith('.') and d != '__pycache__']
  53. parts = fullsplit(dirpath)
  54. package_name = '.'.join(parts)
  55. if '__init__.py' in filenames and is_package(package_name):
  56. packages.append(package_name)
  57. elif filenames:
  58. relative_path = []
  59. while '.'.join(parts) not in packages:
  60. relative_path.append(parts.pop())
  61. relative_path.reverse()
  62. path = os.path.join(*relative_path)
  63. package_files = package_data.setdefault('.'.join(parts), [])
  64. package_files.extend([os.path.join(path, f) for f in filenames])
  65. # Dynamically calculate the version based on django.VERSION.
  66. version = __import__('django').get_version()
  67. setup(
  68. name='Django',
  69. version=version,
  70. url='http://www.djangoproject.com/',
  71. author='Django Software Foundation',
  72. author_email='foundation@djangoproject.com',
  73. description=('A high-level Python Web framework that encourages '
  74. 'rapid development and clean, pragmatic design.'),
  75. license='BSD',
  76. packages=packages,
  77. package_data=package_data,
  78. entry_points={'console_scripts': [
  79. 'django-admin = django.core.management:execute_from_command_line',
  80. ]},
  81. zip_safe=False,
  82. classifiers=[
  83. 'Development Status :: 3 - Alpha',
  84. 'Environment :: Web Environment',
  85. 'Framework :: Django',
  86. 'Intended Audience :: Developers',
  87. 'License :: OSI Approved :: BSD License',
  88. 'Operating System :: OS Independent',
  89. 'Programming Language :: Python',
  90. 'Programming Language :: Python :: 2',
  91. 'Programming Language :: Python :: 2.7',
  92. 'Programming Language :: Python :: 3',
  93. 'Programming Language :: Python :: 3.2',
  94. 'Programming Language :: Python :: 3.3',
  95. 'Topic :: Internet :: WWW/HTTP',
  96. 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
  97. 'Topic :: Internet :: WWW/HTTP :: WSGI',
  98. 'Topic :: Software Development :: Libraries :: Application Frameworks',
  99. 'Topic :: Software Development :: Libraries :: Python Modules',
  100. ],
  101. )
  102. if overlay_warning:
  103. sys.stderr.write("""
  104. ========
  105. WARNING!
  106. ========
  107. You have just installed Django over top of an existing
  108. installation, without removing it first. Because of this,
  109. your install may now include extraneous files from a
  110. previous version that have since been removed from
  111. Django. This is known to cause a variety of problems. You
  112. should manually remove the
  113. %(existing_path)s
  114. directory and re-install Django.
  115. """ % {"existing_path": existing_path})