Ian Bicking avatar Ian Bicking committed 345aab8

Add pip installation

Comments (0)

Files changed (1)

 import sys
 import os
 import optparse
+import re
 import shutil
 import logging
 import distutils.sysconfig
         except ImportError:
             pass
 
-    search_dirs = ['.', os.path.dirname(__file__), join(os.path.dirname(__file__), 'virtualenv_support')]
-    if os.path.splitext(os.path.dirname(__file__))[0] != 'virtualenv':
-        # Probably some boot script; just in case virtualenv is installed...
-        try:
-            import virtualenv
-        except ImportError:
-            pass
-        else:
-            search_dirs.append(os.path.join(os.path.dirname(virtualenv.__file__), 'virtualenv_support'))
+    search_dirs = file_search_dirs()
 
     if setup_fn is not None:
         setup_fn = _find_file(setup_fn, search_dirs)
         if is_jython and os._name == 'nt':
             os.remove(ez_setup)
 
+def file_search_dirs():
+    here = os.path.dirname(os.path.abspath(__file__))
+    dirs = ['.', here,
+            join(here, 'virtualenv_support')]
+    if os.path.splitext(os.path.dirname(__file__))[0] != 'virtualenv':
+        # Probably some boot script; just in case virtualenv is installed...
+        try:
+            import virtualenv
+        except ImportError:
+            pass
+        else:
+            dirs.append(os.path.join(os.path.dirname(virtualenv.__file__), 'virtualenv_support'))
+    return dirs
+
 def install_setuptools(py_executable, unzip=False):
     _install_req(py_executable, unzip)
 
 def install_distribute(py_executable, unzip=False):
     _install_req(py_executable, unzip, distribute=True)
 
+_pip_re = re.compile(r'^pip-.*(zip|tar.gz|tar.bz2|tgz|tbz)$', re.I)
+def install_pip(py_executable):
+    filenames = []
+    for dir in file_search_dirs():
+        filenames.extend([join(dir, fn) for fn in os.listdir(dir)
+                          if _pip_re.search(fn)])
+    filenames.sort(key=lambda x: os.path.basename(x).lower())
+    if not filenames:
+        filename = 'pip'
+    else:
+        filename = filenames[-1]
+    cmd = [py_executable, join(os.path.dirname(py_executable), 'easy_install'), filename]
+    if filename == 'pip':
+        logger.info('Installing pip from network...')
+    else:
+        logger.info('Installing %s' % os.path.basename(filename))
+    logger.indent += 2
+    def _filter_setup(line):
+        return filter_ez_setup(line, 'pip')
+    try:
+        call_subprocess(cmd, show_stdout=False,
+                        filter_stdout=_filter_setup)
+    finally:
+        logger.indent -= 2
+
 def filter_ez_setup(line, project_name='setuptools'):
     if not line.strip():
         return Logger.DEBUG
     else:
         install_setuptools(py_executable, unzip=unzip_setuptools)
 
+    install_pip(py_executable)
+
     install_activate(home_dir, bin_dir)
 
 def path_locations(home_dir):
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.