1. import os
    
  2. import site
    
  3. import sys
    
  4. from distutils.sysconfig import get_python_lib
    
  5. 
    
  6. from setuptools import setup
    
  7. 
    
  8. # Allow editable install into user site directory.
    
  9. # See https://github.com/pypa/pip/issues/7953.
    
  10. site.ENABLE_USER_SITE = "--user" in sys.argv[1:]
    
  11. 
    
  12. # Warn if we are installing over top of an existing installation. This can
    
  13. # cause issues where files that were deleted from a more recent Django are
    
  14. # still present in site-packages. See #18115.
    
  15. overlay_warning = False
    
  16. if "install" in sys.argv:
    
  17.     lib_paths = [get_python_lib()]
    
  18.     if lib_paths[0].startswith("/usr/lib/"):
    
  19.         # We have to try also with an explicit prefix of /usr/local in order to
    
  20.         # catch Debian's custom user site-packages directory.
    
  21.         lib_paths.append(get_python_lib(prefix="/usr/local"))
    
  22.     for lib_path in lib_paths:
    
  23.         existing_path = os.path.abspath(os.path.join(lib_path, "django"))
    
  24.         if os.path.exists(existing_path):
    
  25.             # We note the need for the warning here, but present it after the
    
  26.             # command is run, so it's more likely to be seen.
    
  27.             overlay_warning = True
    
  28.             break
    
  29. 
    
  30. 
    
  31. setup()
    
  32. 
    
  33. 
    
  34. if overlay_warning:
    
  35.     sys.stderr.write(
    
  36.         """
    
  37. 
    
  38. ========
    
  39. WARNING!
    
  40. ========
    
  41. 
    
  42. You have just installed Django over top of an existing
    
  43. installation, without removing it first. Because of this,
    
  44. your install may now include extraneous files from a
    
  45. previous version that have since been removed from
    
  46. Django. This is known to cause a variety of problems. You
    
  47. should manually remove the
    
  48. 
    
  49. %(existing_path)s
    
  50. 
    
  51. directory and re-install Django.
    
  52. 
    
  53. """
    
  54.         % {"existing_path": existing_path}
    
  55.     )