~mdragon/nova/multi-tenant-accounting

« back to all changes in this revision

Viewing changes to test/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg/pip/venv.py

  • Committer: Tarmac
  • Author(s): Anne Gentle
  • Date: 2011-02-26 17:50:42 UTC
  • mfrom: (747.1.1 delpeskytest)
  • Revision ID: tarmac-20110226175042-htwnmds3fydg3ny1
Did a pull from trunk to be sure I had the latest, then deleted the test directory. I guess it appeared when I started using venv. Doh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Tools for working with virtualenv environments"""
2
 
 
3
 
import os
4
 
import sys
5
 
import subprocess
6
 
from pip.exceptions import BadCommand
7
 
from pip.log import logger
8
 
 
9
 
 
10
 
def restart_in_venv(venv, base, site_packages, args):
11
 
    """
12
 
    Restart this script using the interpreter in the given virtual environment
13
 
    """
14
 
    if base and not os.path.isabs(venv) and not venv.startswith('~'):
15
 
        base = os.path.expanduser(base)
16
 
        # ensure we have an abs basepath at this point:
17
 
        #    a relative one makes no sense (or does it?)
18
 
        if os.path.isabs(base):
19
 
            venv = os.path.join(base, venv)
20
 
 
21
 
    if venv.startswith('~'):
22
 
        venv = os.path.expanduser(venv)
23
 
 
24
 
    if not os.path.exists(venv):
25
 
        try:
26
 
            import virtualenv
27
 
        except ImportError:
28
 
            print 'The virtual environment does not exist: %s' % venv
29
 
            print 'and virtualenv is not installed, so a new environment cannot be created'
30
 
            sys.exit(3)
31
 
        print 'Creating new virtualenv environment in %s' % venv
32
 
        virtualenv.logger = logger
33
 
        logger.indent += 2
34
 
        virtualenv.create_environment(venv, site_packages=site_packages)
35
 
    if sys.platform == 'win32':
36
 
        python = os.path.join(venv, 'Scripts', 'python.exe')
37
 
        # check for bin directory which is used in buildouts
38
 
        if not os.path.exists(python):
39
 
            python = os.path.join(venv, 'bin', 'python.exe')
40
 
    else:
41
 
        python = os.path.join(venv, 'bin', 'python')
42
 
    if not os.path.exists(python):
43
 
        python = venv
44
 
    if not os.path.exists(python):
45
 
        raise BadCommand('Cannot find virtual environment interpreter at %s' % python)
46
 
    base = os.path.dirname(os.path.dirname(python))
47
 
    file = os.path.join(os.path.dirname(__file__), 'runner.py')
48
 
    if file.endswith('.pyc'):
49
 
        file = file[:-1]
50
 
    proc = subprocess.Popen(
51
 
        [python, file] + args + [base, '___VENV_RESTART___'])
52
 
    proc.wait()
53
 
    sys.exit(proc.returncode)