Advertisement
Guest User

Django - Default setup.py

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