Created
          November 30, 2010 06:53 
        
      - 
      
- 
        Save dsc/721271 to your computer and use it in GitHub Desktop. 
    fix-setuptools.fish: Reinstalls setuptools (as you'll inevitably do something silly, like `pip install -U distribute`)
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/usr/bin/env fish | |
| function fail | |
| echo "FAIL. $argv" >&2 | |
| exit 1 | |
| end | |
| not which python; and fail "Cannot find python on your path. Are you daft?" | |
| set -l ver (python -c 'import sys; print sys.version[0:3]') | |
| # this is not perfect, as the user could have some byzantine .pth-file chaining going on | |
| echo "Deleting whatever copies of setuptools, pip, and distribute we can find" | |
| set -l homes (dirname (dirname (which python))) $PYTHONHOME | |
| set -l packages $PYTHONPATH (for home in $homes; echo "$home/lib/python$ver/site-packages"; end) | |
| # remove our version of the problematic software | |
| for p in packages | |
| rm -rf $p/setuptools-* $p/pip-* $p/distribute-* | |
| end | |
| echo "Installing Setuptools..." | |
| # find latest version of setuptools | |
| set -l setuptools_url (curl --url 'http://pypi.python.org/pypi/setuptools/' | fgrep '<a href=' | egrep -o 'http://.*\.egg#md5=\w+' | fgrep "py$pyver.egg" | sort | tail -n1) | |
| test -z "$setuptools_url"; and fail "Could not determine URL of setuptools for Python $ver!" | |
| set -l setuptools_name (basename "$setuptools_url" | cut -d\# -f1) | |
| curl --url "$setuptools_url" > "./$setuptools_name" | |
| test ! $status = 0; and fail "Setuptools download failed!" | |
| sh "./$setuptools_name" | |
| test $status != 0 -o (not which easy_install); and fail "Setuptools install failed!" | |
| echo | |
| echo "Installing packages..." | |
| for pkg in pip distribute | |
| echo | |
| echo " Installing $pkg..." | |
| easy_install $pkg | |
| test $status != 0; and fail "Install failed for $pkg!" | |
| end | |
| echo | |
| echo "Success!" | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment