Anonymous avatar Anonymous committed ffce45e

easy_install Distribute now calls the setuptools fake machinery fixes #40

Comments (0)

Files changed (2)

distribute_setup.py

 
 This file can also be run as a script to install or upgrade setuptools.
 """
+from site import USER_SITE
 import sys
 import os
 import shutil
         log.warn('Already patched.')
         return False
     log.warn('Patching...')
-    os.rename(path, path +'.OLD.%s' % time.time())
+    _rename_path(path)
     f = open(path, 'w')
     try:
         f.write(content)
 def _rename_path(path):
     new_name = path + '.OLD.%s' % time.time()
     log.warn('Renaming %s into %s' % (path, new_name))
+    try:
+        from setuptools.sandbox import DirectorySandbox
+        def _violation(*args):
+            pass
+        DirectorySandbox._violation = _violation
+    except ImportError:
+        pass
+
     os.rename(path, new_name)
     return new_name
 
     fake_setuptools()
 
 def _under_prefix(location):
+    if 'install' not in sys.argv:
+        return True
     args = sys.argv[sys.argv.index('install')+1:]
-
     for index, arg in enumerate(args):
         for option in ('--root', '--prefix'):
             if arg.startswith('%s=' % option):
                 if len(args) > index:
                     top_dir = args[index+1]
                     return location.startswith(top_dir)
+            elif option == '--user':
+                return location.startswith(USER_SITE)
     return True
 
 def fake_setuptools():
 
 # if we are installing Distribute using "python setup.py install"
 # we need to get setuptools out of the way
-if 'install' in sys.argv[1:]:
+def _being_installed():
+    # easy_install marker
+    if (len(sys.argv) == 5 and sys.argv[2] == 'bdist_egg' and
+            sys.argv[3] == '--dist-dir'):
+        return True
+    return 'install' in sys.argv[1:]
+
+if _being_installed():
     from distribute_setup import before_install
     before_install()
 
     Topic :: Utilities""".splitlines() if f.strip()],
     scripts = scripts,
 )
-if 'install' in sys.argv[1:]:
+
+if _being_installed():
     from distribute_setup import after_install
     after_install(dist)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.