setup.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. from distutils.core import setup
  2. from distutils.command.install_data import install_data
  3. from distutils.command.install import INSTALL_SCHEMES
  4. from distutils.sysconfig import get_python_lib
  5. import os
  6. import sys
  7. # Warn if we are installing over top of an existing installation. This can
  8. # cause issues where files that were deleted from a more recent Django are
  9. # still present in site-packages. See #18115.
  10. overlay_warning = False
  11. if "install" in sys.argv:
  12. lib_paths = [get_python_lib()]
  13. if lib_paths[0].startswith("/usr/lib/"):
  14. # We have to try also with an explicit prefix of /usr/local in order to
  15. # catch Debian's custom user site-packages directory.
  16. lib_paths.append(get_python_lib(prefix="/usr/local"))
  17. for lib_path in lib_paths:
  18. existing_path = os.path.abspath(os.path.join(lib_path, "django"))
  19. if os.path.exists(existing_path):
  20. # We note the need for the warning here, but present it after the
  21. # command is run, so it's more likely to be seen.
  22. overlay_warning = True
  23. break
  24. class osx_install_data(install_data):
  25. # On MacOS, the platform-specific lib dir is /System/Library/Framework/Python/.../
  26. # which is wrong. Python 2.5 supplied with MacOS 10.5 has an Apple-specific fix
  27. # for this in distutils.command.install_data#306. It fixes install_lib but not
  28. # install_data, which is why we roll our own install_data class.
  29. def finalize_options(self):
  30. # By the time finalize_options is called, install.install_lib is set to the
  31. # fixed directory, so we set the installdir to install_lib. The
  32. # install_data class uses ('install_data', 'install_dir') instead.
  33. self.set_undefined_options('install', ('install_lib', 'install_dir'))
  34. install_data.finalize_options(self)
  35. if sys.platform == "darwin":
  36. cmdclasses = {'install_data': osx_install_data}
  37. else:
  38. cmdclasses = {'install_data': install_data}
  39. def fullsplit(path, result=None):
  40. """
  41. Split a pathname into components (the opposite of os.path.join) in a
  42. platform-neutral way.
  43. """
  44. if result is None:
  45. result = []
  46. head, tail = os.path.split(path)
  47. if head == '':
  48. return [tail] + result
  49. if head == path:
  50. return result
  51. return fullsplit(head, [tail] + result)
  52. # Tell distutils not to put the data_files in platform-specific installation
  53. # locations. See here for an explanation:
  54. # http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb
  55. for scheme in INSTALL_SCHEMES.values():
  56. scheme['data'] = scheme['purelib']
  57. # Compile the list of packages available, because distutils doesn't have
  58. # an easy way to do this.
  59. packages, data_files = [], []
  60. root_dir = os.path.dirname(__file__)
  61. if root_dir != '':
  62. os.chdir(root_dir)
  63. django_dir = 'django'
  64. for dirpath, dirnames, filenames in os.walk(django_dir):
  65. # Ignore PEP 3147 cache dirs and those whose names start with '.'
  66. dirnames[:] = [d for d in dirnames if not d.startswith('.') and d != '__pycache__']
  67. if '__init__.py' in filenames:
  68. packages.append('.'.join(fullsplit(dirpath)))
  69. elif filenames:
  70. data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]])
  71. # Small hack for working with bdist_wininst.
  72. # See http://mail.python.org/pipermail/distutils-sig/2004-August/004134.html
  73. if len(sys.argv) > 1 and sys.argv[1] == 'bdist_wininst':
  74. for file_info in data_files:
  75. file_info[0] = '\\PURELIB\\%s' % file_info[0]
  76. # Dynamically calculate the version based on django.VERSION.
  77. version = __import__('django').get_version()
  78. setup(
  79. name = "Django",
  80. version = version,
  81. url = 'http://www.djangoproject.com/',
  82. author = 'Django Software Foundation',
  83. author_email = 'foundation@djangoproject.com',
  84. description = 'A high-level Python Web framework that encourages rapid development and clean, pragmatic design.',
  85. license = "BSD",
  86. packages = packages,
  87. cmdclass = cmdclasses,
  88. data_files = data_files,
  89. scripts = ['django/bin/django-admin.py'],
  90. classifiers = [
  91. 'Development Status :: 5 - Production/Stable',
  92. 'Environment :: Web Environment',
  93. 'Framework :: Django',
  94. 'Intended Audience :: Developers',
  95. 'License :: OSI Approved :: BSD License',
  96. 'Operating System :: OS Independent',
  97. 'Programming Language :: Python',
  98. 'Programming Language :: Python :: 2.6',
  99. 'Programming Language :: Python :: 2.7',
  100. 'Programming Language :: Python :: 3.2',
  101. 'Programming Language :: Python :: 3.3',
  102. 'Topic :: Internet :: WWW/HTTP',
  103. 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
  104. 'Topic :: Internet :: WWW/HTTP :: WSGI',
  105. 'Topic :: Software Development :: Libraries :: Application Frameworks',
  106. 'Topic :: Software Development :: Libraries :: Python Modules',
  107. ],
  108. )
  109. if overlay_warning:
  110. sys.stderr.write("""
  111. ========
  112. WARNING!
  113. ========
  114. You have just installed Django over top of an existing
  115. installation, without removing it first. Because of this,
  116. your install may now include extraneous files from a
  117. previous version that have since been removed from
  118. Django. This is known to cause a variety of problems. You
  119. should manually remove the
  120. %(existing_path)s
  121. directory and re-install Django.
  122. """ % { "existing_path": existing_path })