setup.py 5.2 KB

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